diff --git a/docs/build/doctrees/api.doctree b/docs/build/doctrees/api.doctree index fb5e2ab..a194c7b 100644 Binary files a/docs/build/doctrees/api.doctree and b/docs/build/doctrees/api.doctree differ diff --git a/docs/build/doctrees/environment.pickle b/docs/build/doctrees/environment.pickle index 854025c..d7258ec 100644 Binary files a/docs/build/doctrees/environment.pickle and b/docs/build/doctrees/environment.pickle differ diff --git a/docs/build/doctrees/index.doctree b/docs/build/doctrees/index.doctree index c2f8b54..b79bf34 100644 Binary files a/docs/build/doctrees/index.doctree and b/docs/build/doctrees/index.doctree differ diff --git a/docs/build/html/_modules/pynodes.html b/docs/build/html/_modules/pynodes.html index 7340df3..b962f86 100644 --- a/docs/build/html/_modules/pynodes.html +++ b/docs/build/html/_modules/pynodes.html @@ -115,8 +115,8 @@
[docs] def add_child(self, child: Node) -> None: - """ - Add new child node to current instance + """ + Add new child node to current instance :param child: Node object """ @@ -133,13 +133,17 @@ @property def siblings(self) -> list[Node]: - """ returns all the siblings of the Node object """ + """ + Returns all the siblings of the Node object + """ if self.has_siblings(): return self.parent.children @property def parents(self) -> list[Node]: - """ returns all the ancestors of the Node object """ + """ + Returns all the ancestors of the Node object + """ parents = [] p = self while p.has_parent(): @@ -149,7 +153,9 @@ @property def level(self) -> int: - """ returns the level of the Node object """ + """ + Returns the level of the Node object + """ level = 0 p = self while p.has_parent(): @@ -160,7 +166,7 @@ @property def path(self) -> str: """ - returns a representation of the ancestor lineage of self + Returns a representation of the ancestor lineage of self """ path = '' for p in reversed(self.parents): @@ -185,7 +191,9 @@
[docs] def is_child(self, other: str) -> bool: - """ check if Node object is a child of the other Node object """ + """ + Check if Node object is a child of the other Node object + """ if other in [s.name for s in self.children]: return True else: @@ -195,7 +203,9 @@
[docs] def pretty_print(self, option: str = 'default') -> None: - """ print children tree from current instance """ + """ + Print children tree from current instance + """ dashes = ' '*self.level+'|'+'--'*self.level+' ' if option == 'id': dashes += f'[{self.id}] ' diff --git a/docs/build/html/_sources/index.rst.txt b/docs/build/html/_sources/index.rst.txt index e76e590..91d0d40 100644 --- a/docs/build/html/_sources/index.rst.txt +++ b/docs/build/html/_sources/index.rst.txt @@ -48,14 +48,10 @@ Basic Usage: alice.pretty_print() -.. code-block:: - :caption: Pretty print of the tree - - Alice - -- Bob - -- Eve - - + Alice + -- Bob + -- Eve + diff --git a/docs/build/html/api.html b/docs/build/html/api.html index e2dc21a..d587041 100644 --- a/docs/build/html/api.html +++ b/docs/build/html/api.html @@ -159,7 +159,7 @@ found

is_child(other: str) bool[source]
-

check if Node object is a child of the other Node object

+

Check if Node object is a child of the other Node object

@@ -176,25 +176,25 @@ found

property level: int
-

returns the level of the Node object

+

Returns the level of the Node object

property parents: list[Node]
-

returns all the ancestors of the Node object

+

Returns all the ancestors of the Node object

property path: str
-

returns a representation of the ancestor lineage of self

+

Returns a representation of the ancestor lineage of self

pretty_print(option: str = 'default') None[source]
-

print children tree from current instance

+

Print children tree from current instance

@@ -206,7 +206,7 @@ found

property siblings: list[Node]
-

returns all the siblings of the Node object

+

Returns all the siblings of the Node object

diff --git a/docs/build/html/index.html b/docs/build/html/index.html index 1150f95..23fbfe7 100644 --- a/docs/build/html/index.html +++ b/docs/build/html/index.html @@ -111,16 +111,12 @@ alice.add_child(eve) alice.pretty_print() + +Alice + -- Bob + -- Eve
-
-
Pretty print of the tree
-
    Alice
-      -- Bob
-      -- Eve
-
-
-
diff --git a/docs/build/html/searchindex.js b/docs/build/html/searchindex.js index 5fe6d60..ee8532b 100644 --- a/docs/build/html/searchindex.js +++ b/docs/build/html/searchindex.js @@ -1 +1 @@ -Search.setIndex({"docnames": ["api", "index"], "filenames": ["api.rst", "index.rst"], "titles": ["API", "Welcome to pynodes\u2019s documentation!"], "terms": {"i": [0, 1], "python": 0, "librari": 0, "manag": 0, "node": [0, 1], "class": [0, 1], "A": 0, "an": [0, 1], "object": 0, "which": 0, "relat": 0, "other": 0, "given": 0, "tree": [0, 1], "chart": 0, "venv": 1, "pip": [], "instal": [], "import": 1, "name": 0, "str": 0, "parent": [0, 1], "none": 0, "sourc": [0, 1], "should": 0, "subclass": 0, "onli": 0, "add_child": [0, 1], "child": 0, "add": 0, "new": 0, "current": 0, "instanc": [0, 1], "static": 0, "check_lineag": 0, "list": 0, "bool": 0, "check": 0, "straight": 0, "lineag": 0, "1": 0, "ancestor": 0, "2": 0, "3": 0, "n": 0, "grand": 0, "children": 0, "classmethod": 0, "create_random_nod": 0, "type_": 0, "cmd": 0, "depth": 0, "int": 0, "0": 0, "creat": 0, "random": 0, "test": 0, "purpos": 0, "properti": 0, "path": 0, "return": 0, "represent": 0, "self": 0, "pretty_print": [0, 1], "print": [0, 1], "from": 0, "reset_stat": 0, "reset": 0, "all": 0, "classvar": 0, "member": 0, "index": [], "modul": [], "search": [], "page": [], "level": 0, "sibl": 0, "get_child": 0, "find": 0, "specifi": 0, "noth": 0, "found": 0, "get_sibl": 0, "has_children": 0, "ha": 0, "one": 0, "least": 0, "has_par": 0, "has_sibl": 0, "is_child": 0, "is_sibl": 0, "code": 1, "host": 1, "my": 1, "own": 1, "gitea": 1, "link": [], "text": [], "usag": [], "basic": [], "pynod": 0, "api": 1, "thi": 1, "project": 1, "under": 1, "activ": 1, "develop": 1, "person": 1, "pass": 1, "bob": 1, "ev": 1, "alic": 1, "pretti": 1, "alice_again": 1, "rais": 1, "error": 1, "cool": [], "bit": [], "some": [], "option": 0, "default": 0, "git": 1, "clone": 1, "http": 1, "lutix": 1, "org": 1, "ftg": 1, "paramet": 0, "param": [], "compar": 0}, "objects": {"": [[0, 0, 0, "-", "pynodes"]], "pynodes": [[0, 1, 1, "", "Node"]], "pynodes.Node": [[0, 2, 1, "", "add_child"], [0, 2, 1, "", "check_lineage"], [0, 2, 1, "", "create_random_nodes"], [0, 2, 1, "", "get_child"], [0, 2, 1, "", "get_sibling"], [0, 2, 1, "", "has_children"], [0, 2, 1, "", "has_parent"], [0, 2, 1, "", "has_siblings"], [0, 2, 1, "", "is_child"], [0, 2, 1, "", "is_sibling"], [0, 3, 1, "", "level"], [0, 3, 1, "", "parents"], [0, 3, 1, "", "path"], [0, 2, 1, "", "pretty_print"], [0, 2, 1, "", "reset_stats"], [0, 3, 1, "", "siblings"]]}, "objtypes": {"0": "py:module", "1": "py:class", "2": "py:method", "3": "py:property"}, "objnames": {"0": ["py", "module", "Python module"], "1": ["py", "class", "Python class"], "2": ["py", "method", "Python method"], "3": ["py", "property", "Python property"]}, "titleterms": {"welcom": 1, "pynod": 1, "": 1, "document": 1, "basic": 1, "usag": 1, "indic": [], "tabl": [], "instal": 1, "api": 0, "content": 1}, "envversion": {"sphinx.domains.c": 3, "sphinx.domains.changeset": 1, "sphinx.domains.citation": 1, "sphinx.domains.cpp": 9, "sphinx.domains.index": 1, "sphinx.domains.javascript": 3, "sphinx.domains.math": 2, "sphinx.domains.python": 4, "sphinx.domains.rst": 2, "sphinx.domains.std": 2, "sphinx.ext.viewcode": 1, "sphinx": 60}, "alltitles": {"Welcome to pynodes\u2019s documentation!": [[1, "welcome-to-pynodes-s-documentation"]], "Content:": [[1, "content"]], "Installation:": [[1, "installation"]], "Basic Usage:": [[1, "basic-usage"]], "API": [[0, "api"]]}, "indexentries": {"node (class in pynodes)": [[0, "pynodes.Node"]], "add_child() (pynodes.node method)": [[0, "pynodes.Node.add_child"]], "check_lineage() (pynodes.node static method)": [[0, "pynodes.Node.check_lineage"]], "create_random_nodes() (pynodes.node class method)": [[0, "pynodes.Node.create_random_nodes"]], "get_child() (pynodes.node method)": [[0, "pynodes.Node.get_child"]], "get_sibling() (pynodes.node method)": [[0, "pynodes.Node.get_sibling"]], "has_children() (pynodes.node method)": [[0, "pynodes.Node.has_children"]], "has_parent() (pynodes.node method)": [[0, "pynodes.Node.has_parent"]], "has_siblings() (pynodes.node method)": [[0, "pynodes.Node.has_siblings"]], "is_child() (pynodes.node method)": [[0, "pynodes.Node.is_child"]], "is_sibling() (pynodes.node method)": [[0, "pynodes.Node.is_sibling"]], "level (pynodes.node property)": [[0, "pynodes.Node.level"]], "module": [[0, "module-pynodes"]], "parents (pynodes.node property)": [[0, "pynodes.Node.parents"]], "path (pynodes.node property)": [[0, "pynodes.Node.path"]], "pretty_print() (pynodes.node method)": [[0, "pynodes.Node.pretty_print"]], "pynodes": [[0, "module-pynodes"]], "reset_stats() (pynodes.node class method)": [[0, "pynodes.Node.reset_stats"]], "siblings (pynodes.node property)": [[0, "pynodes.Node.siblings"]]}}) \ No newline at end of file +Search.setIndex({"docnames": ["api", "index"], "filenames": ["api.rst", "index.rst"], "titles": ["API", "Welcome to pynodes\u2019s documentation!"], "terms": {"i": [0, 1], "python": 0, "librari": 0, "manag": 0, "node": [0, 1], "class": [0, 1], "A": 0, "an": [0, 1], "object": 0, "which": 0, "relat": 0, "other": 0, "given": 0, "tree": 0, "chart": 0, "venv": 1, "pip": [], "instal": [], "import": 1, "name": 0, "str": 0, "parent": [0, 1], "none": 0, "sourc": [0, 1], "should": 0, "subclass": 0, "onli": 0, "add_child": [0, 1], "child": 0, "add": 0, "new": 0, "current": 0, "instanc": [0, 1], "static": 0, "check_lineag": 0, "list": 0, "bool": 0, "check": 0, "straight": 0, "lineag": 0, "1": 0, "ancestor": 0, "2": 0, "3": 0, "n": 0, "grand": 0, "children": 0, "classmethod": 0, "create_random_nod": 0, "type_": 0, "cmd": 0, "depth": 0, "int": 0, "0": 0, "creat": 0, "random": 0, "test": 0, "purpos": 0, "properti": 0, "path": 0, "return": 0, "represent": 0, "self": 0, "pretty_print": [0, 1], "print": 0, "from": 0, "reset_stat": 0, "reset": 0, "all": 0, "classvar": 0, "member": 0, "index": [], "modul": [], "search": [], "page": [], "level": 0, "sibl": 0, "get_child": 0, "find": 0, "specifi": 0, "noth": 0, "found": 0, "get_sibl": 0, "has_children": 0, "ha": 0, "one": 0, "least": 0, "has_par": 0, "has_sibl": 0, "is_child": 0, "is_sibl": 0, "code": 1, "host": 1, "my": 1, "own": 1, "gitea": 1, "link": [], "text": [], "usag": [], "basic": [], "pynod": 0, "api": 1, "thi": 1, "project": 1, "under": 1, "activ": 1, "develop": 1, "person": 1, "pass": 1, "bob": 1, "ev": 1, "alic": 1, "pretti": [], "alice_again": 1, "rais": 1, "error": 1, "cool": [], "bit": [], "some": [], "option": 0, "default": 0, "git": 1, "clone": 1, "http": 1, "lutix": 1, "org": 1, "ftg": 1, "paramet": 0, "param": [], "compar": 0, "cookbook": [], "crawl": [], "web": [], "The": [], "most": [], "simpl": [], "wai": [], "us": [], "our": [], "program": [], "argument": [], "simpli": [], "run": [], "main": [], "py": [], "u": [], "url": [], "webpag": [], "slowli": [], "To": [], "delai": [], "your": [], "crawler": [], "d": [], "10": [], "wait": [], "second": [], "between": [], "fetch": [], "blog": [], "you": [], "want": [], "flag": [], "while": [], "ignor": [], "match": [], "regex": [], "contain": []}, "objects": {"": [[0, 0, 0, "-", "pynodes"]], "pynodes": [[0, 1, 1, "", "Node"]], "pynodes.Node": [[0, 2, 1, "", "add_child"], [0, 2, 1, "", "check_lineage"], [0, 2, 1, "", "create_random_nodes"], [0, 2, 1, "", "get_child"], [0, 2, 1, "", "get_sibling"], [0, 2, 1, "", "has_children"], [0, 2, 1, "", "has_parent"], [0, 2, 1, "", "has_siblings"], [0, 2, 1, "", "is_child"], [0, 2, 1, "", "is_sibling"], [0, 3, 1, "", "level"], [0, 3, 1, "", "parents"], [0, 3, 1, "", "path"], [0, 2, 1, "", "pretty_print"], [0, 2, 1, "", "reset_stats"], [0, 3, 1, "", "siblings"]]}, "objtypes": {"0": "py:module", "1": "py:class", "2": "py:method", "3": "py:property"}, "objnames": {"0": ["py", "module", "Python module"], "1": ["py", "class", "Python class"], "2": ["py", "method", "Python method"], "3": ["py", "property", "Python property"]}, "titleterms": {"welcom": 1, "pynod": 1, "": 1, "document": 1, "basic": 1, "usag": 1, "indic": [], "tabl": [], "instal": 1, "api": 0, "content": 1}, "envversion": {"sphinx.domains.c": 3, "sphinx.domains.changeset": 1, "sphinx.domains.citation": 1, "sphinx.domains.cpp": 9, "sphinx.domains.index": 1, "sphinx.domains.javascript": 3, "sphinx.domains.math": 2, "sphinx.domains.python": 4, "sphinx.domains.rst": 2, "sphinx.domains.std": 2, "sphinx.ext.viewcode": 1, "sphinx": 60}, "alltitles": {"Welcome to pynodes\u2019s documentation!": [[1, "welcome-to-pynodes-s-documentation"]], "Content:": [[1, "content"]], "Installation:": [[1, "installation"]], "Basic Usage:": [[1, "basic-usage"]], "API": [[0, "api"]]}, "indexentries": {"node (class in pynodes)": [[0, "pynodes.Node"]], "add_child() (pynodes.node method)": [[0, "pynodes.Node.add_child"]], "check_lineage() (pynodes.node static method)": [[0, "pynodes.Node.check_lineage"]], "create_random_nodes() (pynodes.node class method)": [[0, "pynodes.Node.create_random_nodes"]], "get_child() (pynodes.node method)": [[0, "pynodes.Node.get_child"]], "get_sibling() (pynodes.node method)": [[0, "pynodes.Node.get_sibling"]], "has_children() (pynodes.node method)": [[0, "pynodes.Node.has_children"]], "has_parent() (pynodes.node method)": [[0, "pynodes.Node.has_parent"]], "has_siblings() (pynodes.node method)": [[0, "pynodes.Node.has_siblings"]], "is_child() (pynodes.node method)": [[0, "pynodes.Node.is_child"]], "is_sibling() (pynodes.node method)": [[0, "pynodes.Node.is_sibling"]], "level (pynodes.node property)": [[0, "pynodes.Node.level"]], "module": [[0, "module-pynodes"]], "parents (pynodes.node property)": [[0, "pynodes.Node.parents"]], "path (pynodes.node property)": [[0, "pynodes.Node.path"]], "pretty_print() (pynodes.node method)": [[0, "pynodes.Node.pretty_print"]], "pynodes": [[0, "module-pynodes"]], "reset_stats() (pynodes.node class method)": [[0, "pynodes.Node.reset_stats"]], "siblings (pynodes.node property)": [[0, "pynodes.Node.siblings"]]}}) \ No newline at end of file diff --git a/docs/source/index.rst b/docs/source/index.rst index e76e590..91d0d40 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -48,14 +48,10 @@ Basic Usage: alice.pretty_print() -.. code-block:: - :caption: Pretty print of the tree - - Alice - -- Bob - -- Eve - - + Alice + -- Bob + -- Eve + diff --git a/pynodes.py b/pynodes.py index 7a65fa2..e36326d 100644 --- a/pynodes.py +++ b/pynodes.py @@ -232,26 +232,4 @@ class Node: return self.name if __name__ == "__main__": - -# while True: -# master_node = Node.create_random_nodes(depth=3, type_='cmd') -# node_list = [master_node, master_node.children[0], -# master_node.children[0].children[0]] -# random.shuffle(node_list) -# print([n.name for n in node_list]) -# print(Node.check_lineage(node_list)) -# input('pause') - class Person(Node): - pass - - bob = Person('Bob') - eve = Person('Eve') - alice = Person('Alice') - - # Alice is parent of bob and eve - alice.add_child(bob) - alice.add_child(eve) - - alice.pretty_print(option = 'id') - - print(alice.id) + pass diff --git a/docs/source/.index.rst.swp b/tests/.test_nodes.py.swp similarity index 86% rename from docs/source/.index.rst.swp rename to tests/.test_nodes.py.swp index e11ccbf..c5de6e4 100644 Binary files a/docs/source/.index.rst.swp and b/tests/.test_nodes.py.swp differ diff --git a/tests/test_nodes.py b/tests/test_nodes.py new file mode 100644 index 0000000..94b330c --- /dev/null +++ b/tests/test_nodes.py @@ -0,0 +1,21 @@ +from pathlib import Path +import sys +# to include the main lib of the tests +sys.path.append(str(Path(__file__).parent.parent)) + +from pynodes import Node + +if __name__ == '__main__': + class Person(Node): + pass + + bob = Person('Bob') + eve = Person('Eve') + alice = Person('Alice') + + # Alice is parent of bob and eve + alice.add_child(bob) + alice.add_child(eve) + + alice.pretty_print(option = 'id') + diff --git a/tests/tests.py b/tests/tests.py index 48b7b92..7a79355 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1,20 +1,9 @@ -import inspect +from pathlib import Path +import sys +# to include the main lib of the tests +sys.path.append(str(Path(__file__).parent.parent)) -def f(*args, **kwargs): - print(kwargs) - -class SquareNumber(int): - def __new__(cls): - return super().__new__(cls) - - -class Test: - def __new__(cls, *args): - print(args[0]) - return super().__new__(cls) - - def __init__(self, first_arg: str = 'first', second_arg: str = 'second' ): - self.name = first_arg +import pynodes if __name__ == '__main__': - t = Test(first_arg = 'hello', second_arg = 'world') + pass