<s> import inspect <EOL> import tempfile <EOL> import unittest <EOL> try : <EOL> from unittest import mock <EOL> except ImportError : <EOL> import mock <EOL> from tap . parser import Parser <EOL> class TestParser ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_finds_ok ( self ) : <EOL> """<STR_LIT>""" <EOL> parser = Parser ( ) <EOL> line = parser . parse_line ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT:test>' , line . category ) <EOL> self . assertTrue ( line . ok ) <EOL> self . assertTrue ( line . number is None ) <EOL> def test_finds_number ( self ) : <EOL> """<STR_LIT>""" <EOL> parser = Parser ( ) <EOL> line = parser . parse_line ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT:test>' , line . category ) <EOL> self . assertEqual ( <NUM_LIT> , line . number ) <EOL> def test_finds_description ( self ) : <EOL> parser = Parser ( ) <EOL> line = parser . parse_line ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT:test>' , line . category ) <EOL> self . assertEqual ( '<STR_LIT>' , line . description ) <EOL> def test_after_hash_is_not_description ( self ) : <EOL> parser = Parser ( ) <EOL> line = parser . parse_line ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT:test>' , line . category ) <EOL> self . assertEqual ( '<STR_LIT>' , line . description ) <EOL> def test_finds_todo ( self ) : <EOL> parser = Parser ( ) <EOL> line = parser . parse_line ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT:test>' , line . category ) <EOL> self . assertTrue ( line . todo ) <EOL> def test_finds_skip ( self ) : <EOL> parser = Parser ( ) <EOL> line = parser . parse_line ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT:test>' , line . category ) <EOL> self . assertTrue ( line . skip ) <EOL> def test_finds_not_ok ( self ) : <EOL> """<STR_LIT>""" <EOL> parser = Parser ( ) <EOL> line = parser . parse_line ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT:test>' , line . category ) <EOL> self . assertFalse ( line . ok ) <EOL> self . assertTrue ( line . number is None ) <EOL> def test_unrecognizable_line ( self ) : <EOL> """<STR_LIT>""" <EOL> parser = Parser ( ) <EOL> line = parser . parse_line ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , line . category ) <EOL> def test_diagnostic_line ( self ) : <EOL> """<STR_LIT>""" <EOL> text = '<STR_LIT>' <EOL> parser = Parser ( ) <EOL> line = parser . parse_line ( text ) <EOL> self . assertEqual ( '<STR_LIT>' , line . category ) <EOL> self . assertEqual ( text , line . text ) <EOL> def test_bail_out_line ( self ) : <EOL> """<STR_LIT>""" <EOL> parser = Parser ( ) <EOL> line = parser . parse_line ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , line . category ) <EOL> self . assertEqual ( '<STR_LIT>' , line . reason ) <EOL> def test_finds_version ( self ) : <EOL> """<STR_LIT>""" <EOL> parser = Parser ( ) <EOL> line = parser . parse_line ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT:version>' , line . category ) <EOL> self . assertEqual ( <NUM_LIT> , line . version ) <EOL> def test_errors_on_old_version ( self ) : <EOL> """<STR_LIT>""" <EOL> parser = Parser ( ) <EOL> self . assertRaises ( ValueError , parser . parse_line , '<STR_LIT>' ) <EOL> def test_finds_plan ( self ) : <EOL> """<STR_LIT>""" <EOL> parser = Parser ( ) <EOL> line = parser . parse_line ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , line . category ) <EOL> self . assertEqual ( <NUM_LIT> , line . expected_tests ) <EOL> def test_finds_plan_with_skip ( self ) : <EOL> """<STR_LIT>""" <EOL> parser = Parser ( ) <EOL> line = parser . parse_line ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , line . category ) <EOL> self . assertTrue ( line . skip ) <EOL> def test_ignores_plan_with_any_non_skip_directive ( self ) : <EOL> """<STR_LIT>""" <EOL> parser = Parser ( ) <EOL> line = parser . parse_line ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , line . category ) <EOL> def test_parses_file ( self ) : <EOL> sample = inspect . cleandoc ( <EOL> """<STR_LIT>""" ) <EOL> temp = tempfile . NamedTemporaryFile ( delete = False ) <EOL> temp . write ( sample . encode ( '<STR_LIT:utf-8>' ) ) <EOL> temp . close ( ) <EOL> parser = Parser ( ) <EOL> lines = [ ] <EOL> for line in parser . parse_file ( temp . name ) : <EOL> lines . append ( line ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( lines ) ) <EOL> self . assertEqual ( '<STR_LIT>' , lines [ <NUM_LIT:0> ] . category ) <EOL> self . assertEqual ( '<STR_LIT:test>' , lines [ <NUM_LIT:1> ] . category ) <EOL> self . assertTrue ( lines [ <NUM_LIT:1> ] . ok ) <EOL> self . assertEqual ( '<STR_LIT:test>' , lines [ <NUM_LIT:2> ] . category ) <EOL> self . assertFalse ( lines [ <NUM_LIT:2> ] . ok ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_parses_stdin ( self , mock_sys ) : <EOL> def stdin_data ( ) : <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> mock_stdin = mock . PropertyMock ( ) <EOL> mock_stdin . side_effect = stdin_data <EOL> type ( mock_sys ) . stdin = mock_stdin <EOL> parser = Parser ( ) <EOL> lines = [ ] <EOL> for line in parser . parse_stdin ( ) : <EOL> lines . append ( line ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( lines ) ) <EOL> self . assertEqual ( '<STR_LIT>' , lines [ <NUM_LIT:0> ] . category ) <EOL> self . assertEqual ( '<STR_LIT:test>' , lines [ <NUM_LIT:1> ] . category ) <EOL> self . assertTrue ( lines [ <NUM_LIT:1> ] . ok ) <EOL> self . assertEqual ( '<STR_LIT:test>' , lines [ <NUM_LIT:2> ] . category ) <EOL> self . assertFalse ( lines [ <NUM_LIT:2> ] . ok ) </s>
