def test_sections_from_file(): simpletext = """# [[[section foo]]] #Foo! # [[[endsection]]] """ f = doctools.SectionedFile(from_string=simpletext) assert len(f) == 1, "Sections found: %s" % f assert f['foo'] == "#Foo!\n", "Foo section contained: '%s'" % f['foo']
def test_bad_section(): f = doctools.SectionedFile(from_string="") try: f['foo'] assert False, "Should have a BuildFailure" except BuildFailure, e: assert str(e) == "No section 'foo' in file 'None'", \ "Error: '%s'" % (str(e))
def test_section_doesnt_end(): myfile = """ [[[section bar]]] Yo. """ try: f = doctools.SectionedFile(from_string=myfile) assert False, "Expected a BuildFailure" except BuildFailure, e: assert str(e) == """No end marker for section 'bar' (in file 'None', starts at line 2)""", "error was: %s" % (str(e))
def test_whole_file(): myfile = """ [[[section bar]]] Hi there. [[[section baz]]] Yo. [[[endsection]]] [[[endsection]]] """ f = doctools.SectionedFile(from_string=myfile) assert f.all == """ Hi there. Yo. """, "All was: %s" % (f.all)
def test_endmarker_without_start(): myfile = """ [[[section foo]]] This is a good section. [[[endsection]]] [[[endsection]]] """ try: f = doctools.SectionedFile(from_string=myfile) assert False, "Expected a BuildFailure" except BuildFailure, e: assert str(e) == """End section marker with no starting marker (in file 'None', at line 6)""", \ "error was: %s" % (str(e))
def test_nested_sections(): myfile = """ [[[section bar]]] Hi there. [[[section baz]]] Yo. [[[endsection]]] [[[endsection]]] """ f = doctools.SectionedFile(from_string=myfile) assert len(f) == 2 assert f['bar'] == """ Hi there. Yo. """, "Bar was: '%s'" % (f['bar']) assert f['bar.baz'] == """ Yo.
def test_section_already_defined(): myfile = """ [[[section foo]]] First one. [[[endsection]]] [[[section foo]]] Second one. [[[endsection]]] """ try: f = doctools.SectionedFile(from_string=myfile) assert False, "Expected a BuildFailure" except BuildFailure, e: assert str(e) == """section 'foo' redefined (in file 'None', first section at line 2, second at line 6)""", \ "error was: %s" % (str(e))