<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import os <EOL> try : <EOL> from unittest2 import TestCase , SkipTest <EOL> except ImportError : <EOL> from unittest import TestCase , SkipTest <EOL> from flake8_putty . config import ( <EOL> CodeSelector , <EOL> EnvironmentMarkerSelector , <EOL> FileSelector , <EOL> Parser , <EOL> RegexSelector , <EOL> Rule , <EOL> markers , <EOL> ) <EOL> from flake8_putty . extension import AutoLineDisableRule <EOL> class TestParser ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_selector_code ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( [ CodeSelector ( '<STR_LIT>' ) ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_selector_code_multi ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( [ CodeSelector ( '<STR_LIT>' ) , CodeSelector ( '<STR_LIT>' ) ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_selector_marker ( self ) : <EOL> p = Parser ( "<STR_LIT>" ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , "<STR_LIT>" ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ "<STR_LIT>" ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( <EOL> [ EnvironmentMarkerSelector ( "<STR_LIT>" ) ] , <EOL> '<STR_LIT>' , <EOL> ) , <EOL> ] <EOL> def test_selector_filename ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( [ FileSelector ( '<STR_LIT>' ) ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_selector_dir ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( [ FileSelector ( '<STR_LIT>' ) ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_selector_filename_multi ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( [ FileSelector ( '<STR_LIT>' ) , FileSelector ( '<STR_LIT>' ) ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_selector_filename_explicit_relative ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( [ FileSelector ( '<STR_LIT>' ) ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_selector_explicit_relative_dir ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( [ FileSelector ( '<STR_LIT>' ) ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_selector_explicit_relative_star ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( [ CodeSelector ( '<STR_LIT>' ) ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_selector_star ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT:*>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( [ CodeSelector ( '<STR_LIT:*>' ) ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_selector_regex ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( [ RegexSelector ( '<STR_LIT:foo>' ) ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_selector_regex_hash ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( [ RegexSelector ( '<STR_LIT>' ) ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_selector_regex_colon ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_selector_regex_comma ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( [ RegexSelector ( '<STR_LIT>' ) ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_selector_regex_multi ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( [ RegexSelector ( '<STR_LIT>' ) , RegexSelector ( '<STR_LIT>' ) ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_selector_regex_codes ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( <EOL> [ RegexSelector ( '<STR_LIT>' ) ] , <EOL> '<STR_LIT>' , <EOL> ) , <EOL> ] <EOL> def test_selector_regex_codes_append ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , <EOL> ] <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( <EOL> [ RegexSelector ( '<STR_LIT>' ) ] , <EOL> '<STR_LIT>' , <EOL> ) , <EOL> ] <EOL> def test_mixed ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( <EOL> [ <EOL> RegexSelector ( '<STR_LIT>' ) , <EOL> CodeSelector ( '<STR_LIT>' ) , <EOL> FileSelector ( '<STR_LIT>' ) , <EOL> ] , <EOL> '<STR_LIT>' , <EOL> ) , <EOL> ] <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:1> , [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> assert p . _rules == [ <EOL> Rule ( <EOL> [ FileSelector ( '<STR_LIT>' ) , RegexSelector ( '<STR_LIT>' ) ] , <EOL> '<STR_LIT>' , <EOL> ) , <EOL> ] <EOL> def test_multiline ( self ) : <EOL> p = Parser ( """<STR_LIT>""" ) <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:2> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> p = Parser ( """<STR_LIT>""" ) <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:2> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:3> , [ '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> def test_multiple_codes ( self ) : <EOL> p = Parser ( """<STR_LIT>""" ) <EOL> assert list ( p . _parsed_lines ( ) ) == [ <EOL> ( <NUM_LIT:2> , [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) , <EOL> ] <EOL> class TestMatchFilename ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_selector_filename ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' . format ( os . sep ) ) <EOL> assert not p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> assert not p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> def test_selector_filename_missing ( self ) : <EOL> """<STR_LIT>""" <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert not p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> def test_selector_filename_multi ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' . format ( os . sep ) ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> assert not p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> def test_selector_directory ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> assert not p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> def test_selector_directory_multi ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> assert not p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> def test_selector_directory_wildcard ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . file_match_any ( <EOL> '<STR_LIT>' . format ( os . sep ) , <EOL> ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> assert not p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> def test_selector_directory_wildcard_nested ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> assert not p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> def test_selector_directory_wildcard_multi ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> assert not p . _rules [ <NUM_LIT:0> ] . file_match_any ( '<STR_LIT>' ) <EOL> class TestMatchRegex ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_selector_regex ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . regex_match_any ( '<STR_LIT>' ) <EOL> assert not p . _rules [ <NUM_LIT:0> ] . regex_match_any ( '<STR_LIT>' ) <EOL> def test_selector_regex_multi ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . regex_match_any ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . regex_match_any ( '<STR_LIT>' ) <EOL> assert not p . _rules [ <NUM_LIT:0> ] . regex_match_any ( '<STR_LIT>' ) <EOL> def test_selector_regex_codes ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . regex_match_any ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> assert not p . _rules [ <NUM_LIT:0> ] . regex_match_any ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> def test_selector_regex_codes_append ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . regex_match_any ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> assert not p . _rules [ <NUM_LIT:0> ] . regex_match_any ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> def test_selector_regex_codes_multi ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . regex_match_any ( <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] , <EOL> ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . regex_match_any ( <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] , <EOL> ) <EOL> def test_selector_regex_codes_multi_match ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . regex_match_any ( <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] , <EOL> ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . regex_match_any ( <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] , <EOL> ) <EOL> def test_selector_auto ( self ) : <EOL> rule = AutoLineDisableRule ( ) <EOL> assert rule . regex_match_any ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> assert not rule . regex_match_any ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> def test_selector_auto_missing_code ( self ) : <EOL> rule = AutoLineDisableRule ( ) <EOL> assert not rule . regex_match_any ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> assert not rule . regex_match_any ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> def test_selector_auto_multi ( self ) : <EOL> rule = AutoLineDisableRule ( ) <EOL> assert rule . regex_match_any ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> assert rule . regex_match_any ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> assert not rule . regex_match_any ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> def test_selector_auto_unrelated ( self ) : <EOL> rule = AutoLineDisableRule ( ) <EOL> assert rule . regex_match_any ( <EOL> '<STR_LIT>' , [ '<STR_LIT>' ] , <EOL> ) <EOL> assert not rule . regex_match_any ( <EOL> '<STR_LIT>' , [ '<STR_LIT>' ] , <EOL> ) <EOL> assert rule . regex_match_any ( <EOL> '<STR_LIT>' , [ '<STR_LIT>' ] , <EOL> ) <EOL> assert not rule . regex_match_any ( <EOL> '<STR_LIT>' , [ '<STR_LIT>' ] , <EOL> ) <EOL> def test_combined_selectors ( self ) : <EOL> p = Parser ( '<STR_LIT>' ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . match ( '<STR_LIT>' , '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> class TestMatchEnvironmentMarker ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> if not markers : <EOL> raise SkipTest ( '<STR_LIT>' ) <EOL> def test_selector_environment_marker ( self ) : <EOL> p = Parser ( "<STR_LIT>" ) <EOL> assert not p . _rules [ <NUM_LIT:0> ] . environment_marker_evaluate ( ) <EOL> p = Parser ( "<STR_LIT>" ) <EOL> assert p . _rules [ <NUM_LIT:0> ] . environment_marker_evaluate ( ) </s>
