diff options
-rw-r--r-- | test/test.py | 67 | ||||
-rw-r--r-- | test/tests/ApiTest.py | 114 | ||||
-rw-r--r-- | test/tests/__init__.py | 0 |
3 files changed, 121 insertions, 60 deletions
diff --git a/test/test.py b/test/test.py index bc4ef14..d11e1cb 100644 --- a/test/test.py +++ b/test/test.py @@ -1,65 +1,12 @@ -import csv -import requests -import random -import os +import sys import unittest -from apitest.pzbs import PzbsCalculator -from apitest.api import ApiCalculator - -def runTest(tester, params): - return tester.get_response( - requests.post( - tester.get_url(), - data=tester.get_request(*params) - ).text) - -class ApiTestCase(unittest.TestCase): - def __setupParams(self): - csv_files = [] - for root, dirs, files in os.walk('./csv'): - csv_files += [os.path.join(root, f) for f in files] - self.params = [] - for csv_file in csv_files: - csv_content = csv.reader(open(csv_file), delimiter=";") - param_contents = [ - row for idx, row in enumerate(csv_content) if idx == 2][0] - self.params.append(( - param_contents[0][0].lower(), - None, 0, - int(param_contents[1]), float(param_contents[4]))) - - def setUp(self): - self.pzbs = PzbsCalculator() - self.api = ApiCalculator() - self.__setupParams() - self.longMessage=True - self.maxDiff = None - - @unittest.skip('') - def test_csvCases(self): - for params in self.params: - for rank in ApiCalculator.ranks.keys(): - for boards in [0, 1]: - p = (params[0], rank, boards, params[3], params[4]) - self.assertEqual( - runTest(self.pzbs, p), - runTest(self.api, p), - msg=str(p)) - - def test_randomCases(self): - for i in range(0, 20): - for type in ['t', 'p', 'i']: - for rank in ApiCalculator.ranks.keys(): - for boards in [0, 1]: - p = (type, rank, boards, - random.randint(6, 350), - random.randint(0, 4000) / 2.0) - self.assertEqual( - runTest(self.pzbs, p), - runTest(self.api, p), - msg=str(p)) +import tests.ApiTest if __name__ == '__main__': - suite = unittest.TestLoader().loadTestsFromTestCase(ApiTestCase) + suite = unittest.TestLoader().loadTestsFromModule(tests.ApiTest) \ + if len(sys.argv) < 2 \ + else unittest.TestLoader().loadTestsFromNames( + ['tests.ApiTest.ApiTestCase.test_%sCases' % (s) + for s in sys.argv[1:]]) unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/tests/ApiTest.py b/test/tests/ApiTest.py new file mode 100644 index 0000000..0af8626 --- /dev/null +++ b/test/tests/ApiTest.py @@ -0,0 +1,114 @@ +import csv +import requests +import random +import os +import unittest + +from apitest.pzbs import PzbsCalculator +from apitest.api import ApiCalculator + +def runTest(tester, params): + return tester.get_response( + requests.post( + tester.get_url(), + data=tester.get_request(*params) + ).text) + +class ApiTestCase(unittest.TestCase): + def __setupParams(self): + csv_files = [] + for root, dirs, files in os.walk('./csv'): + csv_files += [os.path.join(root, f) for f in files if f.lower().endswith('.csv')] + self.params = [] + for csv_file in csv_files: + csv_content = csv.reader(open(csv_file), delimiter=";") + param_contents = [ + row for idx, row in enumerate(csv_content) if idx == 2][0] + self.params.append(( + param_contents[0][0].lower(), + None, 0, + int(param_contents[1]), float(param_contents[4]))) + + def setUp(self): + self.pzbs = PzbsCalculator() + self.api = ApiCalculator() + self.__setupParams() + self.longMessage=True + self.maxDiff = None + + def test_csvCases(self): + for params in self.params: + for rank in ApiCalculator.ranks.keys(): + for boards in [0, 1]: + p = (params[0], rank, boards, params[3], params[4]) + self.assertEqual( + runTest(self.pzbs, p), + runTest(self.api, p), + msg=str(p)) + + def test_randomCases(self): + for i in range(0, 20): + for type in ['t', 'p', 'i']: + for rank in ApiCalculator.ranks.keys(): + for boards in [0, 1]: + p = (type, rank, boards, + random.randint(6, 350), + random.randint(0, 4000) / 2.0) + self.assertEqual( + runTest(self.pzbs, p), + runTest(self.api, p), + msg=str(p)) + + def test_customParamCases(self): + for type in ['t', 'p', 'i']: + for rank in ApiCalculator.ranks.keys(): + for boards in [0, 1]: + for j in range(0, 20): + manualParams = { + 'points': random.randint(20, 100) + } + p = (type, rank, boards, + 35, 400, manualParams) + self.assertEqual( + runTest(self.pzbs, p), + runTest(self.api, p), + msg=str(p)) + for j in range(0, 20): + manualParams = { + 'weight': random.randint(20, 100) + } + p = (type, rank, boards, + 35, 400, manualParams) + self.assertEqual( + runTest(self.pzbs, p), + runTest(self.api, p), + msg=str(p)) + for j in range(0, 20): + manualParams = { + 'players': random.randint(20, 100) * 0.001 + } + p = (type, rank, boards, + 35, 400, manualParams) + self.assertEqual( + runTest(self.pzbs, p), + runTest(self.api, p), + msg=str(p)) + for j in range(0, 20): + manualParams = { + 'cutoff': [ + [random.uniform(0.04, 0.06), + random.uniform(0.7, 0.9)], + [random.uniform(0.15, 0.35), + random.uniform(0.15, 0.35)], + [random.uniform(0.4, 0.6), + 0.0] + ] + } + p = (type, rank, boards, + random.randint(20, 25), + random.randint(300, 400) / 2.0, + manualParams) + self.assertEqual( + runTest(self.pzbs, p), + runTest(self.api, p), + msg=str(p)) diff --git a/test/tests/__init__.py b/test/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/tests/__init__.py |