Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Fixes travis file comparison of written csvs.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavoudTaghawiNejad authored Sep 5, 2017
2 parents 07a9796 + f19853a commit ebfe6a2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
12 changes: 6 additions & 6 deletions unittest/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import start_logging_test

if __name__ == '__main__':
start_core_engine.main(processes=1, rounds=50)
print('Iteration with 1 core finished')
if (platform.system() != 'Windows' and
platform.python_implementation() != 'PyPy'):
start_core_engine.main(processes=4, rounds=50)
print('Iteration with multiple processes finished')
start_logging_test.main(processes=1)
print('Iteration of logger testing with 1 core finished')
if (platform.system() != 'Windows' and
platform.python_implementation() != 'PyPy'):
start_logging_test.main(processes=4)
print('Iteration of logger testing with multiple processes finished')
start_core_engine.main(processes=1, rounds=50)
print('Iteration with 1 core finished')
if (platform.system() != 'Windows' and
platform.python_implementation() != 'PyPy'):
start_core_engine.main(processes=4, rounds=50)
print('Iteration with multiple processes finished')
50 changes: 29 additions & 21 deletions unittest/start_logging_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import platform
from filecmp import cmp
import csv
import abce
try:
from math import isclose
except ImportError:
def isclose(a, b):
return a - 0.000001 < b < a + 0.000001


class Agent(abce.Agent):
Expand All @@ -18,26 +22,30 @@ def compare(to_compare, path, message, processes):
the_path = (path + '/' + to_compare)
if platform.system() == 'Windows': # windows compatibility
the_path = the_path[the_path.find('/') + 1:]
with open(to_compare, 'r') as generatedf:
generated = {}
for row in csv.DictReader(generatedf):
try:
generated[(row['round'], row['id'])] = row
except KeyError:
generated[row['round']] = row
with open(the_path, 'r') as orginialf:
orginial = {}
for row in csv.DictReader(orginialf):
try:
orginial[(row['round'], row['id'])] = row
except KeyError:
orginial[row['round']] = row
for row in generated:
for key in generated[row]:
generated[row][key] == orginial[row][key], (key, generated[row][key], orginial[row][key])
for row in orginial:
for key in orginial[row]:
generated[row][key] == orginial[row][key], (key, generated[row][key], orginial[row][key])
with open(to_compare, 'r') as generatedf:
generated = {}
for row in csv.DictReader(generatedf):
try:
generated[(row['round'], row['id'])] = row
except KeyError:
generated[row['round']] = row
with open(the_path, 'r') as orginialf:
orginial = {}
for row in csv.DictReader(orginialf):
try:
orginial[(row['round'], row['id'])] = row
except KeyError:
orginial[row['round']] = row
for row in generated:
for key in generated[row]:
if key != 'index':
if generated[row][key] != orginial[row][key]:
assert isclose(float(generated[row][key]), float(orginial[row][key])), (key, generated[row][key], orginial[row][key])
for row in orginial:
for key in orginial[row]:
if key != 'index':
if generated[row][key] != orginial[row][key]:
assert isclose(float(generated[row][key]), float(orginial[row][key])), (key, generated[row][key], orginial[row][key])


def main(processes):
Expand Down

0 comments on commit ebfe6a2

Please sign in to comment.