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']))
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']))
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"]))
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"]))
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')), [])
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)
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']))
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)
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
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)
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
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"]
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"]))
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"]))
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),
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', ]
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))
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
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']))
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']))
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"]))
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))
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))
def test_paths_dot_emptyroot(self): p = Pstep() p.a.b = '.' self.assertListEqual(sorted(p._paths()), sorted(['/a']))
def test_paths_dot(self): p = Pstep("r") p.a.b = "." self.assertListEqual(sorted(p._paths()), sorted(["r/a"]))
def test_paths_dot_emptyroot(self): p = Pstep() p.a.b = "." self.assertListEqual(sorted(p._paths()), sorted(["/a"]))
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'])
def test_paths_dotdot_atroot(self): p = Pstep('r') p.pp = '..' p.pp.a self.assertListEqual(sorted(p._paths()), sorted(['a']))
def test_paths_dotdot(self): p = Pstep('r') p.a.aa = '..' p.a.aa.b self.assertListEqual(sorted(p._paths()), sorted(['r/b']))
def test_paths_dotdot(self): p = Pstep("r") p.a.aa = ".." p.a.aa.b self.assertListEqual(sorted(p._paths()), sorted(["r/b"]))
def test_schema(self): json.dumps(Pstep()) json.dumps({Pstep(): 1})
def test_paths_dot(self): p = Pstep('r') p.a.b = '.' self.assertListEqual(sorted(p._paths()), sorted(['r/a']))
def test_as_pandas_index(self): df = pd.DataFrame([1, 3], columns=["a"]) s = Pstep("a") npt.assert_array_equal(df[s], [1, 3])
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")), [])
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"] )
def test_paths_dotdot_atroot(self): p = Pstep("r") p.pp = ".." p.pp.a self.assertListEqual(sorted(p._paths()), sorted(["a"]))
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
def test_paths(self): p = Pstep('r') self.assertListEqual(sorted(p._paths()), sorted(['r'])) p.a self.assertListEqual(sorted(p._paths()), sorted(['r/a']))
def test_paths(self): p = Pstep("r") self.assertListEqual(sorted(p._paths()), sorted(["r"])) p.a self.assertListEqual(sorted(p._paths()), sorted(["r/a"]))
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()))
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()))
def test_json_list(self): json.dumps([Pstep(), Pstep("a")])
def test_json(self): p = Pstep() p._schema.allOf = {} p._schema.type = "list" p.a._schema.kws = {"minimum": 1}