<s> from textwrap import dedent <EOL> from click . testing import CliRunner <EOL> import pytest <EOL> from dennis . cmdline import cli <EOL> from tests import build_po_string , nix_header <EOL> @ pytest . fixture <EOL> def runner ( ) : <EOL> """<STR_LIT>""" <EOL> return CliRunner ( ) <EOL> def build_key_val ( text ) : <EOL> pairs = { } <EOL> for line in text . splitlines ( ) : <EOL> if '<STR_LIT::>' in line : <EOL> key , val = line . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> pairs [ key . strip ( ) ] = val . strip ( ) <EOL> return pairs <EOL> class TestStatus : <EOL> def test_help ( self , runner ) : <EOL> result = runner . invoke ( cli , ( '<STR_LIT:status>' , '<STR_LIT>' ) ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> assert '<STR_LIT>' in result . output . splitlines ( ) [ <NUM_LIT:0> ] <EOL> def test_status_untranslated ( self , runner , tmpdir ) : <EOL> po_file = build_po_string ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> fn = tmpdir . join ( '<STR_LIT>' ) <EOL> fn . write ( po_file ) <EOL> result = runner . invoke ( cli , ( '<STR_LIT:status>' , str ( fn ) ) ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> pairs = build_key_val ( result . output ) <EOL> assert pairs [ '<STR_LIT>' ] == '<STR_LIT:1>' <EOL> assert pairs [ '<STR_LIT>' ] == '<STR_LIT:3>' <EOL> assert pairs [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> def test_status_translated ( self , runner , tmpdir ) : <EOL> po_file = build_po_string ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> fn = tmpdir . join ( '<STR_LIT>' ) <EOL> fn . write ( po_file ) <EOL> result = runner . invoke ( cli , ( '<STR_LIT:status>' , str ( fn ) ) ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> pairs = build_key_val ( result . output ) <EOL> assert pairs [ '<STR_LIT>' ] == '<STR_LIT:1>' <EOL> assert pairs [ '<STR_LIT>' ] == '<STR_LIT:3>' <EOL> assert pairs [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> class TestTranslate : <EOL> def test_help ( self , runner ) : <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> assert '<STR_LIT>' in result . output . splitlines ( ) [ <NUM_LIT:0> ] <EOL> def test_strings ( self , runner ) : <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> assert '<STR_LIT>' in result . output <EOL> def test_no_paths ( self , runner ) : <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert result . exit_code == <NUM_LIT:2> <EOL> last_line = result . output . splitlines ( ) [ - <NUM_LIT:1> ] <EOL> assert last_line == '<STR_LIT>' <EOL> def test_pipe ( self , runner ) : <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:->' ) , input = '<STR_LIT>' ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> assert result . output == '<STR_LIT>' <EOL> def test_pipeline ( self , runner , tmpdir ) : <EOL> po_file = build_po_string ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> fn = tmpdir . join ( '<STR_LIT>' ) <EOL> fn . write ( po_file ) <EOL> assert po_file . endswith ( '<STR_LIT>' ) <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , str ( fn ) ) ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> last_line = fn . read ( ) . splitlines ( ) [ - <NUM_LIT:1> ] <EOL> assert last_line == '<STR_LIT>' <EOL> def test_bad_pipeline ( self , runner , tmpdir ) : <EOL> po_file = build_po_string ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> fn = tmpdir . join ( '<STR_LIT>' ) <EOL> fn . write ( po_file ) <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , str ( fn ) ) ) <EOL> assert result . exit_code == <NUM_LIT:2> <EOL> last_line = result . output . splitlines ( ) [ - <NUM_LIT:1> ] <EOL> assert last_line == '<STR_LIT>' <EOL> def test_nonexistent_file ( self , runner , tmpdir ) : <EOL> fn = tmpdir . join ( '<STR_LIT>' ) <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , str ( fn ) ) ) <EOL> assert result . exit_code == <NUM_LIT:2> <EOL> last_line = result . output . splitlines ( ) [ - <NUM_LIT:1> ] <EOL> assert last_line == '<STR_LIT>' % str ( fn ) <EOL> def test_plurals ( self , runner , tmpdir ) : <EOL> po_file = build_po_string ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> fn = tmpdir . join ( '<STR_LIT>' ) <EOL> fn . write ( po_file ) <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , str ( fn ) ) ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> pot_file = nix_header ( fn . read ( ) ) <EOL> assert ( <EOL> pot_file == <EOL> dedent ( """<STR_LIT>""" ) <EOL> ) <EOL> class TestLint : <EOL> def test_help ( self , runner ) : <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> assert '<STR_LIT>' in result . output . splitlines ( ) [ <NUM_LIT:0> ] <EOL> def test_basic_linting ( self , runner , tmpdir ) : <EOL> po_file = build_po_string ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> fn = tmpdir . join ( '<STR_LIT>' ) <EOL> fn . write ( po_file ) <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , str ( fn ) ) ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> output_lines = result . output . splitlines ( ) <EOL> assert len ( output_lines ) == <NUM_LIT:1> <EOL> assert output_lines [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) <EOL> def test_linting_fail ( self , runner , tmpdir ) : <EOL> po_file = build_po_string ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> fn = tmpdir . join ( '<STR_LIT>' ) <EOL> fn . write ( po_file ) <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , str ( fn ) ) ) <EOL> assert result . exit_code == <NUM_LIT:1> <EOL> output_lines = result . output . splitlines ( ) <EOL> assert len ( output_lines ) == <NUM_LIT:16> <EOL> assert '<STR_LIT>' in result . output <EOL> def test_no_files_to_work_on ( self , runner ) : <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT:foo>' ) ) <EOL> assert result . exit_code == <NUM_LIT:2> <EOL> assert '<STR_LIT>' in result . output <EOL> def test_nonexistent_file ( self , runner , tmpdir ) : <EOL> fn = tmpdir . join ( '<STR_LIT>' ) <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , str ( fn ) ) ) <EOL> assert result . exit_code == <NUM_LIT:2> <EOL> last_line = result . output . splitlines ( ) [ - <NUM_LIT:1> ] <EOL> assert last_line == '<STR_LIT>' % str ( fn ) <EOL> def test_quiet ( self , runner , tmpdir ) : <EOL> po_file = build_po_string ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> fn = tmpdir . join ( '<STR_LIT>' ) <EOL> fn . write ( po_file ) <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT>' , str ( fn ) ) ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> assert result . output == '<STR_LIT>' <EOL> def test_rules ( self , runner , tmpdir ) : <EOL> po_file = build_po_string ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> fn = tmpdir . join ( '<STR_LIT>' ) <EOL> fn . write ( po_file ) <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , str ( fn ) ) ) <EOL> assert result . exit_code == <NUM_LIT:1> <EOL> assert '<STR_LIT>' in result . output <EOL> def test_template_rules ( self , runner , tmpdir ) : <EOL> po_file = build_po_string ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> fn = tmpdir . join ( '<STR_LIT>' ) <EOL> fn . write ( po_file ) <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , str ( fn ) ) ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> assert '<STR_LIT>' in result . output <EOL> def test_nonexisting_rule ( self , runner , tmpdir ) : <EOL> po_file = build_po_string ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> fn = tmpdir . join ( '<STR_LIT>' ) <EOL> fn . write ( po_file ) <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:foo>' , str ( fn ) ) ) <EOL> assert result . exit_code == <NUM_LIT:2> <EOL> assert '<STR_LIT>' in result . output <EOL> def test_excludes ( self , runner , tmpdir ) : <EOL> po_file = build_po_string ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> fn = tmpdir . join ( '<STR_LIT>' ) <EOL> fn . write ( po_file ) <EOL> result = runner . invoke ( cli , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , str ( fn ) ) ) <EOL> assert result . exit_code == <NUM_LIT:0> <EOL> assert '<STR_LIT>' not in result . output </s>
