<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> from ezodf . nodestructurechecker import NodeStructureChecker <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 TestNodeStructureChecker ( unittest . TestCase ) : <EOL> def test_valid_content ( self ) : <EOL> node = create_node ( '<STR_LIT>' ) <EOL> validator = NodeStructureChecker ( PRELUDE_TAGS , '<STR_LIT>' , EPILOGUE_TAGS ) <EOL> self . assertTrue ( validator . is_valid ( node ) ) <EOL> def test_invalid_content ( self ) : <EOL> node = create_node ( '<STR_LIT>' ) <EOL> validator = NodeStructureChecker ( PRELUDE_TAGS , '<STR_LIT>' , EPILOGUE_TAGS ) <EOL> self . assertFalse ( validator . is_valid ( node ) ) <EOL> def test_valid_content_without_prelude ( self ) : <EOL> node = create_node ( '<STR_LIT>' ) <EOL> validator = NodeStructureChecker ( PRELUDE_TAGS , '<STR_LIT>' , EPILOGUE_TAGS ) <EOL> self . assertTrue ( validator . is_valid ( node ) ) <EOL> def test_valid_content_without_epilogue ( self ) : <EOL> node = create_node ( '<STR_LIT>' ) <EOL> validator = NodeStructureChecker ( PRELUDE_TAGS , '<STR_LIT>' , EPILOGUE_TAGS ) <EOL> self . assertTrue ( validator . is_valid ( node ) ) <EOL> def test_valid_content_only_midrange ( self ) : <EOL> node = create_node ( '<STR_LIT>' ) <EOL> validator = NodeStructureChecker ( PRELUDE_TAGS , '<STR_LIT>' , EPILOGUE_TAGS ) <EOL> self . assertTrue ( validator . is_valid ( node ) ) <EOL> def test_valid_content_one_tag ( self ) : <EOL> node = create_node ( '<STR_LIT:g>' ) <EOL> validator = NodeStructureChecker ( PRELUDE_TAGS , '<STR_LIT>' , EPILOGUE_TAGS ) <EOL> self . assertTrue ( validator . is_valid ( node ) ) <EOL> def test_valid_content_empty_tag ( self ) : <EOL> node = create_node ( '<STR_LIT>' ) <EOL> validator = NodeStructureChecker ( PRELUDE_TAGS , '<STR_LIT>' , EPILOGUE_TAGS ) <EOL> self . assertTrue ( validator . is_valid ( node ) ) <EOL> def test_reorder ( self ) : <EOL> node = create_node ( get_n_random_tags ( <NUM_LIT:50> , list ( PRELUDE_TAGS + '<STR_LIT>' + EPILOGUE_TAGS ) ) ) <EOL> no = PreludeEpilogueOrganizer ( PRELUDE_TAGS , EPILOGUE_TAGS ) <EOL> no . reorder ( node ) <EOL> validator = NodeStructureChecker ( PRELUDE_TAGS , '<STR_LIT>' , EPILOGUE_TAGS ) <EOL> self . assertEqual ( has_valid_structure ( node ) , validator . is_valid ( node ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
