Beispiel #1
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())
Beispiel #2
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
Beispiel #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())
Beispiel #4
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
Beispiel #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
Beispiel #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
Beispiel #7
0
    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"]))
Beispiel #8
0
    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"]))
Beispiel #9
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"])
        )
Beispiel #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"]))
Beispiel #11
0
    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"]))
Beispiel #12
0
    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"]))
Beispiel #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())
Beispiel #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())
Beispiel #15
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())
Beispiel #16
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)])
Beispiel #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)])
Beispiel #18
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())
Beispiel #19
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())
Beispiel #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())