def test_from_path_default(self):
     def_json = Settings.default_json_folder()
     Settings.alter_default_json_folder(self.path)
     collection = Collection.from_path()
     Settings.alter_default_json_folder(def_json)
     # collection should not contain the invalid roles/InvalidRole.json
     assert 'InvalidRole' not in collection.collection.get('roles').keys()
     assert Collection(self.collection) == collection
 def test_write_collection_new_file_new_dir(self, tmpdir):
     collection = Collection({"roles": {"Role.json": Tree("Role", "1", {"1": Node("1", "1")})},
                              "tactics": {},
                              "strategies": {},
                              "keeper": {}})
     collection.write_collection(tmpdir)
     collection.path = tmpdir
     assert collection == Collection.from_path(tmpdir)
 def test_write_collection(self, tmpdir):
     collection = Collection.from_path(self.path)
     collection.write_collection(tmpdir)
     read = Collection.from_path(tmpdir)
     # sets path equal, so objects are equal
     collection.path = None
     read.path = None
     assert read == collection
 def test_write_collection_default_path2(self, tmpdir):
     collection = Collection.from_path()
     collection.path = tmpdir
     collection.write_collection()
     read = Collection.from_path(tmpdir)
     # sets path equal, so objects are equal
     collection.path = None
     read.path = None
     assert collection == read
 def test_write_collection_new_file(self, tmpdir):
     collection = Collection.from_path(self.path)
     collection.write_collection(tmpdir)
     collection.add_tree("roles", "tree.json", Tree("name", "1", {"1": Node("node", "1")}))
     collection.write_collection(tmpdir)
     read = Collection.from_path(tmpdir)
     # sets path equal, so objects are equal
     collection.path = None
     read.path = None
     assert read == collection
 def test_build_collection(self):
     collection = Collection()
     collection.build_collection(self.path)
     # check if hidden file is not added to collection
     assert '.hiddendir' not in collection.collection.keys()
     assert '_categoryunderscore' not in collection.collection.keys()
     assert '.hiddenTree.json' not in collection.collection.get('roles')
     # check if file with wrong file extension is not added
     assert 'TreeWithoutJsonFileExtension' not in collection.collection.get('roles')
     assert Collection(self.collection) == collection
 def test_write_collection_default_path1(self, tmpdir):
     def_path = Settings.default_json_folder()
     Settings.alter_default_json_folder(tmpdir)
     collection = Collection.from_path()
     collection.write_collection()
     read = Collection.from_path(tmpdir)
     Settings.alter_default_json_folder(def_path)
     # sets path equal, so objects are equal
     collection.path = None
     read.path = None
     assert collection == read
 def test_verify_trees(self):
     collection = Collection.from_path(Settings.default_json_folder(), only_verify_mathematical_properties=False)
     for category in collection.collection:
         for file in collection.collection[category]:
             # skip these two files as there is a decorator with two children
             if not (file == "GetBallTestTactic.json" or file == "GetBallTestStrategy.json"):
                 assert 0 is len(collection.verify_tree(collection.collection[category][file], category))
 def test_write_tree(self, tmpdir):
     collection = Collection.from_path(self.path)
     tree = self.attack_strategy
     collection.write_tree(tree, Path(tmpdir) / "test.json")
     path = tmpdir / 'test.json'
     read = Tree.from_json(read_json(path))
     assert tree == read
 def test_remove_tree_by_name_not_exists(self):
     collection = Collection.from_path(self.path)
     # add a tree, so the if statement goes to the else
     collection.add_tree("roles", "test", Tree('roles', '1'))
     collection.remove_tree_by_name('roles', "Assister")
     assert "Assister.json" not in collection.collection.get('roles')
     collection.remove_tree_by_name('roles', "Assister")
     assert "Assister.json" not in collection.collection.get('roles')
 def test_categories_and_filenames(self):
     collection = Collection(self.collection)
     collection.collection['keeper'] = {}
     categories_and_filenames = {
         'roles': ['Assister.json'],
         'tactics': ['Attactic.json'],
         'strategies': ['AttackStrategy.json'],
         'keeper': []
     }
     assert categories_and_filenames == collection.categories_and_filenames()
 def open_collection(self, path: Path=None):
     """
     PyqtSlot for opening a a collection
     Sends a open_collection_finished_signal when finished
         with a dictionary of categories containing a list of filenames
     :param path: the path to open from, None if the user
                     wants to open from the default settings path
     """
     self.collection = Collection.from_path(path)
     self.open_collection_finished_signal.emit(self.collection)
 def test_get_category_from_node(self):
     collection = Collection.from_path(self.path)
     result = collection.get_category_from_node("ydjw9of7ndf88")
     assert result == "strategies"
     result = collection.get_category_from_node("57mrxn20qviax5qc")
     assert result == "tactics"
     result = collection.get_category_from_node("sx6fvrxlaoudhmmq9")
     assert result == "roles"
     result = collection.get_category_from_node("invalid_category")
     assert not result
 def test_update_subtrees_in_collection_role_propagation(self):
     # check if role propagation is skipped
     collection = Collection.from_path(self.complete_path)
     node = Node('Role', attributes={'role': 'EnterFormationRole'})
     tree = collection.get_tree_by_name('DemoTeamTwenteStrategy')
     tree.add_node(node)
     tree.nodes.get(tree.root).add_child(node.id)
     other_tree = collection.get_tree_by_name('EnterFormationRole')
     collection.update_subtrees_in_collection(other_tree)
     child = tree.nodes.get(node.children[0])
     assert 'properties' not in child.attributes
 def test_update_subtrees_in_collection_from_subtree(self):
     collection = Collection.from_path(self.complete_path)
     tree = collection.get_tree_by_name('EnterFormationTactic')
     tree.nodes.get('x988e2xb3y8h0hmxq').title = 'TestChange'
     collection.update_subtrees_in_collection(tree, tree.nodes.get('l795jdit0tls4k52'))
     role_tree = collection.get_tree_by_name('EnterFormationRole')
     assert len(role_tree.nodes.items()) == 2
     root_node = role_tree.nodes.get(role_tree.root)
     assert root_node.title == 'TestChange'
     assert len(root_node.children) == 1
     assert role_tree.nodes.get(root_node.children[0]).title == 'EnterFormation'
 def test_get_root_nodes_by_category(self):
     collection = Collection.from_path(self.path)
     result = collection.get_root_nodes_by_category("strategies")
     assert "ydjw9of7ndf88" == result[0][0]
     assert "AttackStrategy" == result[0][1]
     result = collection.get_root_nodes_by_category("tactics")
     assert "57mrxn20qviax5qc" == result[0][0]
     assert "Attactic" == result[0][1]
     result = collection.get_root_nodes_by_category("roles")
     assert "sx6fvrxlaoudhmmq9" == result[0][0]
     assert "Assister" == result[0][1]
     result = collection.get_root_nodes_by_category("invalid_category")
     assert len(result) == 0
 def test_update_subtrees_in_collection_invalid(self):
     # no role subtree
     collection = Collection.from_path(self.complete_path)
     collection_copy = deepcopy(collection)
     tree = collection.get_tree_by_name('DemoTeamTwenteStrategy')
     collection.update_subtrees_in_collection(tree, tree.nodes.get(tree.root))
     assert collection_copy == collection
     # role subtree no children
     node = Node('Role', attributes={'role': 'EnterFormationRole'})
     tree_copy = deepcopy(tree)
     tree.add_node(node)
     tree.nodes.get(tree.root).add_child(node.id)
     collection.update_subtrees_in_collection(tree, node)
     collection.collection['strategies']['DemoTeamTwenteStrategy.json'] = tree_copy
     assert collection == collection_copy
 def test_update_subtrees_in_collection_from_main_tree(self):
     collection = Collection.from_path(self.complete_path)
     collection_copy = deepcopy(collection)
     collection_copy.update_subtrees_in_collection(collection_copy.get_tree_by_name('EnterFormationRole'))
     tree = collection_copy.get_tree_by_name('EnterFormationTactic')
     assert collection_copy.get_tree_by_name('EnterFormationTactic') != \
         collection.get_tree_by_name('EnterFormationTactic')
     old_tree = collection.get_tree_by_name('EnterFormationTactic')
     role_nodes = tree.find_role_subtree_nodes_if_exist('EnterFormationRole')
     for role_node in role_nodes:
         child = role_node.children[0]
         assert child not in old_tree.nodes
         child_node = tree.nodes.get(child)
         old_child_id = old_tree.nodes.get(role_node.id).children[0]
         old_child_node = old_tree.nodes.get(old_child_id)
         assert old_child_node.title == child_node.title
         assert old_child_node.id != child_node.id
         assert len(old_child_node.children) == len(child_node.children)
 def test_ssr_tree(self):
     collection = Collection(self.collection)
     tree = self.ssr_tree
     assert 1 is len(collection.verify_tree(tree, "strategies"))
 def test_incorrect_root_nodes_by_writing(self):
     collection = Collection(self.collection)
     tree1 = self.simple_invalid_root_node_tree1
     tree2 = self.simple_invalid_root_node_tree2
     assert len(collection.write_tree(tree1, Path('json/verification/InvalidRootNodeTree1.json'), True)) != 0
     assert len(collection.write_tree(tree2, Path('json/verification/InvalidRootNodeTree2.json'), True)) != 0
 def test_offensive_strategy(self):
     collection = Collection(self.collection)
     tree = self.offensive_strategy_tree
     assert 0 is len(collection.verify_tree(tree, "strategies"))
 def test_complex_tree(self):
     collection = Collection(self.collection)
     tree = self.complex_tree
     result = collection.get_category_from_node(tree.root)
     assert "tactics" == result
     assert 0 is len(collection.verify_tree(tree, "tactics"))
 def test_invalid_decorator_tree(self):
     collection = Collection(self.collection)
     tree = self.simple_invalid_decorator_tree
     assert 0 is not len(collection.verify_tree(tree, "roles"))
 def test_invalid_role_inheritance_tree_2(self):
     collection = Collection(self.collection)
     tree = self.simple_invalid_role_inheritance_tree_2
     assert 0 is not len(collection.verify_tree(tree))
 def test_json_path(self):
     collection = Collection.from_path(self.path)
     assert collection.jsons_path() == self.path
     collection = Collection.from_path()
     assert collection.jsons_path() == Settings.default_json_folder()
 def test_remove_tree_by_name_dir_not_exists(self):
     collection = Collection.from_path(self.path)
     collection.remove_tree_by_name("test", "Assister")
     assert "test" not in collection.collection.keys()
 def test_remove_tree_by_name_tree_not_exists(self):
     collection = Collection.from_path(self.path)
     collection.remove_tree_by_name('roles', "Assister")
     assert "Assister.json" not in collection.collection.get('roles')
     collection.remove_tree_by_name('roles', "Assister")
     assert "Assister.json" not in collection.collection.get('roles')
 def test_ttr_tree(self):
     collection = Collection(self.collection)
     tree = self.ttr_tree
     assert 1 is len(collection.verify_tree(tree, "tactics"))
 def test_rr_tree(self):
     collection = Collection(self.collection)
     tree = self.rr_tree
     assert 1 is len(collection.verify_tree(tree, "roles"))
 def test_simple_valid_tree(self):
     collection = Collection(self.collection)
     tree = self.simple_non_cyclic_tree
     assert 0 is len(collection.verify_tree(tree))