From 475a663c1f05caef20ba582ede832fe6a8687f92 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Wed, 10 May 2023 12:28:38 +0200
Subject: [PATCH] MAINT: remove another rfp and debugging output

---
 integrationtests/basic_example/test_basic.py | 48 +++++++++-----------
 unittests/test_table_converter.py            |  4 --
 2 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/integrationtests/basic_example/test_basic.py b/integrationtests/basic_example/test_basic.py
index 15aee62b..f67628b3 100755
--- a/integrationtests/basic_example/test_basic.py
+++ b/integrationtests/basic_example/test_basic.py
@@ -26,38 +26,35 @@
 an integration test module that does basic integration tests
 """
 
-from caosadvancedtools.crawler import Crawler as OldCrawler
-from caoscrawler.debug_tree import DebugTree
-import os
-from caosdb import EmptyUniqueQueryError
 import argparse
+import os
 import sys
 from argparse import RawTextHelpFormatter
+from pathlib import Path
+
+import caosdb as db
+import pytest
+import yaml
+from caosadvancedtools.crawler import Crawler as OldCrawler
+from caosadvancedtools.models.parser import parse_model_from_yaml
 from caoscrawler import Crawler, SecurityMode
+from caoscrawler.debug_tree import DebugTree
 from caoscrawler.identifiable import Identifiable
-import caosdb as db
 from caoscrawler.identifiable_adapters import CaosDBIdentifiableAdapter
 from caoscrawler.scanner import scan_directory
-import pytest
-from caosadvancedtools.models.parser import parse_model_from_yaml
-import yaml
-
+from caosdb import EmptyUniqueQueryError
 from caosdb.utils.register_tests import clear_database, set_test_key
+
 set_test_key("10b128cf8a1372f30aa3697466bb55e76974e0c16a599bb44ace88f19c8f61e2")
 
-#TODO move test related stuff here and remove it from unittests
+# TODO move test related stuff here and remove it from unittests
 
-def rfp(*pathcomponents):
-    """
-    Return full path.
-    Shorthand convenience function.
-    """
-    return os.path.join(os.path.dirname(__file__), *pathcomponents)
+UNITTESTDIR = Path(__file__).parent.parent.parent / "unittests"
 
 
 @pytest.fixture
 def usemodel():
-    model = parse_model_from_yaml(rfp("model.yml"))
+    model = parse_model_from_yaml(UNITTESTDIR / "model.yml")
     model.sync_data_model(noquestion=True, verbose=False)
 
 
@@ -88,8 +85,8 @@ def ident():
 def crawl_standard_test_directory(subdir: str = "examples_article",
                                   cfood: str = "scifolder_cfood.yml",
                                   debug_tree=None):
-    return scan_directory(rfp("..", "..", "unittests", "test_directories", subdir),
-                          rfp("..", "..", "unittests", cfood),
+    return scan_directory(UNITTESTDIR / "test_directories" / subdir,
+                          UNITTESTDIR / cfood,
                           debug_tree=debug_tree)
 
 
@@ -110,7 +107,7 @@ def crawler_extended(ident):
     # correct paths for current working directory
     file_list = [r for r in crawled_data if r.role == "File"]
     for f in file_list:
-        f.file = rfp("..", "..", "unittests", "test_directories", f.file)
+        f.file = UNITTESTDIR / "test_directories" / f.file
     return cr, crawled_data, debug_tree
 
 
@@ -132,7 +129,7 @@ def test_single_insertion(clear_database, usemodel, crawler, ident):
         if res[i].parents[0].name == "PyTestInfo":
             del res[i]
     # uncomment this to recreate the `records.xml` file
-    # filename = rfp("..", "..", "unittests", "records.xml")
+    # filename = UNITTESTDIR/ "records.xml"
     # with open(filename, "w") as f:
     #    xml = res.to_xml()
     #    # Remove noscript and transaction benchmark:
@@ -146,8 +143,8 @@ def test_single_insertion(clear_database, usemodel, crawler, ident):
 
     # Do a second run on the same data, there should be no changes:
     crawler = Crawler(identifiableAdapter=ident)
-    crawled_data = scan_directory(rfp("../../unittests/test_directories", "examples_article"),
-                                  rfp("../../unittests/scifolder_cfood.yml"))
+    crawled_data = scan_directory(UNITTESTDIR/"test_directories", "examples_article",
+                                  UNITTESTDIR/"scifolder_cfood.yml")
     ins, ups = crawler.synchronize(crawled_data=crawled_data)
     assert len(ins) == 0
     assert len(ups) == 0
@@ -215,7 +212,6 @@ def test_insertion_and_update(clear_database, usemodel, ident, crawler):
 
     cr = Crawler(identifiableAdapter=ident)
     crawled_data = crawl_standard_test_directory("example_overwrite_1")
-    # cr.save_debug_data(rfp("provenance.yml"))
     assert len(crawled_data) == 3
     ins, ups = cr.synchronize(crawled_data=crawled_data)
     assert len(ins) == 0
@@ -318,7 +314,7 @@ def test_file_update(clear_database, usemodel, ident, crawler_extended):
 
     file_list = [r for r in crawled_data if r.role == "File"]
     for f in file_list:
-        f.file = rfp("..", "..", "unittests", "test_directories", f.file)
+        f.file = UNITTESTDIR / "test_directories", f.file
     ins2, ups2 = cr.synchronize(crawled_data=crawled_data, commit_changes=True)
     assert len(ups1) == 0
     assert len(ups2) == 0
@@ -333,7 +329,7 @@ def test_file_update(clear_database, usemodel, ident, crawler_extended):
 
     file_list = [r for r in crawled_data if r.role == "File"]
     for f in file_list:
-        f.file = rfp("..", "..", "unittests", "test_directories", f.file)
+        f.file = UNITTESTDIR / "test_directories", f.file
     ins3, ups3 = cr2.synchronize(crawled_data=crawled_data, commit_changes=True)
     assert len(ups3) == 11
 
diff --git a/unittests/test_table_converter.py b/unittests/test_table_converter.py
index 12fcabf9..178393d9 100644
--- a/unittests/test_table_converter.py
+++ b/unittests/test_table_converter.py
@@ -146,10 +146,6 @@ def test_crawl_csv_table():
                    rfp("test_directories", "examples_tables", "crawler_for_tables.yml"),
                    debug_tree=dbt)
     for file_ext in ["xlsx", "csv"]:
-        print(dbt.debug_tree)
-        print(dircheckstr(
-            UNITTESTDIR / "test_directories" / "examples_tables" / "ExperimentalData",
-            "test1." + file_ext))
         subd = dbt.debug_tree[dircheckstr(
             UNITTESTDIR / "test_directories" / "examples_tables" / "ExperimentalData",
             "test1." + file_ext)]
-- 
GitLab