Beispiel #1
0
 def test_get_item(self):
     self.assertEqual(Path("one")[0], "one")
     self.assertEqual(Path("one.2.3")[0], "one")
     self.assertEqual(Path("one.2.3")[2], "3")
     self.assertEqual(Path("one.2.3")[-1], "3")
     with self.assertRaises(ValueError):
         Path(".one.2.3")[-1]
Beispiel #2
0
 def test_get_item_slice(self):
     self.assertEqual(str(Path("one")[0:1]), "one")
     self.assertEqual(str(Path("one.2.3")[1:3]), "2.3")
     self.assertEqual(str(Path("one.2.3")[0:-1]), "one.2")
     self.assertEqual(str(Path("one.2.3")[-1:]), "3")
     with self.assertRaises(ValueError):
         Path(".one.2.3")[0:1:-1]
Beispiel #3
0
 def test_descend_one(self):
     self.assertEqual(str(Path("one.2.3").descend_one()), "2.3")
     self.assertEqual(str(Path("3").descend_one()), "")
     with self.assertRaises(ValueError):
         Path("").descend_one()
     with self.assertRaises(ValueError):
         Path(".one.2").descend_one()
Beispiel #4
0
 def test_len(self):
     self.assertEqual(len(Path("")), 0)
     self.assertEqual(len(Path("one")), 1)
     self.assertEqual(len(Path("one.2.3")), 3)
     with self.assertRaises(ValueError):
         len(Path(".one"))
         len(Path("."))
Beispiel #5
0
 def test_ancestors(self):
     self.assertEqual(Path("").ancestors(), set([Path("")]))
     self.assertEqual(Path("a").ancestors(), set([Path(""), Path("a")]))
     self.assertEqual(
         Path("one.two.three").ancestors(),
         set([
             Path(""),
             Path("one"),
             Path("one.two"),
             Path("one.two.three")
         ]))
Beispiel #6
0
 def test_parent(self):
     self.assertEqual(Path("one").parent(), Path(""))
     self.assertEqual(Path("one.two.three").parent(), Path("one.two"))
     self.assertEqual(Path(".one").parent(), Path("."))
     with self.assertRaises(ValueError):
         Path(".").parent()
     with self.assertRaises(ValueError):
         Path("").parent()
Beispiel #7
0
 def test_append(self):
     self.assertEqual(str(Path("one").append("2")), "one.2")
     self.assertEqual(str(Path("").append("2")), "2")
     self.assertEqual(str(Path(".").append("2")), ".2")
     self.assertEqual(str(Path(".1.2").append("2")), ".1.2.2")
     with self.assertRaises(ValueError):
         Path("one").append("")
     with self.assertRaises(ValueError):
         Path("one").append(".")
     with self.assertRaises(ValueError):
         Path("one").append("two.3")
Beispiel #8
0
 def test_init(self):
     self.assertTrue(type(Path("")) == Path)
     self.assertTrue(type(Path("..")) == Path)
     self.assertTrue(type(Path(".2")) == Path)
     self.assertTrue(type(Path("one.2")) == Path)
     with self.assertRaises(ValueError):
         Path(".one.")
         Path("one..2")
Beispiel #9
0
 def test_get_absolute(self):
     self.assertEqual(Path(".").get_absolute(Path("1.2")), Path("1.2"))
     self.assertEqual(
         Path(".x.y").get_absolute(Path("1.2")), Path("1.2.x.y"))
     self.assertEqual(
         Path("..x.y").get_absolute(Path("1.2")), Path("1.x.y"))
     self.assertEqual(Path("...x.y").get_absolute(Path("1.2")), Path("x.y"))
     with self.assertRaises(ValueError):
         Path("....x.y").get_absolute(Path("1.2"))
Beispiel #10
0
 def test_add_path(self):
     self.assertEqual(str(Path("one").add_path(Path("2"))), "one.2")
     self.assertEqual(str(Path("one").add_path(Path("2.3"))), "one.2.3")
     self.assertEqual(str(Path("").add_path(Path("2.3"))), "2.3")
     self.assertEqual(str(Path("one.2").add_path(Path(""))), "one.2")
     self.assertEqual(str(Path("").add_path(Path(""))), "")
     self.assertEqual(str(Path(".").add_path(Path(""))), ".")
     self.assertEqual(str(Path(".").add_path(Path("one.two"))), ".one.two")
     self.assertEqual(str(Path(".xy").add_path(Path("one.two"))),
                      ".xy.one.two")
     with self.assertRaises(NotImplementedError):
         Path("one").add_path(Path(".2.3"))
Beispiel #11
0
 def test_set(self):
     s = set([Path("one.2"), Path("one.1.3"), Path("one.1.3")])
     self.assertIn(Path("one.2"), s)
     self.assertEqual(len(s), 2)
Beispiel #12
0
 def test_str(self):
     self.assertEqual(str(Path("one.2")), "one.2")
     self.assertEqual(str(Path("")), "")
Beispiel #13
0
 def test_eq(self):
     self.assertEqual(Path(""), Path(""))
     self.assertEqual(Path(".."), Path(".."))
     self.assertEqual(Path("one.2"), Path("one.2"))
     self.assertEqual(Path("one.2"), Path("one.2.3").parent())
     self.assertNotEqual(Path("one.2"), Path("one.2.3"))
     self.assertNotEqual(Path(""), Path("."))