Skip to content

Commit 139ba95

Browse files
committed
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.
1 parent da17a19 commit 139ba95

File tree

7 files changed

+29
-38
lines changed

7 files changed

+29
-38
lines changed

CHANGES.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ Features:
102102
- Allow admin to configure language used for stemming in xapian
103103
indexer. (John Rouillard request by Nagy Gabor)
104104
- Move memorydb from test to roundup/test to allow regression-testing in
105-
tracker instances without copying code.
106-
105+
tracker instances without copying code. Also move the test-detectors in
106+
tx_Source_detector.py to roundup/test for two reasons: It's used in the
107+
memorydb convenience functions and it may be useful in other tests. Make
108+
the prefix a paramter of the convenience functions to be usable in other
109+
tests.
107110

108111
2020-07-13 2.0.0
109112

roundup/test/memorydb.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@
1616
from roundup.backends import indexer_common
1717
from roundup.support import ensureParentsExist
1818
from roundup.anypy.strings import s2b
19+
from roundup.test.tx_Source_detector import init as tx_Source_init
1920

20-
def new_config(debug=False):
21+
default_prefix = '../../share/roundup/templates/classic'
22+
23+
def new_config(debug=False, prefix=default_prefix):
24+
if not prefix.startswith('/'):
25+
prefix = os.path.join (os.path.dirname(__file__), prefix)
2126
config = configuration.CoreConfig()
22-
config.detectors = configuration.UserConfig("share/roundup/templates/classic/detectors/config.ini")
23-
config.ext = configuration.UserConfig("share/roundup/templates/classic/extensions/config.ini")
27+
config.detectors = configuration.UserConfig(
28+
os.path.join(prefix, "detectors/config.ini"))
29+
config.ext = configuration.UserConfig(
30+
os.path.join(prefix, "extensions/config.ini"))
2431
config.DATABASE = "db"
2532
#config.logging = MockNull()
2633
# these TRACKER_WEB and MAIL_DOMAIN values are used in mailgw tests
@@ -30,39 +37,34 @@ def new_config(debug=False):
3037
config.TRACKER_WEB = "http://tracker.example/cgi-bin/roundup.cgi/bugs/"
3138
return config
3239

33-
def create(journaltag, create=True, debug=False):
40+
def create(journaltag, create=True, debug=False, prefix=default_prefix):
3441
db = Database(new_config(debug), journaltag)
3542

3643
# load standard schema
37-
schema = os.path.join(os.path.dirname(__file__),
38-
'../share/roundup/templates/classic/schema.py')
44+
if not prefix.startswith('/'):
45+
prefix = os.path.join (os.path.dirname(__file__), prefix)
46+
schema = os.path.join(prefix, 'schema.py')
3947
vars = hyperdb.__dict__
4048
vars['Class'] = Class
4149
vars['FileClass'] = FileClass
4250
vars['IssueClass'] = IssueClass
4351
vars['db'] = db
4452
exec(compile(open(schema).read(), schema, 'exec'), vars)
45-
initial_data = os.path.join(os.path.dirname(__file__),
46-
'../share/roundup/templates/classic/initial_data.py')
53+
initial_data = os.path.join(prefix, 'initial_data.py')
4754
vars = dict(db=db, admin_email='[email protected]',
4855
adminpw=password.Password('sekrit'))
4956
exec(compile(open(initial_data).read(), initial_data, 'exec'), vars)
5057

5158
# load standard detectors
52-
thisdir = os.path.dirname(__file__)
53-
dirname = os.path.join(thisdir,
54-
'../share/roundup/templates/classic/detectors')
59+
dirname = os.path.join(prefix, 'detectors')
5560
for fn in os.listdir(dirname):
5661
if not fn.endswith('.py'): continue
5762
vars = {}
5863
exec(compile(open(os.path.join(dirname, fn)).read(),
5964
os.path.join(dirname, fn), 'exec'), vars)
6065
vars['init'](db)
6166

62-
vars = {}
63-
exec(compile(open(os.path.join(thisdir, "tx_Source_detector.py")).read(),
64-
os.path.join(thisdir, "tx_Source_detector.py"), 'exec'), vars)
65-
vars['init'](db)
67+
tx_Source_init(db)
6668

6769
'''
6870
status = Class(db, "status", name=String())

test/rest_common.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from time import sleep
99
from datetime import datetime, timedelta
10+
from roundup.test.tx_Source_detector import init as tx_Source_init
1011

1112
try:
1213
from datetime import timezone
@@ -230,12 +231,7 @@ def setUp(self):
230231

231232
self.db.post_init()
232233

233-
thisdir = os.path.dirname(__file__)
234-
vars = {}
235-
with open(os.path.join(thisdir, "tx_Source_detector.py")) as f:
236-
code = compile(f.read(), "tx_Source_detector.py", "exec")
237-
exec(code, vars)
238-
vars['init'](self.db)
234+
tx_Source_init(self.db)
239235

240236
env = {
241237
'PATH_INFO': 'http://localhost/rounduptest/rest/',

test/test_cgi.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from roundup.cgi.form_parser import FormParser
2222
from roundup import init, instance, password, hyperdb, date
2323
from roundup.anypy.strings import u2s, b2s, s2b
24+
from roundup.test.tx_Source_detector import init as tx_Source_init
2425

2526
from time import sleep
2627

@@ -83,13 +84,7 @@ class FormTestCase(FormTestParent, StringFragmentCmpHelper, unittest.TestCase):
8384
def setUp(self):
8485
FormTestParent.setUp(self)
8586

86-
vars = {}
87-
thisdir = os.path.dirname(__file__)
88-
exec(compile(open(os.path.join(thisdir,
89-
"tx_Source_detector.py")).read(),
90-
os.path.join(thisdir, "tx_Source_detector.py"), 'exec'),
91-
vars)
92-
vars['init'](self.db)
87+
tx_Source_init(self.db)
9388

9489
test = self.instance.backend.Class(self.db, "test",
9590
string=hyperdb.String(), number=hyperdb.Number(),

test/test_mailgw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from roundup import init, instance, password, __version__
4242

4343
#import db_test_base
44-
from . import memorydb
44+
from roundup.test import memorydb
4545
from .cmp_helper import StringFragmentCmpHelper
4646

4747
def expectedFailure(method):

test/test_xmlrpc.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from roundup.backends import list_backends
1616
from roundup.hyperdb import String
1717
from roundup.cgi import TranslationService
18+
from roundup.test.tx_Source_detector import init as tx_Source_init
1819

1920
from . import db_test_base
2021
from .test_mysql import skip_mysql
@@ -51,13 +52,7 @@ def setUp(self):
5152

5253
self.db.post_init()
5354

54-
thisdir = os.path.dirname(__file__)
55-
vars = {}
56-
exec(compile(open(os.path.join(thisdir,
57-
"tx_Source_detector.py")).read(),
58-
os.path.join(thisdir, "tx_Source_detector.py"), 'exec'),
59-
vars)
60-
vars['init'](self.db)
55+
tx_Source_init(self.db)
6156

6257
self.server = RoundupInstance(self.db, self.instance.actions, None)
6358

0 commit comments

Comments
 (0)