6817: Enhancements for testing localized Relationship handlers (contribution by Fedir)

svn: r22535
This commit is contained in:
Jérôme Rapinat
2013-06-20 10:07:41 +00:00
parent 87499c96bc
commit fab092f6fd

View File

@@ -1840,7 +1840,7 @@ def get_relationship_calculator(reinit=False, clocale=glocale):
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def _test(rc, onlybirth, inlawa, inlawb, printrelstr): def _test(rc, onlybirth, inlawa, inlawb, printrelstr, testNum = None):
""" this is a generic test suite for the singular relationship """ this is a generic test suite for the singular relationship
TRANSLATORS: do NOT translate, use __main__ ! TRANSLATORS: do NOT translate, use __main__ !
""" """
@@ -1865,291 +1865,333 @@ def _test(rc, onlybirth, inlawa, inlawb, printrelstr):
FMT = '%+50s' FMT = '%+50s'
MAX = 30 MAX = 30
#rc = RelationshipCalculator() if testNum == None:
print """
Select a test:
0 - all tests
1 - testing sons
2 - testing daughters
3 - testing unknown children
4 - testing grandfathers
5 - testing grandmothers
6 - testing unknown parents
7 - testing nieces
8 - testing nephews
9 - testing unknown nephews/nieces
10 - testing uncles
11 - testing aunts
12 - testing unknown uncles/aunts
13 - testing male cousins same generation
14 - testing female cousins same generation
15 - testing unknown cousins same generation
16 - testing some cousins up
17 - testing some cousins down
print('\ntesting sons (Enter to start)\n') Please enter a test number and press Enter for continue:
sys.stdin.readline() """
for i in range(MAX) : testNum = sys.stdin.readline().strip()
relstr = _rand_relstr(i,'f') testNum = int(testNum)
rel = FMT % rc.get_single_relationship_string(0, i,
MALE, if testNum == 0 or testNum == 1:
MALE, print '\ntesting sons'
'', relstr, #sys.stdin.readline()
only_birth=onlybirth, for i in range(MAX) :
in_law_a=inlawa, relstr = _rand_relstr(i,'f')
in_law_b=inlawb) rel = FMT % rc.get_single_relationship_string(0, i,
if printrelstr : MALE,
print(rel + ' |info:', relstr) MALE,
else: '', relstr,
print(rel) only_birth=onlybirth,
print('\n\ntesting daughters\n') in_law_a=inlawa,
sys.stdin.readline() in_law_b=inlawb)
for i in range(MAX) : if printrelstr :
relstr = _rand_relstr(i,'m') print rel + ' |info:', relstr
rel = FMT % rc.get_single_relationship_string(0, i, else:
MALE, print rel
FEMALE, if testNum == 0 or testNum == 2:
'', relstr, print '\ntesting daughters\n'
only_birth=onlybirth, #sys.stdin.readline()
in_law_a=inlawa, in_law_b=inlawb) for i in range(MAX) :
if printrelstr : relstr = _rand_relstr(i,'m')
print(rel + ' |info:', relstr) rel = FMT % rc.get_single_relationship_string(0, i,
else: MALE,
print(rel) FEMALE,
print('\n\ntesting unknown children\n') '', relstr,
sys.stdin.readline() only_birth=onlybirth,
for i in range(MAX) : in_law_a=inlawa, in_law_b=inlawb)
relstr = _rand_relstr(i,'f') if printrelstr :
rel = FMT % rc.get_single_relationship_string(0, i, print rel + ' |info:', relstr
MALE, else:
UNKNOWN, print rel
'', relstr, if testNum == 0 or testNum == 3:
only_birth=onlybirth, print '\ntesting unknown children\n'
in_law_a=inlawa, in_law_b=inlawb) #sys.stdin.readline()
if printrelstr : for i in range(MAX) :
print(rel + ' |info:', relstr) relstr = _rand_relstr(i,'f')
else: rel = FMT % rc.get_single_relationship_string(0, i,
print(rel) MALE,
print('\n\ntesting grandfathers\n') UNKNOWN,
sys.stdin.readline() '', relstr,
for i in range(MAX) : only_birth=onlybirth,
relstr = _rand_relstr(i,'f') in_law_a=inlawa, in_law_b=inlawb)
rel = FMT % rc.get_single_relationship_string(i, 0, if printrelstr :
FEMALE, print rel + ' |info:', relstr
MALE, else:
relstr, '', print rel
only_birth=onlybirth, if testNum == 0 or testNum == 4:
in_law_a=inlawa, in_law_b=inlawb) print '\ntesting grandfathers\n'
if printrelstr : #sys.stdin.readline()
print(rel + ' |info:', relstr) for i in range(MAX) :
else: relstr = _rand_relstr(i,'f')
print(rel) rel = FMT % rc.get_single_relationship_string(i, 0,
print('\n\ntesting grandmothers\n') FEMALE,
sys.stdin.readline() MALE,
for i in range(MAX) : relstr, '',
relstr = _rand_relstr(i,'m') only_birth=onlybirth,
rel = FMT % rc.get_single_relationship_string(i, 0, in_law_a=inlawa, in_law_b=inlawb)
FEMALE, if printrelstr :
FEMALE, print rel + ' |info:', relstr
relstr, '', else:
only_birth=onlybirth, print rel
in_law_a=inlawa, in_law_b=inlawb) if testNum == 0 or testNum == 5:
if printrelstr : print '\ntesting grandmothers\n'
print(rel + ' |info:', relstr) #sys.stdin.readline()
else: for i in range(MAX) :
print(rel) relstr = _rand_relstr(i,'m')
print('\n\ntesting unknown parents\n') rel = FMT % rc.get_single_relationship_string(i, 0,
sys.stdin.readline() FEMALE,
for i in range(MAX) : FEMALE,
relstr = _rand_relstr(i,'f') relstr, '',
rel = FMT % rc.get_single_relationship_string(i, 0, only_birth=onlybirth,
FEMALE, in_law_a=inlawa, in_law_b=inlawb)
UNKNOWN, if printrelstr :
relstr, '', print rel + ' |info:', relstr
only_birth=onlybirth, else:
in_law_a=inlawa, in_law_b=inlawb) print rel
if printrelstr : if testNum == 0 or testNum == 6:
print(rel + ' |info:', relstr) print '\ntesting unknown parents\n'
else: #sys.stdin.readline()
print(rel) for i in range(MAX) :
print('\n\ntesting nieces\n') relstr = _rand_relstr(i,'f')
sys.stdin.readline() rel = FMT % rc.get_single_relationship_string(i, 0,
for i in range(1, MAX) : FEMALE,
relstr = _rand_relstr(i,'m') UNKNOWN,
rel = FMT % rc.get_single_relationship_string(1, i, relstr, '',
FEMALE, only_birth=onlybirth,
FEMALE, in_law_a=inlawa, in_law_b=inlawb)
'm', relstr, if printrelstr :
only_birth=onlybirth, print rel + ' |info:', relstr
in_law_a=inlawa, in_law_b=inlawb) else:
if printrelstr : print rel
print(rel + ' |info:', relstr) if testNum == 0 or testNum == 7:
else: print '\ntesting nieces\n'
print(rel) #sys.stdin.readline()
print('\n\ntesting nephews\n') for i in range(1, MAX) :
sys.stdin.readline() relstr = _rand_relstr(i,'m')
for i in range(1, MAX) : rel = FMT % rc.get_single_relationship_string(1, i,
relstr = _rand_relstr(i,'f') FEMALE,
rel = FMT % rc.get_single_relationship_string(1, i, FEMALE,
FEMALE, 'm', relstr,
MALE, only_birth=onlybirth,
'f', relstr, in_law_a=inlawa, in_law_b=inlawb)
only_birth=onlybirth, if printrelstr :
in_law_a=inlawa, in_law_b=inlawb) print rel + ' |info:', relstr
if printrelstr : else:
print(rel + ' |info:', relstr) print rel
else: if testNum == 0 or testNum == 8:
print(rel) print '\ntesting nephews\n'
print('\n\ntesting unknown nephews/nieces\n') #sys.stdin.readline()
sys.stdin.readline() for i in range(1, MAX) :
for i in range(1, MAX) : relstr = _rand_relstr(i,'f')
relstr = _rand_relstr(i,'f') rel = FMT % rc.get_single_relationship_string(1, i,
rel = FMT % rc.get_single_relationship_string(1, i, FEMALE,
FEMALE, MALE,
UNKNOWN, 'f', relstr,
'f', relstr, only_birth=onlybirth,
only_birth=onlybirth, in_law_a=inlawa, in_law_b=inlawb)
in_law_a=inlawa, in_law_b=inlawb) if printrelstr :
if printrelstr : print rel + ' |info:', relstr
print(rel + ' |info:', relstr) else:
else: print rel
print(rel) if testNum == 0 or testNum == 9:
print('\n\ntesting uncles\n') print '\ntesting unknown nephews/nieces\n'
sys.stdin.readline() #sys.stdin.readline()
for i in range(1, MAX) : for i in range(1, MAX) :
relstr = _rand_relstr(i,'f') relstr = _rand_relstr(i,'f')
rel = FMT % rc.get_single_relationship_string(i, 1, rel = FMT % rc.get_single_relationship_string(1, i,
FEMALE, FEMALE,
MALE, UNKNOWN,
relstr, 'f', 'f', relstr,
only_birth=onlybirth, only_birth=onlybirth,
in_law_a=inlawa, in_law_b=inlawb) in_law_a=inlawa, in_law_b=inlawb)
if printrelstr : if printrelstr :
print(rel + ' |info:', relstr) print rel + ' |info:', relstr
else: else:
print(rel) print rel
print('\n\ntesting aunts\n') if testNum == 0 or testNum == 10:
sys.stdin.readline() print '\ntesting uncles\n'
for i in range(1, MAX) : #sys.stdin.readline()
relstr = _rand_relstr(i,'f') for i in range(1, MAX) :
rel = FMT % rc.get_single_relationship_string(i, 1, relstr = _rand_relstr(i,'f')
MALE, rel = FMT % rc.get_single_relationship_string(i, 1,
FEMALE, FEMALE,
relstr, 'f', MALE,
only_birth=onlybirth, relstr, 'f',
in_law_a=inlawa, in_law_b=inlawb) only_birth=onlybirth,
if printrelstr : in_law_a=inlawa, in_law_b=inlawb)
print(rel + ' |info:', relstr) if printrelstr :
else: print rel + ' |info:', relstr
print(rel) else:
print('\n\ntesting unknown uncles/aunts\n') print rel
sys.stdin.readline() if testNum == 0 or testNum == 11:
for i in range(1, MAX) : print '\ntesting aunts\n'
relstr = _rand_relstr(i,'m') #sys.stdin.readline()
rel = FMT % rc.get_single_relationship_string(i, 1, for i in range(1, MAX) :
MALE, relstr = _rand_relstr(i,'f')
UNKNOWN, rel = FMT % rc.get_single_relationship_string(i, 1,
relstr, 'm', MALE,
only_birth=onlybirth, FEMALE,
in_law_a=inlawa, in_law_b=inlawb) relstr, 'f',
if printrelstr : only_birth=onlybirth,
print(rel + ' |info:', relstr) in_law_a=inlawa, in_law_b=inlawb)
else: if printrelstr :
print(rel) print rel + ' |info:', relstr
print('\n\ntesting male cousins same generation\n') else:
sys.stdin.readline() print rel
for i in range(1, MAX) : if testNum == 0 or testNum == 12:
relstra = _rand_relstr(i,'f') print '\ntesting unknown uncles/aunts\n'
relstrb = _rand_relstr(i,'f') #sys.stdin.readline()
rel = FMT % rc.get_single_relationship_string(i, i, for i in range(1, MAX) :
MALE, relstr = _rand_relstr(i,'m')
MALE, rel = FMT % rc.get_single_relationship_string(i, 1,
relstra, MALE,
relstrb, UNKNOWN,
only_birth=onlybirth, relstr, 'm',
in_law_a=inlawa, in_law_b=inlawb) only_birth=onlybirth,
if printrelstr : in_law_a=inlawa, in_law_b=inlawb)
print(rel + ' |info:', relstra, relstrb) if printrelstr :
else: print rel + ' |info:', relstr
print(rel) else:
print('\n\ntesting female cousins same generation\n') print rel
sys.stdin.readline() if testNum == 0 or testNum == 13:
for i in range(1, MAX) : print '\ntesting male cousins same generation\n'
relstra = _rand_relstr(i,'m') #sys.stdin.readline()
relstrb = _rand_relstr(i,'m') for i in range(1, MAX) :
rel = FMT % rc.get_single_relationship_string(i, i, relstra = _rand_relstr(i,'f')
MALE, relstrb = _rand_relstr(i,'f')
FEMALE, rel = FMT % rc.get_single_relationship_string(i, i,
relstra, MALE,
relstrb, MALE,
only_birth=onlybirth, relstra,
in_law_a=inlawa, in_law_b=inlawb) relstrb,
if printrelstr : only_birth=onlybirth,
print(rel + ' |info:', relstra, relstrb) in_law_a=inlawa, in_law_b=inlawb)
else: if printrelstr :
print(rel) print rel + ' |info:', relstra, relstrb
print('\n\ntesting unknown cousins same generation\n') else:
sys.stdin.readline() print rel
for i in range(1, MAX) : if testNum == 0 or testNum == 14:
relstra = _rand_relstr(i,'m') print '\ntesting female cousins same generation\n'
relstrb = _rand_relstr(i,'m') #sys.stdin.readline()
rel = FMT % rc.get_single_relationship_string(i, i, for i in range(1, MAX) :
MALE, relstra = _rand_relstr(i,'m')
UNKNOWN, relstrb = _rand_relstr(i,'m')
relstra, rel = FMT % rc.get_single_relationship_string(i, i,
relstrb, MALE,
only_birth=onlybirth, FEMALE,
in_law_a=inlawa, in_law_b=inlawb) relstra,
if printrelstr : relstrb,
print(rel + ' |info:', relstra, relstrb) only_birth=onlybirth,
else: in_law_a=inlawa, in_law_b=inlawb)
print(rel) if printrelstr :
print('\n\ntesting some cousins up\n') print rel + ' |info:', relstra, relstrb
sys.stdin.readline() else:
import random print rel
random.seed() if testNum == 0 or testNum == 15:
for i in range(1, MAX) : print '\ntesting unknown cousins same generation\n'
for j in range (i, MAX) : #sys.stdin.readline()
rnd = random.randint(0, 100) for i in range(1, MAX) :
if rnd < 10 : relstra = _rand_relstr(i,'m')
relstra = _rand_relstr(j,'f') relstrb = _rand_relstr(i,'m')
relstrb = _rand_relstr(i,'f') rel = FMT % rc.get_single_relationship_string(i, i,
if rnd < 5 : MALE,
rel = (FMT + ' |info: female, Ga=%2d, Gb=%2d') % ( UNKNOWN,
rc.get_single_relationship_string(j, i, relstra,
MALE, relstrb,
FEMALE, only_birth=onlybirth,
relstra, relstrb, in_law_a=inlawa, in_law_b=inlawb)
only_birth=onlybirth, if printrelstr :
in_law_a=inlawa, in_law_b=inlawb), j, i ) print rel + ' |info:', relstra, relstrb
if printrelstr : else:
print(rel + ' |info:', relstra, relstrb) print rel
if testNum == 0 or testNum == 16:
print '\ntesting some cousins up\n'
#sys.stdin.readline()
import random
random.seed()
for i in range(1, MAX) :
for j in range (i, MAX) :
rnd = random.randint(0, 100)
if rnd < 10 :
relstra = _rand_relstr(j,'f')
relstrb = _rand_relstr(i,'f')
if rnd < 5 :
rel = (FMT + ' |info: female, Ga=%2d, Gb=%2d') % (
rc.get_single_relationship_string(j, i,
MALE,
FEMALE,
relstra, relstrb,
only_birth=onlybirth,
in_law_a=inlawa, in_law_b=inlawb), j, i )
if printrelstr :
print rel + ' |info:', relstra, relstrb
else:
print rel
else: else:
print(rel) rel = (FMT + ' |info: male, Ga=%2d, Gb=%2d') % (
else: rc.get_single_relationship_string(j, i,
rel = (FMT + ' |info: male, Ga=%2d, Gb=%2d') % ( MALE,
rc.get_single_relationship_string(j, i, MALE,
MALE, relstra, relstrb,
MALE, only_birth=onlybirth,
relstra, relstrb, in_law_a=inlawa, in_law_b=inlawb), j, i )
only_birth=onlybirth, if printrelstr :
in_law_a=inlawa, in_law_b=inlawb), j, i ) print rel + ' |info:', relstra, relstrb
if printrelstr : else:
print(rel + ' |info:', relstra, relstrb) print rel
if testNum == 0 or testNum == 17:
print '\ntesting some cousins down\n'
#sys.stdin.readline()
for i in range(1, MAX) :
for j in range (i, MAX) :
rnd = random.randint(0, 100)
if rnd < 10 :
relstra = _rand_relstr(i,'f')
relstrb = _rand_relstr(j,'f')
if rnd < 5 :
rel = (FMT + ' |info: female, Ga=%2d, Gb=%2d') % (
rc.get_single_relationship_string(i, j,
MALE,
FEMALE,
relstra, relstrb,
only_birth=onlybirth,
in_law_a=inlawa, in_law_b=inlawb), i, j)
if printrelstr :
print rel + ' |info:', relstra, relstrb
else:
print rel
else: else:
print(rel) rel = (FMT + ' |info: male, Ga=%2d, Gb=%2d') % (
print('\n\ntesting some cousins down\n') rc.get_single_relationship_string(i, j,
sys.stdin.readline() MALE,
for i in range(1, MAX) : MALE,
for j in range (i, MAX) : relstra, relstrb,
rnd = random.randint(0, 100) only_birth=onlybirth,
if rnd < 10 : in_law_a=inlawa, in_law_b=inlawb), i, j)
relstra = _rand_relstr(i,'f') if printrelstr :
relstrb = _rand_relstr(j,'f') print rel + ' |info:', relstra, relstrb
if rnd < 5 : else:
rel = (FMT + ' |info: female, Ga=%2d, Gb=%2d') % ( print rel
rc.get_single_relationship_string(i, j,
MALE,
FEMALE,
relstra, relstrb,
only_birth=onlybirth,
in_law_a=inlawa, in_law_b=inlawb), i, j)
if printrelstr :
print(rel + ' |info:', relstra, relstrb)
else:
print(rel)
else:
rel = (FMT + ' |info: male, Ga=%2d, Gb=%2d') % (
rc.get_single_relationship_string(i, j,
MALE,
MALE,
relstra, relstrb,
only_birth=onlybirth,
in_law_a=inlawa, in_law_b=inlawb), i, j)
if printrelstr :
print(rel + ' |info:', relstr)
else:
print(rel)
def _testsibling(rc): def _testsibling(rc):
vals = [(rc.NORM_SIB, 'sibling'), vals = [(rc.NORM_SIB, 'sibling'),
@@ -2162,9 +2204,9 @@ def _testsibling(rc):
(UNKNOWN, 'unknown')]: (UNKNOWN, 'unknown')]:
for inlaw in [False, True]: for inlaw in [False, True]:
for sibt, str in vals: for sibt, str in vals:
print(FMT % rc.get_sibling_relationship_string( print FMT % rc.get_sibling_relationship_string(
sibt, MALE, gendr, sibt, MALE, gendr,
in_law_a = inlaw) + ' |info:', str, strgen) in_law_a = inlaw) + ' |info:', str, strgen
def _test_spouse(rc): def _test_spouse(rc):
FMT = '%+50s' FMT = '%+50s'
@@ -2180,9 +2222,9 @@ def _test_spouse(rc):
(FEMALE, 'female'), (FEMALE, 'female'),
(UNKNOWN, 'unknown')] : (UNKNOWN, 'unknown')] :
for spouse_type, str in vals: for spouse_type, str in vals:
print(FMT % rc.get_partner_relationship_string( print FMT % rc.get_partner_relationship_string(
spouse_type, MALE, gender) + \ spouse_type, MALE, gender) + \
' |info: gender='+strgen+', rel='+str) ' |info: gender='+strgen+', rel='+str
def test(rc, printrelstr): def test(rc, printrelstr):
""" this is a generic test suite for the singular relationship """ this is a generic test suite for the singular relationship
@@ -2190,31 +2232,53 @@ def test(rc, printrelstr):
__main__ in the rel_xx.py module. __main__ in the rel_xx.py module.
""" """
import sys import sys
import argparse
print('\nType y to do a test\n\n') parser = argparse.ArgumentParser(description='Test the Relationship Calculator')
print('Test normal relations?') parser.add_argument('-r', type=int, help = 'type of the relations test')
data = sys.stdin.readline() parser.add_argument('-s', type=int, help = 'type of the singular relationship test')
if data == 'y\n':
_test(rc, True, False, False, printrelstr) args = parser.parse_args()
print('\n\nTest step relations?') testNum = args.r
data = sys.stdin.readline()
if data == 'y\n': if testNum == None:
_test(rc, False, False, False, printrelstr) print """
print('\n\nTest in-law relations (first pers)?') Select a test:
data = sys.stdin.readline() 0 - all tests
if data == 'y\n': 1 - Test normal relations
_test(rc, True, True, False, printrelstr) 2 - Test step relations
print('\n\nTest step and in-law relations?') 3 - Test in-law relations (first pers)
data = sys.stdin.readline() 4 - Test step and in-law relations
if data == 'y\n': 5 - Test sibling types
_test(rc, False, True, False, printrelstr) 6 - Test partner types
print('\n\nTest sibling types?')
data = sys.stdin.readline() Please enter a test number and press Enter for continue:
if data == 'y\n': """
testNum = sys.stdin.readline().strip()
testNum = int(testNum)
if testNum == 0 or testNum == 1:
print '\n\n=== Test normal relations ==='
_test(rc, True, False, False, printrelstr, args.s)
if testNum == 0 or testNum == 2:
print '\n\n=== Test step relations ==='
_test(rc, False, False, False, printrelstr, args.s)
if testNum == 0 or testNum == 3:
print '\n\n=== Test in-law relations (first pers) ==='
_test(rc, True, True, False, printrelstr, args.s)
if testNum == 0 or testNum == 4:
print '\n\n=== Test step and in-law relations ==='
_test(rc, False, True, False, printrelstr, args.s)
if testNum == 0 or testNum == 5:
print '\n\n=== Test sibling types ==='
_testsibling(rc) _testsibling(rc)
print('\n\nTest partner types?')
data = sys.stdin.readline() if testNum == 0 or testNum == 6:
if data == 'y\n': print '\n\n=== Test partner types ==='
_test_spouse(rc) _test_spouse(rc)
if __name__ == "__main__": if __name__ == "__main__":