Ejemplo n.º 1
0
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']
Ejemplo n.º 2
0
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))
Ejemplo n.º 3
0
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))
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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))
Ejemplo n.º 6
0
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.
Ejemplo n.º 7
0
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))