<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import unittest <EOL> from unidiff . patch import ( <EOL> LINE_TYPE_ADDED , <EOL> LINE_TYPE_CONTEXT , <EOL> LINE_TYPE_REMOVED , <EOL> Hunk , <EOL> Line , <EOL> ) <EOL> class TestHunk ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( TestHunk , self ) . setUp ( ) <EOL> self . context_line = Line ( '<STR_LIT>' , line_type = LINE_TYPE_CONTEXT ) <EOL> self . added_line = Line ( '<STR_LIT>' , line_type = LINE_TYPE_ADDED ) <EOL> self . removed_line = Line ( '<STR_LIT>' , line_type = LINE_TYPE_REMOVED ) <EOL> def test_missing_length ( self ) : <EOL> hunk = Hunk ( src_len = None , tgt_len = None ) <EOL> hunk . append ( self . context_line ) <EOL> self . assertTrue ( hunk . is_valid ( ) ) <EOL> def test_default_is_valid ( self ) : <EOL> hunk = Hunk ( ) <EOL> self . assertTrue ( hunk . is_valid ( ) ) <EOL> def test_missing_data_is_not_valid ( self ) : <EOL> hunk = Hunk ( src_len = <NUM_LIT:1> , tgt_len = <NUM_LIT:1> ) <EOL> self . assertFalse ( hunk . is_valid ( ) ) <EOL> def test_append_context ( self ) : <EOL> hunk = Hunk ( src_len = <NUM_LIT:1> , tgt_len = <NUM_LIT:1> ) <EOL> hunk . append ( self . context_line ) <EOL> self . assertTrue ( hunk . is_valid ( ) ) <EOL> self . assertEqual ( len ( hunk . source ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( hunk . target , hunk . source ) <EOL> self . assertIn ( str ( self . context_line ) , hunk . source ) <EOL> source_lines = list ( hunk . source_lines ( ) ) <EOL> target_lines = list ( hunk . target_lines ( ) ) <EOL> self . assertEqual ( target_lines , source_lines ) <EOL> self . assertEqual ( target_lines , [ self . context_line ] ) <EOL> def test_append_added_line ( self ) : <EOL> hunk = Hunk ( src_len = <NUM_LIT:0> , tgt_len = <NUM_LIT:1> ) <EOL> hunk . append ( self . added_line ) <EOL> self . assertTrue ( hunk . is_valid ( ) ) <EOL> self . assertEqual ( len ( hunk . target ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( hunk . source , [ ] ) <EOL> self . assertIn ( str ( self . added_line ) , hunk . target ) <EOL> target_lines = list ( hunk . target_lines ( ) ) <EOL> self . assertEqual ( target_lines , [ self . added_line ] ) <EOL> def test_append_deleted_line ( self ) : <EOL> hunk = Hunk ( src_len = <NUM_LIT:1> , tgt_len = <NUM_LIT:0> ) <EOL> hunk . append ( self . removed_line ) <EOL> self . assertTrue ( hunk . is_valid ( ) ) <EOL> self . assertEqual ( len ( hunk . source ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( hunk . target , [ ] ) <EOL> self . assertIn ( str ( self . removed_line ) , hunk . source ) <EOL> source_lines = list ( hunk . source_lines ( ) ) <EOL> self . assertEqual ( source_lines , [ self . removed_line ] ) </s>
