Skip to content

Commit 4f1dfea

Browse files
local_replace: improve self-test.
* Add automatic counting of failed self-tests. * Use print() statement as preparation for python3 move. This can be done now that we require Python 2.7.
1 parent 4010a36 commit 4f1dfea

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

share/roundup/templates/devel/extensions/local_replace.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import re
23

34
hg_url_base = r'http://sourceforge.net/p/roundup/code/ci/'
@@ -29,12 +30,21 @@ def init(instance):
2930
instance.registerUtil('localReplace', local_replace)
3031

3132
def quicktest(msgstr, should_replace = True):
32-
if not should_replace:
33-
print "(no)",
34-
print "'%s' -> '%s'" % (msgstr, local_replace(msgstr))
33+
testcount['run'] += 1
34+
replacedstr = local_replace(msgstr)
35+
36+
if not (not replacedstr == msgstr ) == should_replace:
37+
print("(fail)", end=' ')
38+
testcount['failed'] += 1
39+
40+
if replacedstr == msgstr:
41+
print( "'%s'" % (msgstr,))
42+
else:
43+
print("'%s' -> '%s'" % (msgstr, replacedstr))
3544

3645
if "__main__" == __name__:
37-
print "Replacement examples. '(no)' should result in no replacement:"
46+
testcount = {'run':0 , 'failed': 0}
47+
print("Replacement examples:")
3848
quicktest(" debian:#222")
3949
quicktest(" #555")
4050
quicktest("issue333")
@@ -55,3 +65,5 @@ def quicktest(msgstr, should_replace = True):
5565
quicktest("rev4891:ad3d628e73f2")
5666
quicktest("hg4891:ad3d628e73f2")
5767
quicktest("changeset: 4542:46239c21a1eb")
68+
print()
69+
print(testcount)

share/roundup/templates/responsive/extensions/local_replace.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import re
23

34
hg_url_base = r'http://sourceforge.net/p/roundup/code/ci/'
@@ -29,12 +30,21 @@ def init(instance):
2930
instance.registerUtil('localReplace', local_replace)
3031

3132
def quicktest(msgstr, should_replace = True):
32-
if not should_replace:
33-
print "(no)",
34-
print "'%s' -> '%s'" % (msgstr, local_replace(msgstr))
33+
testcount['run'] += 1
34+
replacedstr = local_replace(msgstr)
35+
36+
if not (not replacedstr == msgstr ) == should_replace:
37+
print("(fail)", end=' ')
38+
testcount['failed'] += 1
39+
40+
if replacedstr == msgstr:
41+
print( "'%s'" % (msgstr,))
42+
else:
43+
print("'%s' -> '%s'" % (msgstr, replacedstr))
3544

3645
if "__main__" == __name__:
37-
print "Replacement examples. '(no)' should result in no replacement:"
46+
testcount = {'run':0 , 'failed': 0}
47+
print("Replacement examples:")
3848
quicktest(" debian:#222")
3949
quicktest(" #555")
4050
quicktest("issue333")
@@ -55,3 +65,5 @@ def quicktest(msgstr, should_replace = True):
5565
quicktest("rev4891:ad3d628e73f2")
5666
quicktest("hg4891:ad3d628e73f2")
5767
quicktest("changeset: 4542:46239c21a1eb")
68+
print()
69+
print(testcount)

website/issues/extensions/local_replace.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import re
23

34
hg_url_base = r'http://sourceforge.net/p/roundup/code/ci/'
@@ -29,12 +30,21 @@ def init(instance):
2930
instance.registerUtil('localReplace', local_replace)
3031

3132
def quicktest(msgstr, should_replace = True):
32-
if not should_replace:
33-
print "(no)",
34-
print "'%s' -> '%s'" % (msgstr, local_replace(msgstr))
33+
testcount['run'] += 1
34+
replacedstr = local_replace(msgstr)
35+
36+
if not (not replacedstr == msgstr ) == should_replace:
37+
print("(fail)", end=' ')
38+
testcount['failed'] += 1
39+
40+
if replacedstr == msgstr:
41+
print( "'%s'" % (msgstr,))
42+
else:
43+
print("'%s' -> '%s'" % (msgstr, replacedstr))
3544

3645
if "__main__" == __name__:
37-
print "Replacement examples. '(no)' should result in no replacement:"
46+
testcount = {'run':0 , 'failed': 0}
47+
print("Replacement examples:")
3848
quicktest(" debian:#222")
3949
quicktest(" #555")
4050
quicktest("issue333")
@@ -55,3 +65,5 @@ def quicktest(msgstr, should_replace = True):
5565
quicktest("rev4891:ad3d628e73f2")
5666
quicktest("hg4891:ad3d628e73f2")
5767
quicktest("changeset: 4542:46239c21a1eb")
68+
print()
69+
print(testcount)

0 commit comments

Comments
 (0)