test_parser.py 2.52 KB
Newer Older
Savva Golubitsky's avatar
Savva Golubitsky committed
1
import unittest
Savva Golubitsky's avatar
Savva Golubitsky committed
2
import subprocess
Savva Golubitsky's avatar
Savva Golubitsky committed
3 4 5 6 7

from comsdk.graph import *
from comsdk.parser import Parser

path_to_comsdk = "/home/lbstr/bmstu/comsdk"
Savva Golubitsky's avatar
Savva Golubitsky committed
8
path_to_pycomsdk = "/home/lbstr/bmstu/pycomsdk"
Savva Golubitsky's avatar
Savva Golubitsky committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

class ParserGoodCheck(unittest.TestCase):

    def test_trivial_graph(self):
        parsr = Parser()
        gr = parsr.parse_file("./tests/adot/trivial.adot")
        data = {"a": 1}
        gr.run(data)
        self.assertEqual(data["a"], 4)

    def test_branching_graph(self):
        parsr = Parser()
        gr = parsr.parse_file("./tests/adot/branching.adot")
        data = {"a": 1, "b": 1}
        gr.run(data)
        self.assertEqual(data["a"], 4)
        self.assertEqual(data["b"], 4)

    def test_cycled_graph(self):
        parsr = Parser()
        gr = parsr.parse_file("./tests/adot/cycled.adot")
        data = {"a": 10}
        gr.run(data)
        self.assertEqual(data["a"], 0)

    def test_complex_graph(self):
        parsr = Parser()
        gr = parsr.parse_file("./tests/adot/complex.adot")
        data = {"a": 1, "b": 1}
        gr.run(data)
        self.assertEqual(data["a"], 4)
        self.assertEqual(data["b"], 4)

    def test_cpp_trivial_graph(self):
Savva Golubitsky's avatar
Savva Golubitsky committed
43 44 45 46 47
        parsr = Parser(tocpp=True)
        gr = parsr.parse_file("./tests/adot/cpptrivial.adot")
        parsr.generate_cpp(path_to_comsdk+"res.cpp")
        command = "cd "+path_to_comsdk+"; "+path_to_pycomsdk+"/cpp/run.sh "+path_to_comsdk+"res.cpp"
        subprocess.check_output(["bash", "-c", command])
Savva Golubitsky's avatar
Savva Golubitsky committed
48 49
    
    def test_cpp_branching_graph(self):
Savva Golubitsky's avatar
Savva Golubitsky committed
50 51 52 53 54
        parsr = Parser(tocpp=True)
        gr = parsr.parse_file("./tests/adot/cppbranching.adot")
        parsr.generate_cpp(path_to_comsdk+"res.cpp")
        command = "cd "+path_to_comsdk+"; "+path_to_pycomsdk+"/cpp/run.sh "+path_to_comsdk+"res.cpp"
        subprocess.check_output(["bash", "-c", command])
Savva Golubitsky's avatar
Savva Golubitsky committed
55 56

    def test_cpp_cycled_graph(self):
Savva Golubitsky's avatar
Savva Golubitsky committed
57 58 59 60 61
        parsr = Parser(tocpp=True)
        gr = parsr.parse_file("./tests/adot/cppcycled.adot")
        parsr.generate_cpp(path_to_comsdk+"res.cpp")
        command = "cd "+path_to_comsdk+"; "+path_to_pycomsdk+"/cpp/run.sh "+path_to_comsdk+"res.cpp"
        subprocess.check_output(["bash", "-c", command])
Savva Golubitsky's avatar
Savva Golubitsky committed
62 63

    def test_cpp_complex_graph(self):
Savva Golubitsky's avatar
Savva Golubitsky committed
64 65 66 67 68
        parsr = Parser(tocpp=True)
        gr = parsr.parse_file("./tests/adot/cppcomplex.adot")
        parsr.generate_cpp(path_to_comsdk+"res.cpp")
        command = "cd "+path_to_comsdk+"; "+path_to_pycomsdk+"/cpp/run.sh "+path_to_comsdk+"res.cpp"
        subprocess.check_output(["bash", "-c", command])
Savva Golubitsky's avatar
Savva Golubitsky committed
69 70 71 72

if __name__ == '__main__':
    unittest.main()