Skip to content

Resolves issue #143: Upgrade to python3 with backward compatibility #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions test/correctness/document-correctness.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_clients(str1, str2, ns):
client_dict['mm'] = lambda: MongoModel("MongoDB")

instance_id = str(random.random())[2:] if ns['instance_id'] == 0 else str(ns['instance_id'])
print 'Instance: ' + instance_id
print ('Instance: ' + instance_id)

client1 = client_dict[str1]()
client2 = client_dict[str2]()
Expand Down Expand Up @@ -141,12 +141,12 @@ def diff_results(cA, rA, cB, rB):
only_b = b - a

if len(only_a) > 0 or len(only_b) > 0:
print " RESULT SET DIFFERENCES (as 'sets' so order within the returned results is not considered)"
print (" RESULT SET DIFFERENCES (as 'sets' so order within the returned results is not considered)")
for x in only_a:
print " Only in", cA.__module__, ":", x
print (" Only in", cA.__module__, ":", x)
for x in only_b:
print " Only in", cB.__module__, ":", x
print
print (" Only in", cB.__module__, ":", x)
print()


zero_resp_queries = 0
Expand All @@ -166,7 +166,7 @@ def check_query(query, collection1, collection2, projection=None, sort=None, lim
ret1 = get_result(query, collection1, projection, sort, limit, skip, exception_msg)
ret2 = get_result(query, collection2, projection, sort, limit, skip, exception_msg)
if len(exception_msg) == 1:
print '\033[91m\n', exception_msg[0], '\033[0m'
print ('\033[91m\n', exception_msg[0], '\033[0m')
return False

global total_queries
Expand All @@ -187,11 +187,11 @@ def check_query(query, collection1, collection2, projection=None, sort=None, lim
assert ret1[i] == ret2[i]
return True
except AssertionError:
print '\nQuery results didn\'t match at index %d!' % i
print 'Query: %r' % query
print 'Projection: %r' % projection
print '\n %s' % format_result(collection1, ret1, i)
print ' %s\n' % format_result(collection2, ret2, i)
print ('\nQuery results didn\'t match at index %d!' % i)
print ('Query: %r' % query)
print ('Projection: %r' % projection)
print ('\n %s' % format_result(collection1, ret1, i))
print (' %s\n' % format_result(collection2, ret2, i))

diff_results(collection1, ret1, collection2, ret2)

Expand All @@ -201,12 +201,12 @@ def check_query(query, collection1, collection2, projection=None, sort=None, lim

return False
except IndexError:
print 'Query results didn\'t match!'
print 'Query: %r' % query
print 'Projection: %r' % projection
print ('Query results didn\'t match!')
print ('Query: %r' % query)
print ('Projection: %r' % projection)

print '\n %s' % format_result(collection1, ret1, i)
print ' %s\n' % format_result(collection2, ret2, i)
print ('\n %s' % format_result(collection1, ret1, i))
print (' %s\n' % format_result(collection2, ret2, i))

diff_results(collection1, ret1, collection2, ret2)

Expand Down Expand Up @@ -237,8 +237,8 @@ def test_update(collection1, collection2, verbose=False):
if verbose:
all = [x for x in collection1.find(dict())]
for item in collection1.find(update['query']):
print '[{}] Before update doc:{}'.format(type(collection1), item)
print 'Before update collection1 size: ', len(all)
print ('[{}] Before update doc:{}'.format(type(collection1), item))
print ('Before update collection1 size: ', len(all))
collection1.update(update['query'], update['update'], upsert=update['upsert'], multi=update['multi'])
except pymongo.errors.OperationFailure as e:
exceptionOne = e
Expand All @@ -248,8 +248,8 @@ def test_update(collection1, collection2, verbose=False):
if verbose:
all = [x for x in collection2.find(dict())]
for item in collection2.find(update['query']):
print '[{}]Before update doc:{}'.format(type(collection2), item)
print 'Before update collection2 size: ', len(all)
print ('[{}]Before update doc:{}'.format(type(collection2), item))
print ('Before update collection2 size: ', len(all))
collection2.update(update['query'], update['update'], upsert=update['upsert'], multi=update['multi'])
except pymongo.errors.OperationFailure as e:
exceptionTwo = e
Expand All @@ -265,9 +265,9 @@ def test_update(collection1, collection2, verbose=False):
# TODO re-enable consistency check when failure happened
return (True, True)
else:
print 'Unmatched result: '
print type(exceptionOne), ': ', str(exceptionOne)
print type(exceptionTwo), ': ', str(exceptionTwo)
print ('Unmatched result: ')
print (type(exceptionOne), ': ', str(exceptionOne))
print (type(exceptionTwo), ': ', str(exceptionTwo))
ignored_exception_check(exceptionOne)
ignored_exception_check(exceptionTwo)
return (False, False)
Expand Down Expand Up @@ -307,30 +307,30 @@ def _run_operation_(op1, op2):
func1(*args1, **kwargs1)
except pymongo.errors.OperationFailure as e:
if verbose:
print "Failed func1 with " + str(e)
print ("Failed func1 with " + str(e))
exceptionOne = e
except MongoModelException as e:
if verbose:
print "Failed func1 with " + str(e)
print ("Failed func1 with " + str(e))
exceptionOne = e
try:
func2(*args2, **kwargs2)
except pymongo.errors.OperationFailure as e:
if verbose:
print "Failed func2 with " + str(e)
print ("Failed func2 with " + str(e))
exceptionTwo = e
except MongoModelException as e:
if verbose:
print "Failed func2 with " + str(e)
print ("Failed func2 with " + str(e))
exceptionTwo = e

if ((exceptionOne is None and exceptionTwo is None)
or (exceptionOne is not None and exceptionTwo is not None and exceptionOne.code == exceptionTwo.code)):
pass
else:
print 'Unmatched result: '
print type(exceptionOne), ': ', str(exceptionOne)
print type(exceptionTwo), ': ', str(exceptionTwo)
print ('Unmatched result: ')
print (type(exceptionOne), ': ', str(exceptionOne))
print (type(exceptionTwo), ': ', str(exceptionTwo))
okay = False
ignored_exception_check(exceptionOne)
ignored_exception_check(exceptionTwo)
Expand Down Expand Up @@ -383,7 +383,7 @@ def _run_operation_(op1, op2):
(collection2.insert, (docs,), {})
)
if not okay:
print "Failed when doing inserts"
print ("Failed when doing inserts")
return (okay, fname, None)

if not indexes_first:
Expand All @@ -398,7 +398,7 @@ def _run_operation_(op1, op2):
(collection2.ensure_index, (i,), {"unique": uniqueIndex})
)
if not okay:
print "Failed when adding index after insert"
print ("Failed when adding index after insert")
return (okay, fname, None)
ii += 1

Expand All @@ -410,7 +410,7 @@ def _run_operation_(op1, op2):
okay, skip_current_iteration = test_update(collection1, collection2, verbose)
if skip_current_iteration:
if verbose:
print "Skipping current iteration due to the failure from update."
print ("Skipping current iteration due to the failure from update.")
return (True, fname, None)
if not okay:
return (okay, fname, None)
Expand Down Expand Up @@ -442,7 +442,7 @@ def _run_operation_(op1, op2):
return (okay, fname, None)

except IgnoredException as e:
print "Ignoring EXCEPTION: ", e.message
print ("Ignoring EXCEPTION: ", e.message)
return True, fname, None
except Exception as e:
import traceback
Expand Down Expand Up @@ -489,9 +489,9 @@ def test_forever(ns):
collection1 = client1[dbName][collName]
collection2 = client2[dbName][collName]

print '========================================================'
print 'PID : ' + str(os.getpid()) + ' iteration : ' + str(jj) + ' DB : ' + dbName + ' Collection: ' + collName
print '========================================================'
print ('========================================================')
print ('PID : ' + str(os.getpid()) + ' iteration : ' + str(jj) + ' DB : ' + dbName + ' Collection: ' + collName)
print ('========================================================')
(okay, fname, e) = one_iteration(collection1, collection2, ns, seed)

if not okay:
Expand All @@ -500,11 +500,11 @@ def test_forever(ns):
# print 'File for failing iteration: ', fname
with open(fname, 'r') as fp:
for line in fp:
print line
print (line)
break

# Generate a new seed and start over
seed = random.randint(0, sys.maxint)
seed = random.randint(0, sys.maxsize)
gen.global_prng = random.Random(seed)

# house keeping
Expand Down Expand Up @@ -567,13 +567,13 @@ def tester_thread(c1, c2):
time.sleep(1)
if not t1.is_alive():
sys.stdout = oldstdout
print 'SUCCESS: Test harness found artificial bug'
print ('SUCCESS: Test harness found artificial bug')
break

sys.stdout = oldstdout

if t1.is_alive():
print 'FAILURE: Test harness did not find obvious artificial bug in 5 seconds'
print ('FAILURE: Test harness did not find obvious artificial bug in 5 seconds')

sys.stdout = NullWriter()

Expand All @@ -583,12 +583,12 @@ def tester_thread(c1, c2):
time.sleep(1)
if not t2.is_alive():
sys.stdout = oldstdout
print 'FAILURE: Test of model vs. itself did not match'
print ('FAILURE: Test of model vs. itself did not match')
return

sys.stdout = oldstdout

print 'SUCCESS: Model was consistent with itself'
print ('SUCCESS: Model was consistent with itself')


if __name__ == '__main__':
Expand All @@ -605,7 +605,7 @@ def tester_thread(c1, c2):
parser_forever.add_argument('1', choices=['mongo', 'mm', 'doclayer'], help='first tester')
parser_forever.add_argument('2', choices=['mongo', 'mm', 'doclayer'], help='second tester')
parser_forever.add_argument(
'-s', '--seed', type=int, default=random.randint(0, sys.maxint), help='random seed to use')
'-s', '--seed', type=int, default=random.randint(0, sys.maxsize), help='random seed to use')
parser_forever.add_argument('--no-updates', default=True, action='store_false', help='disable update tests')
parser_forever.add_argument(
'--no-sort', default=True, action='store_false', help='disable non-deterministic sort tests')
Expand Down
4 changes: 2 additions & 2 deletions test/correctness/driver-correctness.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def test_all(times=300):
return tests


print yaml.safe_dump({
print (yaml.safe_dump({
'host': 'localhost',
'port': 8031,
'database': 'test',
'collection': 'test',
'tests': test_all()
},
default_flow_style=False)
default_flow_style=False))
12 changes: 6 additions & 6 deletions test/correctness/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def random_elem_match_predicate():
else:
r = global_prng.choice([global_prng.uniform(0, 0.4), global_prng.uniform(0.5, 0.9)])
q = random_query(r)
q = {k: q.values()[0][k] for k in q.values()[0]}
q = {k: list(q.values())[0][k] for k in list(q.values())[0]}
e.update(q)
return ('$elemMatch', e)

Expand All @@ -337,10 +337,10 @@ def random_ne_predicate():

def random_not_predicate():
r = global_prng.uniform(0, 0.9)
q = random_query(r).values()[0]
q = list(random_query(r).values())[0]
while type(q) is list or not generator_options.allow_general_nots and ('$not' in q or '$regex' in q):
r = global_prng.uniform(0, 0.9)
q = random_query(r).values()[0]
q = list(random_query(r).values())[0]
return ('$not', q)


Expand Down Expand Up @@ -419,12 +419,12 @@ def random_update_operator_mul():

def random_update_operator_rename():
doc = {}
while len(doc.keys()) == 0:
while len(list(doc.keys())) == 0:
for i in range(0, global_prng.randint(0, 3)):
old_name = random_field_name()
new_name = random_field_name()
if old_name != new_name and old_name not in doc.values() and new_name not in doc.keys(
) and new_name not in doc.values():
if old_name != new_name and old_name not in list(doc.values()) and new_name not in list(doc.keys()
) and new_name not in list(doc.values()):
doc[old_name] = new_name
return {'$rename': doc}

Expand Down
Loading