Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_node():
tree1 = Node("foo")
assert tree1.empty == True
assert tree1 == Node("foo")
assert str(tree1) == ""
assert tree1.render() == \
"""\
foo
"""
tree2 = Node("foo", children = ["bar", "baz"])
assert tree2.parent == None
assert tree2 != Node("foo", children = ["bar", "baz", "boo"])
assert Node("foo", children = ["bar", "baz"]) \
== Node("foo", children = ["bar", "baz"])
assert not Node("foo", children = ["bar", "baz"]) \
== Node("foo", children = ["baz", "boo"])
assert tree1.empty == True
assert tree1 == Node("foo")
assert str(tree1) == ""
assert tree1.render() == \
"""\
foo
"""
tree2 = Node("foo", children = ["bar", "baz"])
assert tree2.parent == None
assert tree2 != Node("foo", children = ["bar", "baz", "boo"])
assert Node("foo", children = ["bar", "baz"]) \
== Node("foo", children = ["bar", "baz"])
assert not Node("foo", children = ["bar", "baz"]) \
== Node("foo", children = ["baz", "boo"])
assert tree2.render() == \
"""\
foo
bar
baz
"""
assert tree2.render(indent = 4) == \
"""\
foo
bar
baz
"""
bar
baz
"""
assert tree2.render(indent = 4, formatter = lambda x: "* %s" % x) == \
"""\
* foo
* bar
* baz
"""
assert tree2.find(lambda x: x.obj == "foo")
assert tree2.find(lambda x: x.obj == "bar")
assert not tree2.find(lambda x: x.obj == "foobaz")
tree3 = Node("foo")
tree3.add_children(["bar", "baz"])
tree4 = Node("foo")
tree4.children = ["bar", "baz"]
with pytest.raises(TypeError):
tree4.children = "bar"
def test_node():
tree1 = Node("foo")
assert tree1.empty == True
assert tree1 == Node("foo")
assert str(tree1) == ""
assert tree1.render() == \
"""\
foo
"""
tree2 = Node("foo", children = ["bar", "baz"])
assert tree2.parent == None
assert tree2 != Node("foo", children = ["bar", "baz", "boo"])
assert Node("foo", children = ["bar", "baz"]) \
== Node("foo", children = ["bar", "baz"])
assert not Node("foo", children = ["bar", "baz"]) \
== Node("foo", children = ["baz", "boo"])
assert tree2.render() == \
"""\
foo
bar
baz
"""
assert tree2.render(indent = 4) == \
"""\
assert tree2.render(indent = 4, formatter = lambda x: "* %s" % x) == \
"""\
* foo
* bar
* baz
"""
assert tree2.find(lambda x: x.obj == "foo")
assert tree2.find(lambda x: x.obj == "bar")
assert not tree2.find(lambda x: x.obj == "foobaz")
tree3 = Node("foo")
tree3.add_children(["bar", "baz"])
tree4 = Node("foo")
tree4.children = ["bar", "baz"]
with pytest.raises(TypeError):
tree4.children = "bar"
def test_node():
tree1 = Node("foo")
assert tree1.empty == True
assert tree1 == Node("foo")
assert str(tree1) == ""
assert tree1.render() == \
"""\
foo
"""
tree2 = Node("foo", children = ["bar", "baz"])
assert tree2.parent == None
assert tree2 != Node("foo", children = ["bar", "baz", "boo"])
assert Node("foo", children = ["bar", "baz"]) \
== Node("foo", children = ["bar", "baz"])
assert not Node("foo", children = ["bar", "baz"]) \
def _get_dependency_tree_for_package(package, parent = None, sync = False,
jobs = 1):
if package.name not in _TREE_DICT:
logger.info("Building dependency tree for package: %s..." % package)
tree = TreeNode(package, parent = parent)
dependencies = [ ]
with parallel.no_daemon_pool(processes = jobs) as pool:
dependencies = pool.imap_unordered(
partial(
_create_package, **{
"sync": sync
}
),
_INFO_DICT[package.name]["dependencies"]
)
with parallel.no_daemon_pool(processes = jobs) as pool:
children = pool.imap_unordered(
partial(
try:
_db.query("""
UPDATE `tabPackage`
SET latest_version = '%s', home_page = '%s', _updated_at = '%s'
WHERE
name = '%s'
""" % (self.latest_version, self.home_page, datetime.now(), self.name))
except db.OperationalError as e:
logger.warn("Unable to update package name. %s" % e)
else:
logger.info("Using cached info for package %s." % self)
self.latest_version = res["latest_version"]
self.home_page = res["home_page"]
self.dependency_tree = TreeNode(self)