def test_descend_one(self): self.assertEqual(str(persistence.Path("one.2.3").descend_one()), "2.3") self.assertEqual(str(persistence.Path("3").descend_one()), "") with self.assertRaises(ValueError): persistence.Path("").descend_one() with self.assertRaises(ValueError): persistence.Path(".one.2").descend_one()
def test_len(self): self.assertEqual(len(persistence.Path("")), 0) self.assertEqual(len(persistence.Path("one")), 1) self.assertEqual(len(persistence.Path("one.2.3")), 3) with self.assertRaises(ValueError): len(persistence.Path(".one")) len(persistence.Path("."))
def test_get_item_slice(self): self.assertEqual(str(persistence.Path("one")[0:1]), "one") self.assertEqual(str(persistence.Path("one.2.3")[1:3]), "2.3") self.assertEqual(str(persistence.Path("one.2.3")[0:-1]), "one.2") self.assertEqual(str(persistence.Path("one.2.3")[-1:]), "3") with self.assertRaises(ValueError): persistence.Path(".one.2.3")[0:1:-1]
def test_get_item(self): self.assertEqual(persistence.Path("one")[0], "one") self.assertEqual(persistence.Path("one.2.3")[0], "one") self.assertEqual(persistence.Path("one.2.3")[2], "3") self.assertEqual(persistence.Path("one.2.3")[-1], "3") with self.assertRaises(ValueError): persistence.Path(".one.2.3")[-1]
def test_set(self): s = { persistence.Path("one.2"), persistence.Path("one.1.3"), persistence.Path("one.1.3") } self.assertIn(persistence.Path("one.2"), s) self.assertEqual(len(s), 2)
def test_ancestors(self): self.assertEqual( persistence.Path("").ancestors(), {persistence.Path("")}) self.assertEqual( persistence.Path("a").ancestors(), {persistence.Path(""), persistence.Path("a")}) self.assertEqual( persistence.Path("one.two.three").ancestors(), { persistence.Path(""), persistence.Path("one"), persistence.Path("one.two"), persistence.Path("one.two.three") })
def test_parent(self): self.assertEqual( persistence.Path("one").parent(), persistence.Path("")) self.assertEqual( persistence.Path("one.two.three").parent(), persistence.Path("one.two")) self.assertEqual( persistence.Path(".one").parent(), persistence.Path(".")) with self.assertRaises(ValueError): persistence.Path(".").parent() with self.assertRaises(ValueError): persistence.Path("").parent()
def test_append(self): self.assertEqual(str(persistence.Path("one").append("2")), "one.2") self.assertEqual(str(persistence.Path("").append("2")), "2") self.assertEqual(str(persistence.Path(".").append("2")), ".2") self.assertEqual(str(persistence.Path(".1.2").append("2")), ".1.2.2") with self.assertRaises(ValueError): persistence.Path("one").append("") with self.assertRaises(ValueError): persistence.Path("one").append(".") with self.assertRaises(ValueError): persistence.Path("one").append("two.3")
def test_init(self): self.assertTrue(type(persistence.Path("")) == persistence.Path) self.assertTrue(type(persistence.Path("..")) == persistence.Path) self.assertTrue(type(persistence.Path(".2")) == persistence.Path) self.assertTrue(type(persistence.Path("one.2")) == persistence.Path) with self.assertRaises(ValueError): persistence.Path(".one.") persistence.Path("one..2")
def test_get_absolute(self): self.assertEqual( persistence.Path(".").get_absolute(persistence.Path("1.2")), persistence.Path("1.2")) self.assertEqual( persistence.Path(".x.y").get_absolute(persistence.Path("1.2")), persistence.Path("1.2.x.y")) self.assertEqual( persistence.Path("..x.y").get_absolute(persistence.Path("1.2")), persistence.Path("1.x.y")) self.assertEqual( persistence.Path("...x.y").get_absolute(persistence.Path("1.2")), persistence.Path("x.y")) with self.assertRaises(ValueError): persistence.Path("....x.y").get_absolute(persistence.Path("1.2"))
def test_add_path(self): self.assertEqual( str(persistence.Path("one").add_path(persistence.Path("2"))), "one.2") self.assertEqual( str(persistence.Path("one").add_path(persistence.Path("2.3"))), "one.2.3") self.assertEqual( str(persistence.Path("").add_path(persistence.Path("2.3"))), "2.3") self.assertEqual( str(persistence.Path("one.2").add_path(persistence.Path(""))), "one.2") self.assertEqual( str(persistence.Path("").add_path(persistence.Path(""))), "") self.assertEqual( str(persistence.Path(".").add_path(persistence.Path(""))), ".") self.assertEqual( str(persistence.Path(".").add_path(persistence.Path("one.two"))), ".one.two") self.assertEqual( str(persistence.Path(".xy").add_path(persistence.Path("one.two"))), ".xy.one.two") with self.assertRaises(NotImplementedError): persistence.Path("one").add_path(persistence.Path(".2.3"))
def test_str(self): self.assertEqual(str(persistence.Path("one.2")), "one.2") self.assertEqual(str(persistence.Path("")), "")
def test_eq(self): self.assertEqual(persistence.Path(""), persistence.Path("")) self.assertEqual(persistence.Path(".."), persistence.Path("..")) self.assertEqual(persistence.Path("one.2"), persistence.Path("one.2")) self.assertEqual(persistence.Path("one.2"), persistence.Path("one.2.3").parent()) self.assertNotEqual(persistence.Path("one.2"), persistence.Path("one.2.3")) self.assertNotEqual(persistence.Path(""), persistence.Path("."))