diff roundup/test/memorydb.py @ 6361:58817c3bf471

Fix roundup/test Move the test-detectors in tx_Source_detector.py to roundup/test for two reasons: It's used in the memorydb convenience functions and it may be useful in other tests. Make the prefix a paramter of the convenience functions to be usable in other tests.
author Ralf Schlatterbeck <rsc@runtux.com>
date Tue, 30 Mar 2021 14:16:28 +0200
parents a77a7d04ed23
children 7f00fc5958ca
line wrap: on
line diff
--- a/roundup/test/memorydb.py	Tue Mar 30 09:10:46 2021 +0200
+++ b/roundup/test/memorydb.py	Tue Mar 30 14:16:28 2021 +0200
@@ -16,11 +16,18 @@
 from roundup.backends import indexer_common
 from roundup.support import ensureParentsExist
 from roundup.anypy.strings import s2b
+from roundup.test.tx_Source_detector import init as tx_Source_init
 
-def new_config(debug=False):
+default_prefix = '../../share/roundup/templates/classic'
+
+def new_config(debug=False, prefix=default_prefix):
+    if not prefix.startswith('/'):
+        prefix = os.path.join (os.path.dirname(__file__), prefix)
     config = configuration.CoreConfig()
-    config.detectors = configuration.UserConfig("share/roundup/templates/classic/detectors/config.ini")
-    config.ext = configuration.UserConfig("share/roundup/templates/classic/extensions/config.ini")
+    config.detectors = configuration.UserConfig(
+        os.path.join(prefix, "detectors/config.ini"))
+    config.ext = configuration.UserConfig(
+        os.path.join(prefix, "extensions/config.ini"))
     config.DATABASE = "db"
     #config.logging = MockNull()
     # these TRACKER_WEB and MAIL_DOMAIN values are used in mailgw tests
@@ -30,28 +37,26 @@
     config.TRACKER_WEB = "http://tracker.example/cgi-bin/roundup.cgi/bugs/"
     return config
 
-def create(journaltag, create=True, debug=False):
+def create(journaltag, create=True, debug=False, prefix=default_prefix):
     db = Database(new_config(debug), journaltag)
 
     # load standard schema
-    schema = os.path.join(os.path.dirname(__file__),
-        '../share/roundup/templates/classic/schema.py')
+    if not prefix.startswith('/'):
+        prefix = os.path.join (os.path.dirname(__file__), prefix)
+    schema = os.path.join(prefix, 'schema.py')
     vars = hyperdb.__dict__
     vars['Class'] = Class
     vars['FileClass'] = FileClass
     vars['IssueClass'] = IssueClass
     vars['db'] = db
     exec(compile(open(schema).read(), schema, 'exec'), vars)
-    initial_data = os.path.join(os.path.dirname(__file__),
-        '../share/roundup/templates/classic/initial_data.py')
+    initial_data = os.path.join(prefix, 'initial_data.py')
     vars = dict(db=db, admin_email='admin@test.com',
         adminpw=password.Password('sekrit'))
     exec(compile(open(initial_data).read(), initial_data, 'exec'), vars)
 
     # load standard detectors
-    thisdir = os.path.dirname(__file__)
-    dirname = os.path.join(thisdir,
-        '../share/roundup/templates/classic/detectors')
+    dirname = os.path.join(prefix, 'detectors')
     for fn in os.listdir(dirname):
         if not fn.endswith('.py'): continue
         vars = {}
@@ -59,10 +64,7 @@
                      os.path.join(dirname, fn), 'exec'), vars)
         vars['init'](db)
 
-    vars = {}
-    exec(compile(open(os.path.join(thisdir, "tx_Source_detector.py")).read(),
-                 os.path.join(thisdir, "tx_Source_detector.py"), 'exec'), vars)
-    vars['init'](db)
+    tx_Source_init(db)
 
     '''
     status = Class(db, "status", name=String())

Roundup Issue Tracker: http://roundup-tracker.org/