示例#1
0
 def test_paths_dotdot_multi(self):
     p = Pstep('r')
     p.pp = '..'
     p.pp.a.b
     p.c.cc = '..'
     p.c.cc.d
     self.assertListEqual(sorted(p._paths()), sorted(['a/b', 'r/d']))
示例#2
0
 def test_paths_dotdot_multi_emptyroot(self):
     p = Pstep('')
     p.pp = '..'
     p.pp.a.b
     p.c.cc = '..'
     p.c.cc.d
     self.assertListEqual(sorted(p._paths()), sorted(['/a/b', '/d']))
示例#3
0
 def test_paths_dotdot_multi_emptyroot(self):
     p = Pstep("")
     p.pp = ".."
     p.pp.a.b
     p.c.cc = ".."
     p.c.cc.d
     self.assertListEqual(sorted(p._paths()), sorted(["/a/b", "/d"]))
示例#4
0
 def test_paths_dotdot_multi(self):
     p = Pstep("r")
     p.pp = ".."
     p.pp.a.b
     p.c.cc = ".."
     p.c.cc.d
     self.assertListEqual(sorted(p._paths()), sorted(["a/b", "r/d"]))
示例#5
0
    def test_tags_delete(self):
        p = Pstep()
        p.a._tag('u').aa._tag('t').aaa
        p.b.c._tag('u')
        self.assertSequenceEqual(sorted(p._paths()), ['/a/aa/aaa', '/b/c'])
        self.assertSequenceEqual(sorted(p._paths(tag='t')), ['/a/aa'])
        self.assertSequenceEqual(sorted(p._paths(tag='u')), ['/a', '/b/c'])
        self.assertSequenceEqual(sorted(p._paths(tag='BAD')), [])

        p.a._tag_remove('u').aa.aaa
        self.assertSequenceEqual(sorted(p._paths()), ['/a/aa/aaa', '/b/c'])
        self.assertSequenceEqual(sorted(p._paths(tag='t')), ['/a/aa'])
        self.assertSequenceEqual(sorted(p._paths(tag='u')), ['/b/c'])

        p.a.aa._tag_remove('t').aaa
        p.a.aa._tag_remove('u').aaa  # Useless
        p.b.c._tag_remove('u')
        self.assertSequenceEqual(sorted(p._paths()), ['/a/aa/aaa', '/b/c'])
        self.assertSequenceEqual(sorted(p._paths(tag='t')), [])
        self.assertSequenceEqual(sorted(p._paths(tag='u')), [])

        p.a.aa.aaa._tag_remove('u')  # Useless
        p.a.aa.aaa._tag_remove('t')
        self.assertSequenceEqual(sorted(p._paths()), ['/a/aa/aaa', '/b/c'])
        self.assertSequenceEqual(sorted(p._paths(tag='t')), [])
        self.assertSequenceEqual(sorted(p._paths(tag='u')), [])
示例#6
0
    def test_assign(self):
        p1 = Pstep("root")

        def f1():
            p1.a = 1

        p1.a = "a"
        p1.a = p1
        p1.a = Pstep()  # TODO: Make step assigning work?

        self.assertRaises(AssertionError, f1)
示例#7
0
    def test_paths_dotdot_emptyroot(self):
        p = Pstep()
        p.a.aa = '..'
        p.a.aa.b
        self.assertListEqual(sorted(p._paths()), sorted(['/b']))

        p = Pstep()
        p.a.aa = '..'
        p.a.aa.b
        p.a.c
        self.assertListEqual(sorted(p._paths()), sorted(['/a/c', '/b']))
示例#8
0
    def test_assign(self):
        p1 = Pstep('root')

        def f1():
            p1.a = 1

        p1.a = 'a'
        p1.a = p1
        p1.a = Pstep()  # TODO: Make step assigning work?

        self.assertRaises(AssertionError, f1)
示例#9
0
    def test_buildtree_valid_ops(self):
        p = Pstep()
        p.abc
        p.abc.ddd = 'def'
        p.abc.dfg = 'defg'
        p.n123
        p.pp = '321'
        p._some_hidden = '12'
        p.a.b.c.d = '123'
        p.a.b.c.d.e = '123'

        return p
示例#10
0
    def test_pmods_lock_CAN_RELOCATE_unmapped(self):
        p = Pstep()
        p._locked = Pstep.CAN_RELOCATE
        p2 = p._lock
        self.assertIs(p2, p)
        p2 = p._fix
        self.assertIs(p2, p)

        p2 = p.abc._lock
        self.assertIs(p2, p.abc)
        p2 = p.abc._fix
        self.assertIs(p2, p.abc)
示例#11
0
    def test_pmods_lock_CAN_RELOCATE_unmapped(self):
        p = Pstep()
        p._locked = Pstep.CAN_RELOCATE
        p2 = p._lock
        self.assertIs(p2, p)
        p2 = p._fix
        self.assertIs(p2, p)

        p2 = p.abc._lock
        self.assertIs(p2, p.abc)
        p2 = p.abc._fix
        self.assertIs(p2, p.abc)
示例#12
0
    def test_buildtree_valid_ops(self):
        p = Pstep()
        p.abc
        p.abc.ddd = "def"
        p.abc.dfg = "defg"
        p.n123
        p.pp = "321"
        p._some_hidden = "12"
        p.a.b.c.d = "123"
        p.a.b.c.d.e = "123"

        return p
示例#13
0
    def test_paths_multi_nonemptyroot(self):
        p = Pstep("r")
        p.abc
        p.abc.aaa = "def"
        p.abc.defg
        p.n123
        p.pp = "321"
        p._some_hidden = 12
        exp = ["r/abc/def", "r/abc/defg", "r/321", "r/n123"]
        self.assertListEqual(sorted(p._paths()), sorted(exp))

        exp = ["r/abc/(aaa-->def)", "r/abc/defg", "r/(pp-->321)", "r/n123"]
示例#14
0
    def test_paths_empty1ststep(self):
        p = Pstep()
        self.assertListEqual(sorted(p._paths()), sorted([""]))

        p.a
        self.assertListEqual(sorted(p._paths()), sorted(["/a"]))

        p = Pstep("")
        self.assertListEqual(sorted(p._paths()), sorted([""]))

        p = Pstep("")
        p.a
        self.assertListEqual(sorted(p._paths()), sorted(["/a"]))
示例#15
0
    def test_paths_dotdot_atroot_emptyroot(self):
        p = Pstep()
        p.pp = ".."
        p.pp.a
        self.assertListEqual(sorted(p._paths()), sorted(["/a"]))

        p = Pstep()
        p.pp = ".."
        p.pp.a
        p.pp.b
        self.assertListEqual(sorted(p._paths()), sorted(["/a", "/b"]))
示例#16
0
    def test_buildtree_invalid_ops(self):

        p = Pstep()

        def f1(p):
            p.abc = 1

        def f2(p):
            p.a = 1

        def f3(p):
            p.a.b = 1

        def f4(p):
            p.a.c = 1

        for f in [f1, f2, f3, f4]:
            p = Pstep()
            with self.assertRaises(AssertionError, msg=f):
                f(p),
示例#17
0
    def test_paths_multi_nonemptyroot(self):
        p = Pstep('r')
        p.abc
        p.abc.aaa = 'def'
        p.abc.defg
        p.n123
        p.pp = '321'
        p._some_hidden = 12
        exp = [
            'r/abc/def',
            'r/abc/defg',
            'r/321',
            'r/n123',
        ]
        self.assertListEqual(sorted(p._paths()), sorted(exp))

        exp = [
            'r/abc/(aaa-->def)',
            'r/abc/defg',
            'r/(pp-->321)',
            'r/n123',
        ]
示例#18
0
    def test_paths_multi_empty1ststep(self):
        p = Pstep()
        p.abc
        p.abc.aaa = 'def'
        p.abc.defg
        p.n123
        p.pp = '321'
        p._some_hidden = 12
        exp = [
            '/abc/def',
            '/abc/defg',
            '/321',
            '/n123',
        ]
        self.assertListEqual(sorted(p._paths()), sorted(exp))

        exp = [
            '/abc/(aaa-->def)',
            '/abc/defg',
            '/(pp-->321)',
            '/n123',
        ]
        self.assertListEqual(sorted(p._paths(with_orig=True)), sorted(exp))
示例#19
0
    def _build_psteps(self, root="", pmods=None):
        p = Pstep(root, pmods)
        p.a.b.c
        p.a.b.d
        p.a.c
        p.abc.df
        p.n123
        p.a.n123
        p.cc.a123.a123
        p.cc.a123.abc
        p.b321
        # p[''] ##NOTE: Will always return to root.

        return p
示例#20
0
    def test_paths_empty1ststep(self):
        p = Pstep()
        self.assertListEqual(sorted(p._paths()), sorted(['']))

        p.a
        self.assertListEqual(sorted(p._paths()), sorted(['/a']))

        p = Pstep('')
        self.assertListEqual(sorted(p._paths()), sorted(['']))

        p = Pstep('')
        p.a
        self.assertListEqual(sorted(p._paths()), sorted(['/a']))
示例#21
0
    def test_paths_dotdot_atroot_emptyroot(self):
        p = Pstep()
        p.pp = '..'
        p.pp.a
        self.assertListEqual(sorted(p._paths()), sorted(['/a']))

        p = Pstep()
        p.pp = '..'
        p.pp.a
        p.pp.b
        self.assertListEqual(sorted(p._paths()), sorted(['/a', '/b']))
示例#22
0
    def test_paths_dotdot_emptyroot(self):
        p = Pstep()
        p.a.aa = ".."
        p.a.aa.b
        self.assertListEqual(sorted(p._paths()), sorted(["/b"]))

        p = Pstep()
        p.a.aa = ".."
        p.a.aa.b
        p.a.c
        self.assertListEqual(sorted(p._paths()), sorted(["/a/c", "/b"]))
示例#23
0
    def test_paths_multi_empty1ststep(self):
        p = Pstep()
        p.abc
        p.abc.aaa = "def"
        p.abc.defg
        p.n123
        p.pp = "321"
        p._some_hidden = 12
        exp = ["/abc/def", "/abc/defg", "/321", "/n123"]
        self.assertListEqual(sorted(p._paths()), sorted(exp))

        exp = ["/abc/(aaa-->def)", "/abc/defg", "/(pp-->321)", "/n123"]
        self.assertListEqual(sorted(p._paths(with_orig=True)), sorted(exp))
示例#24
0
    def test_equality(self):
        p = Pstep()
        self.assertEqual(str(p), "")
        self.assertEqual(p, Pstep(""))

        self.assertEqual(str(p.a), "a")
        self.assertEqual(p.a, Pstep("a"))

        n = "foo"
        p = Pstep(n)
        self.assertEqual(str(p), n)
        self.assertEqual(p, Pstep(n))
        self.assertEqual(str(p.foo), str(p))

        n = "/foo"
        p = Pstep(n)
        self.assertEqual(str(p), n)
        self.assertEqual(p, Pstep(n))
示例#25
0
 def test_paths_dot_emptyroot(self):
     p = Pstep()
     p.a.b = '.'
     self.assertListEqual(sorted(p._paths()), sorted(['/a']))
示例#26
0
 def test_paths_dot(self):
     p = Pstep("r")
     p.a.b = "."
     self.assertListEqual(sorted(p._paths()), sorted(["r/a"]))
示例#27
0
 def test_paths_dot_emptyroot(self):
     p = Pstep()
     p.a.b = "."
     self.assertListEqual(sorted(p._paths()), sorted(["/a"]))
示例#28
0
    def test_tags_paths(self):
        p = Pstep()
        self.assertEqual(p._tags, ())
        self.assertEqual(p._paths(tag='BAD'), [])

        p._tag('inp')
        self.assertSequenceEqual(sorted(p._tags), ['inp'])
        self.assertEqual(p._paths(tag='BAD'), [])
#         self.assertEqual(p._paths(tag='inp'), [''])

        self.assertEqual(p.a._tags, ())

        p.a._tag('t')
        self.assertSequenceEqual(sorted(p._paths(tag='t')), ['/a'])
        self.assertEqual(p._paths(tag='BAD'), [])
        p.b
        self.assertSequenceEqual(sorted(p._paths(tag='t')), ['/a'])
        p.a.aa
        self.assertSequenceEqual(sorted(p._paths(tag='t')), ['/a'])
        p.b.c
        self.assertSequenceEqual(sorted(p._paths(tag='t')), ['/a'])
        p.b._tag('t')
        self.assertSequenceEqual(sorted(p._paths(tag='t')), ['/a', '/b'])
        p.b.c._tag('t')
        self.assertSequenceEqual(
            sorted(p._paths(tag='t')), ['/a', '/b', '/b/c'])
        p.a.aa._tag('nt')
        self.assertSequenceEqual(
            sorted(p._paths(tag='t')), ['/a', '/b', '/b/c'])
        p.a.aa._tag('t')
        self.assertSequenceEqual(
            sorted(p._paths(tag='t')), ['/a', '/a/aa', '/b', '/b/c'])
示例#29
0
 def test_paths_dotdot_atroot(self):
     p = Pstep('r')
     p.pp = '..'
     p.pp.a
     self.assertListEqual(sorted(p._paths()), sorted(['a']))
示例#30
0
 def test_paths_dotdot(self):
     p = Pstep('r')
     p.a.aa = '..'
     p.a.aa.b
     self.assertListEqual(sorted(p._paths()), sorted(['r/b']))
示例#31
0
 def test_paths_dotdot(self):
     p = Pstep("r")
     p.a.aa = ".."
     p.a.aa.b
     self.assertListEqual(sorted(p._paths()), sorted(["r/b"]))
示例#32
0
 def test_schema(self):
     json.dumps(Pstep())
     json.dumps({Pstep(): 1})
示例#33
0
 def test_paths_dot(self):
     p = Pstep('r')
     p.a.b = '.'
     self.assertListEqual(sorted(p._paths()), sorted(['r/a']))
示例#34
0
 def test_as_pandas_index(self):
     df = pd.DataFrame([1, 3], columns=["a"])
     s = Pstep("a")
     npt.assert_array_equal(df[s], [1, 3])
示例#35
0
    def test_tags_delete(self):
        p = Pstep()
        p.a._tag("u").aa._tag("t").aaa
        p.b.c._tag("u")
        self.assertSequenceEqual(sorted(p._paths()), ["/a/aa/aaa", "/b/c"])
        self.assertSequenceEqual(sorted(p._paths(tag="t")), ["/a/aa"])
        self.assertSequenceEqual(sorted(p._paths(tag="u")), ["/a", "/b/c"])
        self.assertSequenceEqual(sorted(p._paths(tag="BAD")), [])

        p.a._tag_remove("u").aa.aaa
        self.assertSequenceEqual(sorted(p._paths()), ["/a/aa/aaa", "/b/c"])
        self.assertSequenceEqual(sorted(p._paths(tag="t")), ["/a/aa"])
        self.assertSequenceEqual(sorted(p._paths(tag="u")), ["/b/c"])

        p.a.aa._tag_remove("t").aaa
        p.a.aa._tag_remove("u").aaa  # Useless
        p.b.c._tag_remove("u")
        self.assertSequenceEqual(sorted(p._paths()), ["/a/aa/aaa", "/b/c"])
        self.assertSequenceEqual(sorted(p._paths(tag="t")), [])
        self.assertSequenceEqual(sorted(p._paths(tag="u")), [])

        p.a.aa.aaa._tag_remove("u")  # Useless
        p.a.aa.aaa._tag_remove("t")
        self.assertSequenceEqual(sorted(p._paths()), ["/a/aa/aaa", "/b/c"])
        self.assertSequenceEqual(sorted(p._paths(tag="t")), [])
        self.assertSequenceEqual(sorted(p._paths(tag="u")), [])
示例#36
0
    def test_tags_paths(self):
        p = Pstep()
        self.assertEqual(p._tags, ())
        self.assertEqual(p._paths(tag="BAD"), [])

        p._tag("inp")
        self.assertSequenceEqual(sorted(p._tags), ["inp"])
        self.assertEqual(p._paths(tag="BAD"), [])
        #         self.assertEqual(p._paths(tag='inp'), [''])

        self.assertEqual(p.a._tags, ())

        p.a._tag("t")
        self.assertSequenceEqual(sorted(p._paths(tag="t")), ["/a"])
        self.assertEqual(p._paths(tag="BAD"), [])
        p.b
        self.assertSequenceEqual(sorted(p._paths(tag="t")), ["/a"])
        p.a.aa
        self.assertSequenceEqual(sorted(p._paths(tag="t")), ["/a"])
        p.b.c
        self.assertSequenceEqual(sorted(p._paths(tag="t")), ["/a"])
        p.b._tag("t")
        self.assertSequenceEqual(sorted(p._paths(tag="t")), ["/a", "/b"])
        p.b.c._tag("t")
        self.assertSequenceEqual(sorted(p._paths(tag="t")), ["/a", "/b", "/b/c"])
        p.a.aa._tag("nt")
        self.assertSequenceEqual(sorted(p._paths(tag="t")), ["/a", "/b", "/b/c"])
        p.a.aa._tag("t")
        self.assertSequenceEqual(
            sorted(p._paths(tag="t")), ["/a", "/a/aa", "/b", "/b/c"]
        )
示例#37
0
 def test_paths_dotdot_atroot(self):
     p = Pstep("r")
     p.pp = ".."
     p.pp.a
     self.assertListEqual(sorted(p._paths()), sorted(["a"]))
示例#38
0
 def pout(self, path=None):
     """The suggested :class:`Pstep` for cfunc to use to access outputs."""
     p = self._pout
     if p is None:
         self._pout = p = Pstep(path or self._name, maps=self._pmod)
     return p
示例#39
0
    def test_paths(self):
        p = Pstep('r')
        self.assertListEqual(sorted(p._paths()), sorted(['r']))

        p.a
        self.assertListEqual(sorted(p._paths()), sorted(['r/a']))
示例#40
0
    def test_paths(self):
        p = Pstep("r")
        self.assertListEqual(sorted(p._paths()), sorted(["r"]))

        p.a
        self.assertListEqual(sorted(p._paths()), sorted(["r/a"]))
示例#41
0
 def test_pmods_miss(self):
     p = pmods_from_tuples([("/MISS", "BOO")]).step()
     self.assertEqual(p, "", (p, p._paths()))
     p = Pstep("foo", pmods_from_tuples([("/MISS", "BOO")]))
     self.assertEqual(p, "foo", (p, p._paths()))
示例#42
0
 def test_pmods_miss(self):
     p = pmods_from_tuples([('/MISS', 'BOO')]).step()
     self.assertEquals(p, '', (p, p._paths()))
     p = Pstep('foo', pmods_from_tuples([('/MISS', 'BOO')]))
     self.assertEquals(p, 'foo', (p, p._paths()))
示例#43
0
 def test_json_list(self):
     json.dumps([Pstep(), Pstep("a")])
示例#44
0
 def test_json(self):
     p = Pstep()
     p._schema.allOf = {}
     p._schema.type = "list"
     p.a._schema.kws = {"minimum": 1}