Skip to content
Snippets Groups Projects
Commit 388930ab authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

ENH: cleaned up deubg tree and streamlined unit testing

parent da94b3d0
No related branches found
No related tags found
1 merge request!53Release 0.1
...@@ -79,7 +79,9 @@ class FileSystemStructureElement(StructureElement): ...@@ -79,7 +79,9 @@ class FileSystemStructureElement(StructureElement):
self.path = path self.path = path
def __str__(self): def __str__(self):
return "{}: {}, {}".format(self.__class__, self.name, self.path) class_name_short = str(self.__class__).replace(
"<class \'", "")[:-2]
return "{}: {}, {}".format(class_name_short, self.name, self.path)
class Directory(FileSystemStructureElement): class Directory(FileSystemStructureElement):
pass pass
...@@ -389,7 +391,7 @@ class Crawler(object): ...@@ -389,7 +391,7 @@ class Crawler(object):
self.debug = debug self.debug = debug
if self.debug: if self.debug:
self.debug_tree = dict() self.debug_tree: dict[str, tuple] = dict()
def crawl_directory(self, dirname: str, def crawl_directory(self, dirname: str,
cfood: str): cfood: str):
...@@ -466,7 +468,7 @@ class Crawler(object): ...@@ -466,7 +468,7 @@ class Crawler(object):
children = converter.create_children(generalStore_copy, element) children = converter.create_children(generalStore_copy, element)
if self.debug: if self.debug:
self.debug_tree[str(element)] = ( self.debug_tree[str(element)] = (
generalStore_copy, recordStore_copy) generalStore_copy.storage, recordStore_copy.storage)
self.crawl(children, global_converters, converter.converters, self.crawl(children, global_converters, converter.converters,
generalStore_copy, recordStore_copy) generalStore_copy, recordStore_copy)
......
...@@ -4,12 +4,36 @@ ...@@ -4,12 +4,36 @@
# A. Schlemmer, 06/2021 # A. Schlemmer, 06/2021
from newcrawler import Crawler from newcrawler import Crawler
from os.path import join, dirname from os.path import join, dirname, basename
import yaml
def rfp(*pathcomponents):
"""
Return full path.
Shorthand convenience function.
"""
return join(dirname(__file__), *pathcomponents)
def dircheckstr(*pathcomponents):
"""
Return the debug tree identifier for a given path.
"""
return "newcrawler.crawl.Directory: " + basename(join(*pathcomponents)) + ", " + rfp("test_directories", "examples_article", *pathcomponents)
def test_crawler(): def test_crawler():
crawler = Crawler(debug=True) crawler = Crawler(debug=True)
crawler.crawl_directory(join(dirname(__file__), "test_directories/examples_article"), crawler.crawl_directory(rfp("test_directories", "examples_article"),
join(dirname(__file__), "scifolder_cfood.yml")) rfp("scifolder_cfood.yml"))
# debug_variables = dict()
# for k, v in crawler.debug_tree.items():
# debug_variables[k] = v[0]
# print(yaml.dump(debug_variables))
print(crawler.debug_tree) subd = crawler.debug_tree[dircheckstr("DataAnalysis")]
assert crawler.generalStore["date"] == "test" assert len(subd) == 2
assert len(subd[0]) == 0
subd = crawler.debug_tree[dircheckstr("DataAnalysis", "2020_climate-model-predict")]
assert len(subd[0]) == 2
assert subd[0]["date"] == "2020"
assert subd[0]["identifier"] == "climate-model-predict"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment