<s> from __future__ import unicode_literals , print_function , division <EOL> __author__ = "<STR_LIT>" <EOL> try : <EOL> import unittest2 as unittest <EOL> except ImportError : <EOL> import unittest <EOL> from mytesttools import SimpleStructureChecker , create_node , get_n_random_tags <EOL> from ezodf . nodeorganizer import PreludeEpilogueOrganizer <EOL> PRELUDE_TAGS = '<STR_LIT:abc>' <EOL> EPILOGUE_TAGS = '<STR_LIT>' <EOL> ALLTAGS = list ( PRELUDE_TAGS + '<STR_LIT>' + EPILOGUE_TAGS ) <EOL> checker = SimpleStructureChecker ( list ( PRELUDE_TAGS ) , list ( EPILOGUE_TAGS ) ) <EOL> has_valid_structure = checker . has_valid_structure <EOL> class TestTestFunction ( unittest . TestCase ) : <EOL> def test_valid_structure_sorted_midrange ( self ) : <EOL> nodes = create_node ( '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' ) <EOL> self . assertTrue ( has_valid_structure ( nodes ) ) <EOL> def test_valid_structure_unsorted_midrange ( self ) : <EOL> nodes = create_node ( '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' ) <EOL> self . assertTrue ( has_valid_structure ( nodes ) ) <EOL> def test_invalid_structure_b_after_c ( self ) : <EOL> nodes = create_node ( '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' ) <EOL> self . assertFalse ( has_valid_structure ( nodes ) ) <EOL> def test_invalid_structure_x_after_y ( self ) : <EOL> nodes = create_node ( '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' ) <EOL> self . assertFalse ( has_valid_structure ( nodes ) ) <EOL> def test_invalid_structure_a_in_midrange ( self ) : <EOL> nodes = create_node ( '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' ) <EOL> self . assertFalse ( has_valid_structure ( nodes ) ) <EOL> def test_invalid_structure_a_in_midrange_without_prelude ( self ) : <EOL> nodes = create_node ( '<STR_LIT>' '<STR_LIT>' ) <EOL> self . assertFalse ( has_valid_structure ( nodes ) ) <EOL> def test_invalid_structure_x_in_midrange ( self ) : <EOL> nodes = create_node ( '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' ) <EOL> self . assertFalse ( has_valid_structure ( nodes ) ) <EOL> def test_invalid_structure_x_in_midrange_without_epilouge ( self ) : <EOL> nodes = create_node ( '<STR_LIT>' '<STR_LIT>' ) <EOL> self . assertFalse ( has_valid_structure ( nodes ) ) <EOL> class TestPreludeEpilogueOrganizer ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . nodeorganizer = PreludeEpilogueOrganizer ( PRELUDE_TAGS , EPILOGUE_TAGS ) <EOL> def test_reorg ( self ) : <EOL> tags = get_n_random_tags ( <NUM_LIT:100> , ALLTAGS ) <EOL> tree = create_node ( tags ) <EOL> self . nodeorganizer . reorder ( tree ) <EOL> self . assertTrue ( has_valid_structure ( tree ) ) <EOL> def test_reorg_with_zero_nodes ( self ) : <EOL> node = create_node ( '<STR_LIT>' ) <EOL> self . nodeorganizer . reorder ( node ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( node ) ) <EOL> def test_reorg_with_one_node ( self ) : <EOL> node = create_node ( '<STR_LIT:g>' ) <EOL> self . nodeorganizer . reorder ( node ) <EOL> self . assertEqual ( '<STR_LIT:g>' , node [ <NUM_LIT:0> ] . tag ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
