예제 #1
0
파일: test_evil.py 프로젝트: icio/evil
 def test_set_evil_op_opposing(self):
     try:
         set_evil("a > < b", lambda t: set(), self.left_right_ops())
     except SyntaxError as e:
         eq_(e.args[0], "Operators cannot be beside one another if they "
                        "act on expressions facing one-another.")
         set_evil("a <> <> b", lambda t: set(), self.left_right_ops())
예제 #2
0
파일: test_evil.py 프로젝트: icio/evil
 def test_set_evil_op_left_missing(self):
     try:
         set_evil("< b", lambda t: set(), self.left_right_ops())
     except TypeError as e:
         eq_(e.args[0], "Operators which act on expressions to their "
                        "left or both sides cannot be at the beginning "
                        "of an expression.")
         raise e
예제 #3
0
 def test_set_evil_op_opposing(self):
     try:
         set_evil("a > < b", lambda t: set(), self.left_right_ops())
     except SyntaxError as e:
         eq_(
             e.args[0], "Operators cannot be beside one another if they "
             "act on expressions facing one-another.")
         set_evil("a <> <> b", lambda t: set(), self.left_right_ops())
예제 #4
0
파일: test_evil.py 프로젝트: icio/evil
 def test_set_evil_op_right_missing(self):
     try:
         set_evil("a >", lambda t: set(), self.left_right_ops())
     except SyntaxError as e:
         eq_(e.args[0], "Operators which act on expressions to their "
                        "right or both sides cannot be at the end of "
                        "an expression.")
         raise e
예제 #5
0
 def test_set_evil_op_right_missing(self):
     try:
         set_evil("a >", lambda t: set(), self.left_right_ops())
     except SyntaxError as e:
         eq_(
             e.args[0], "Operators which act on expressions to their "
             "right or both sides cannot be at the end of "
             "an expression.")
         raise e
예제 #6
0
 def test_set_evil_op_left_missing(self):
     try:
         set_evil("< b", lambda t: set(), self.left_right_ops())
     except TypeError as e:
         eq_(
             e.args[0], "Operators which act on expressions to their "
             "left or both sides cannot be at the beginning "
             "of an expression.")
         raise e
예제 #7
0
파일: test_set.py 프로젝트: icio/evil
    def test_globlookup(self):
        # Create temporary files equivalent to those used in test_strlookup
        tmp = mkdtemp()
        chars = ("a", "b", "c")
        for l1 in chars:
            os.mkdir(os.path.join(tmp, l1))
            for l2 in chars:
                os.mkdir(os.path.join(tmp, l1, l2))
                for l3 in chars:
                    f = os.path.join(tmp, l1, l2, l3)
                    with open(f, "w") as fh:
                        fh.write(f)

        # Test the lookup
        lookup = partial(globlookup, root=tmp)
        eq_(list(lookup("a/a/*")), ["a/a/a", "a/a/b", "a/a/c"])
        eq_(list(lookup("a/*/a")), ["a/a/a", "a/b/a", "a/c/a"])
        eq_(list(lookup("*/a/a")), ["a/a/a", "b/a/a", "c/a/a"])
        eq_(list(lookup("a/*")), [
            "a/a/a", "a/a/b", "a/a/c",
            "a/b/a", "a/b/b", "a/b/c",
            "a/c/a", "a/c/b", "a/c/c",
            ])

        # Test the lookup within set_evil
        eq_(set_evil("a/* = */a", lookup), set(["a/a/a", "a/b/a", "a/c/a"]))
예제 #8
0
파일: test_set.py 프로젝트: wiley17402/evil
    def test_globlookup(self):
        # Create temporary files equivalent to those used in test_strlookup
        tmp = mkdtemp()
        chars = ("a", "b", "c")
        for l1 in chars:
            os.mkdir(os.path.join(tmp, l1))
            for l2 in chars:
                os.mkdir(os.path.join(tmp, l1, l2))
                for l3 in chars:
                    f = os.path.join(tmp, l1, l2, l3)
                    with open(f, "w") as fh:
                        fh.write(f)

        # Test the lookup
        lookup = partial(globlookup, root=tmp)
        eq_(list(lookup("a/a/*")), ["a/a/a", "a/a/b", "a/a/c"])
        eq_(list(lookup("a/*/a")), ["a/a/a", "a/b/a", "a/c/a"])
        eq_(list(lookup("*/a/a")), ["a/a/a", "b/a/a", "c/a/a"])
        eq_(list(lookup("a/*")), [
            "a/a/a",
            "a/a/b",
            "a/a/c",
            "a/b/a",
            "a/b/b",
            "a/b/c",
            "a/c/a",
            "a/c/b",
            "a/c/c",
        ])

        # Test the lookup within set_evil
        eq_(set_evil("a/* = */a", lookup), set(["a/a/a", "a/b/a", "a/c/a"]))
예제 #9
0
파일: test_dag.py 프로젝트: icio/evil
    def test_daglookup(self):
        def node_dependencies(node, graph):
            yield node
            for depnode in graph[node]:
                for depdepnode in node_dependencies(depnode, graph):
                    yield depdepnode

        # Create a DAG where each node has dependencies declared by name
        # +-----+       +-----+
        # | b.b |       | c.b |
        # +-----+       +-----+
        #   |               |
        #   v               v
        # +-----+       +-----+
        # | b.a |       | c.a |
        # +-----+       +-----+
        #   |               |
        #   |    +-----+    |
        #   +--> | a.b | <--+
        #        +-----+
        #           |
        #           v
        #        +-----+
        #        | a.a |
        #        +-----+
        graph = {
            "a.a": [],
            "a.b": ["a.a"],
            "b.a": ["a.b"],
            "b.b": ["b.a"],
            "c.a": ["a.b"],
            "c.b": ["c.a"],
        }

        # The node lookup
        node_lookup = partial(strlookup, space=graph.keys())

        # The node operators. dependency_op returns the given node and all
        # other nodes up the chain from it.
        dependency_op = lambda nodes: set(
            dep for node in nodes for dep in node_dependencies(node, graph)
        )
        node_operators = [op("^", dependency_op, right=True)] + set_operators()

        # Assert that the node and dependency lookups are working
        eq_(set(node_lookup("a.*")), set(["a.a", "a.b"]))
        eq_(
            set(dependency_op(node_lookup("*.a"))),
            set(["a.a", "a.b", "b.a", "c.a"])
        )

        # Nodes matching *.a of (the dependencies of (all nodes matching *.b))
        eq_(
            set_evil("^*.b = *.a", node_lookup, node_operators),
            set(["a.a", "b.a", "c.a"])
        )
예제 #10
0
    def test_daglookup(self):
        def node_dependencies(node, graph):
            yield node
            for depnode in graph[node]:
                for depdepnode in node_dependencies(depnode, graph):
                    yield depdepnode

        # Create a DAG where each node has dependencies declared by name
        # +-----+       +-----+
        # | b.b |       | c.b |
        # +-----+       +-----+
        #   |               |
        #   v               v
        # +-----+       +-----+
        # | b.a |       | c.a |
        # +-----+       +-----+
        #   |               |
        #   |    +-----+    |
        #   +--> | a.b | <--+
        #        +-----+
        #           |
        #           v
        #        +-----+
        #        | a.a |
        #        +-----+
        graph = {
            "a.a": [],
            "a.b": ["a.a"],
            "b.a": ["a.b"],
            "b.b": ["b.a"],
            "c.a": ["a.b"],
            "c.b": ["c.a"],
        }

        # The node lookup
        node_lookup = partial(strlookup, space=graph.keys())

        # The node operators. dependency_op returns the given node and all
        # other nodes up the chain from it.
        dependency_op = lambda nodes: set(
            dep for node in nodes for dep in node_dependencies(node, graph))
        node_operators = [op("^", dependency_op, right=True)] + set_operators()

        # Assert that the node and dependency lookups are working
        eq_(set(node_lookup("a.*")), set(["a.a", "a.b"]))
        eq_(set(dependency_op(node_lookup("*.a"))),
            set(["a.a", "a.b", "b.a", "c.a"]))

        # Nodes matching *.a of (the dependencies of (all nodes matching *.b))
        eq_(set_evil("^*.b = *.a", node_lookup, node_operators),
            set(["a.a", "b.a", "c.a"]))
예제 #11
0
파일: test_set.py 프로젝트: wiley17402/evil
    def test_set_evil(self):
        lookup = partial(strlookup,
                         space=[
                             "a.a.a",
                             "a.a.b",
                             "a.a.c",
                             "a.b.a",
                             "a.b.b",
                             "a.b.c",
                             "a.c.a",
                             "a.c.b",
                             "a.c.c",
                             "b.a.a",
                             "b.a.b",
                             "b.a.c",
                             "b.b.a",
                             "b.b.b",
                             "b.b.c",
                             "b.c.a",
                             "b.c.b",
                             "b.c.c",
                             "c.a.a",
                             "c.a.b",
                             "c.a.c",
                             "c.b.a",
                             "c.b.b",
                             "c.b.c",
                             "c.c.a",
                             "c.c.b",
                             "c.c.c",
                         ])
        eq_(set_evil("a.a.*", lookup), set(["a.a.a", "a.a.b", "a.a.c"]))
        eq_(set_evil("a.*.a", lookup), set(["a.a.a", "a.b.a", "a.c.a"]))

        eq_(set_evil("a.a.* = a.*.a", lookup), set(["a.a.a"]))
        eq_(set_evil("a.a.* + a.*.a", lookup),
            set(["a.a.a", "a.a.b", "a.a.c", "a.b.a", "a.c.a"]))
        eq_(set_evil("a.a.* - a.*.a", lookup), set(["a.a.b", "a.a.c"]))
        eq_(set_evil("a.*.a - a.a.*", lookup), set(["a.b.a", "a.c.a"]))
        eq_(set_evil("(a.*) = (a.b.*) = (a.b.c)", lookup), set(["a.b.c"]))
        eq_(set_evil("(a.* + b.*) = (*.b.*, *.c.*) = *.c", lookup),
            set(["a.b.c", "a.c.c", "b.b.c", "b.c.c"]))
예제 #12
0
파일: test_set.py 프로젝트: icio/evil
    def test_set_evil(self):
        lookup = partial(strlookup, space=[
            "a.a.a", "a.a.b", "a.a.c", "a.b.a", "a.b.b", "a.b.c", "a.c.a",
            "a.c.b", "a.c.c", "b.a.a", "b.a.b", "b.a.c", "b.b.a", "b.b.b",
            "b.b.c", "b.c.a", "b.c.b", "b.c.c", "c.a.a", "c.a.b", "c.a.c",
            "c.b.a", "c.b.b", "c.b.c", "c.c.a", "c.c.b", "c.c.c",
        ])
        eq_(set_evil("a.a.*", lookup), set(["a.a.a", "a.a.b", "a.a.c"]))
        eq_(set_evil("a.*.a", lookup), set(["a.a.a", "a.b.a", "a.c.a"]))

        eq_(set_evil("a.a.* = a.*.a", lookup),
            set(["a.a.a"]))
        eq_(set_evil("a.a.* + a.*.a", lookup),
            set(["a.a.a", "a.a.b", "a.a.c", "a.b.a", "a.c.a"]))
        eq_(set_evil("a.a.* - a.*.a", lookup),
            set(["a.a.b", "a.a.c"]))
        eq_(set_evil("a.*.a - a.a.*", lookup),
            set(["a.b.a", "a.c.a"]))
        eq_(set_evil("(a.*) = (a.b.*) = (a.b.c)", lookup),
            set(["a.b.c"]))
        eq_(set_evil("(a.* + b.*) = (*.b.*, *.c.*) = *.c", lookup),
            set(["a.b.c", "a.c.c", "b.b.c", "b.c.c"]))
예제 #13
0
 def test_set_evil_op_either_missing(self):
     try:
         set_evil("a <>", lambda t: set(), self.left_right_ops())
     except TypeError:
         set_evil("<> b", lambda t: set(), self.left_right_ops())
예제 #14
0
 def test_set_evil_op_double(self):
     eq_(set_evil("a > > b", lambda t: set(), self.left_right_ops()), set())
     eq_(set_evil("a < < b", lambda t: set(), self.left_right_ops()), set())
예제 #15
0
파일: test_evil.py 프로젝트: icio/evil
 def test_set_evil_left_right(self):
     eq_(set_evil("> b", lambda t: set(), self.left_right_ops()), set())
     eq_(set_evil("a <", lambda t: set(), self.left_right_ops()), set())
     eq_(set_evil("a <> b", lambda t: set(), self.left_right_ops()), set())
예제 #16
0
파일: test_evil.py 프로젝트: icio/evil
 def test_set_evil_bad_operators(self):
     try:
         set_evil("a", lambda: 0, [("(", lambda: 0, 1)])
     except ValueError:
         set_evil("a", lambda: 0, [(")", lambda: 0, 1)])
예제 #17
0
 def test_set_evil_bad_operators(self):
     try:
         set_evil("a", lambda: 0, [("(", lambda: 0, 1)])
     except ValueError:
         set_evil("a", lambda: 0, [(")", lambda: 0, 1)])
예제 #18
0
파일: test_evil.py 프로젝트: icio/evil
 def test_set_evil_op_either_missing(self):
     try:
         set_evil("a <>", lambda t: set(), self.left_right_ops())
     except TypeError:
         set_evil("<> b", lambda t: set(), self.left_right_ops())
예제 #19
0
파일: test_evil.py 프로젝트: icio/evil
 def test_set_evil_op_double(self):
     eq_(set_evil("a > > b", lambda t: set(), self.left_right_ops()), set())
     eq_(set_evil("a < < b", lambda t: set(), self.left_right_ops()), set())
예제 #20
0
 def test_set_evil_left_right(self):
     eq_(set_evil("> b", lambda t: set(), self.left_right_ops()), set())
     eq_(set_evil("a <", lambda t: set(), self.left_right_ops()), set())
     eq_(set_evil("a <> b", lambda t: set(), self.left_right_ops()), set())