示例#1
0
 def test_register_backend(self):
     shaape = Shaape(TestUtils.EMPTY_INPUT)
     original_backends = copy.copy(shaape.backends())
     cairobackend = CairoBackend()
     shaape.register_backend(cairobackend)
     assert shaape.backends() == original_backends + [cairobackend]
     assert_raises(TypeError, shaape.register_backend, OverlayParser())
示例#2
0
 def test_register_parser(self):
     shaape = Shaape(TestUtils.EMPTY_INPUT)
     original_parsers = copy.copy(shaape.parsers())
     overlayparser = OverlayParser()
     shaape.register_parser(overlayparser)
     assert shaape.parsers() == original_parsers + [overlayparser]
     assert_raises(TypeError, shaape.register_parser, CairoBackend())
示例#3
0
    def test_run(self):
        parser = OverlayParser()
        parser.run("", [])

        parser.run("-", [])
        assert len(parser.drawable_objects()) == 1, parser.drawable_objects()
        assert type(parser.drawable_objects()[0]) == OpenGraph

        parser.run("- -", [])
        assert len(parser.drawable_objects()) == 2
        assert type(parser.drawable_objects()[0]) == OpenGraph
        assert type(parser.drawable_objects()[1]) == OpenGraph

        parser.run(["++", "++"], [])
        assert len(parser.drawable_objects()) == 1, "got " + str(
            len(parser.drawable_objects())) + " drawable objects " + str(
                parser.drawable_objects())
        assert len(
            [o for o in parser.drawable_objects() if type(o) == Polygon]) == 1

        parser.run(["+--+", "| ++", "| ++", "+--+"], [])
        assert len(parser.drawable_objects()) == 2, "got " + str(
            len(parser.drawable_objects())) + " drawable objects "
        assert len(
            [o for o in parser.drawable_objects() if type(o) == Polygon]) == 2
示例#4
0
 def test_cycle_len(self):
     parser = OverlayParser()
     cycle = [Node(0, 0), Node(4, 0), Node(4, 2), Node(0, 2), Node(0, 0)]
     assert parser.cycle_len(cycle) == 12
示例#5
0
 def test_init(self):
     parser = OverlayParser()
     assert parser != None
示例#6
0
    def test_run(self):
        parser = OverlayParser()
        parser.run("",[])

        parser.run("-",[])
        assert len(parser.drawable_objects()) == 1, parser.drawable_objects()
        assert type(parser.drawable_objects()[0]) == OpenGraph

        parser.run("- -",[])
        assert len(parser.drawable_objects()) == 2
        assert type(parser.drawable_objects()[0]) == OpenGraph
        assert type(parser.drawable_objects()[1]) == OpenGraph

        parser.run(["++","++"],[])
        assert len(parser.drawable_objects()) == 1, "got " + str(len(parser.drawable_objects())) + " drawable objects " + str(parser.drawable_objects())
        assert len([ o for o in parser.drawable_objects() if type(o) == Polygon]) == 1

        parser.run(["+--+", "| ++", "| ++", "+--+"],[])
        assert len(parser.drawable_objects()) == 2, "got " + str(len(parser.drawable_objects())) + " drawable objects "
        assert len([ o for o in parser.drawable_objects() if type(o) == Polygon]) == 2
示例#7
0
 def test_cycle_len(self):
     parser = OverlayParser()
     cycle = [Node(0, 0), Node(4, 0), Node(4, 2), Node(0, 2), Node(0, 0)]
     assert parser.cycle_len(cycle) == 12