Exemplo n.º 1
0
	def test_depth_one(self):
		foo = path.Node("foo")
		path.mount("/", foo)
		self.assertEqual(path.select("/"), ("foo",))
		self.assertTrue(path.exists("/foo"))
		path.umount("/foo")
		self.assertEqual(path.select("/"), ())
Exemplo n.º 2
0
	def test_depth_two(self):
		foo = path.Node("foo")
		path.mount("/", foo)
		bar = path.Node("bar")
		path.mount("/foo", bar)
		self.assertTrue(path.exists("/foo/bar"))
		self.assertEqual(path.select("/foo"), ("bar",))
		self.assertEqual(path.get("/foo/bar"), bar)
		path.umount("/foo/bar")
		self.assertEqual(path.select("/foo"), ())
		self.assertEqual(path.select("/"), ("foo",))
Exemplo n.º 3
0
	def test_link(self):
		"""
		/
		+- foo
		   +- baz
		+- bar
		   +- foo@
		"""
		foo = path.mount("/", path.Node("foo"))
		self.assertFalse(path.is_link("/foo"))
		path.mount("/", path.Node("bar"))
		lfoo = path.link("/bar", foo)
		self.assertEqual(lfoo.path, "/bar/foo")
		self.assertEqual(path.get("/bar/foo"), foo)
		self.assertTrue(path.is_link("/bar/foo"))
		baz = path.mount("/bar/foo", path.Node("baz"))
		self.assertEqual(baz.path, "/foo/baz")
		path.umount("/bar/foo")
		self.assertEqual(path.get("/foo"), foo)
Exemplo n.º 4
0
	def test_select(self):
		class XNode(path.Node):
			def __init__(self, name, x):
				super(XNode, self).__init__(name)
				self.x = x
		foo = XNode("foo", 42)
		bar = XNode("bar", 100)
		baz = XNode("baz", 3.14)
		qux = XNode("qux", 50)
		path.mount("/", foo)
		path.mount("/", bar)
		path.mount("/", baz)
		path.mount("/", qux)
		self.assertEqual(set(path.select("/")), set(("foo", "bar", "baz", "qux")))
		self.assertEqual(set(path.select("/", by_value = True)), set((foo, bar, baz, qux)))
		self.assertEqual(
			path.select("/", predicate = lambda node: node.x < 100, key = lambda node: node.x),
			("baz", "foo", "qux"))