From db64ee5f0b9db2447d511543fd3afc8140533902 Mon Sep 17 00:00:00 2001 From: Anders Pearson Date: Fri, 22 Apr 2016 17:15:41 +0100 Subject: [PATCH] add python3 support --- .travis.yml | 4 ++++ exceptionstest/tests.py | 6 ++---- main/tests.py | 19 +++++++++++-------- setup.cfg | 2 ++ smoketest/__init__.py | 2 +- smoketest/views.py | 15 ++++++++------- 6 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 setup.cfg diff --git a/.travis.yml b/.travis.yml index 89456d3..eece1f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ language: python sudo: False python: - "2.7" + - "3.5" +env: + - DJANGO="Django>=1.8.0,<1.9.0" + - DJANGO="Django>=1.9.0,<1.10.0" install: - pip install . - pip install flake8 diff --git a/exceptionstest/tests.py b/exceptionstest/tests.py index 27a3fc6..c9632e8 100644 --- a/exceptionstest/tests.py +++ b/exceptionstest/tests.py @@ -5,7 +5,6 @@ from exceptionstest import EXC_MSG - class ExceptionsTest(TestCase): """ Check how smoke test works with different exceptionstest raise from different places in code. @@ -15,11 +14,10 @@ def setUp(self): settings.INSTALLED_APPS = ('exceptionstest', 'smoketest') self.c = Client() - def test_exceptions(self): response = self.c.get("/smoketest/") self.assertEqual(response.status_code, 500) - self.assertIn("FAIL", response.content) + self.assertIn("FAIL", response.content.decode('utf-8')) self.assertIn( "Exception while importing smoke test script: %s" % EXC_MSG, - response.content) + response.content.decode('utf-8')) diff --git a/main/tests.py b/main/tests.py index 523e8ef..3327c4c 100644 --- a/main/tests.py +++ b/main/tests.py @@ -4,7 +4,7 @@ from django.test import TestCase from django.test.client import Client -from smoke import TestFailedSmokeTests +from .smoke import TestFailedSmokeTests from smoketest import SmokeTest @@ -34,20 +34,23 @@ def test_basics(self): response = self.c.get("/smoketest/") self.assertEqual(response.status_code, 500) - self.assertIn("FAIL", response.content) + self.assertIn("FAIL", response.content.decode('utf-8')) # only tests from TestFailedSmokeTests should fail - self.assertNotIn(".SmokeTest.", response.content) + self.assertNotIn(".SmokeTest.", + response.content.decode('utf-8')) # and both tests from TestFailedSmokeTests should fail - self.assertIn("tests failed: 2\n", response.content) - self.assertIn("tests errored: 0\n", response.content) + self.assertIn("tests failed: 2\n", + response.content.decode('utf-8')) + self.assertIn("tests errored: 0\n", + response.content.decode('utf-8')) self.assertIn( (".TestFailedSmokeTests.test_assertTrueWoMsg " "failed: False is not true"), - response.content) + response.content.decode('utf-8')) self.assertIn( ".TestFailedSmokeTests.test_assertEqualWMsg failed: %s" % TestFailedSmokeTests.CUSTOM_TEST_MSG, - response.content) + response.content.decode('utf-8')) def test_json(self): " Testing JSON response. " @@ -55,7 +58,7 @@ def test_json(self): response = self.c.get("/smoketest/", HTTP_ACCEPT=json_content_type) self.assertEqual(json_content_type, response.get('Content-Type', None)) - response_obj = json.loads(response.content) + response_obj = json.loads(response.content.decode('utf-8')) self.assertEqual('FAIL', response_obj['status']) self.assertEqual(2, response_obj['tests_failed']) self.assertEqual(0, response_obj['tests_errored']) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..2a9acf1 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[bdist_wheel] +universal = 1 diff --git a/smoketest/__init__.py b/smoketest/__init__.py index a3620ad..f548933 100644 --- a/smoketest/__init__.py +++ b/smoketest/__init__.py @@ -57,7 +57,7 @@ def run(self): passed += 1 if hasattr(self, 'tearDown'): self.tearDown() - except Exception, e: + except Exception as e: errored += 1 msg = self._FAILED_TEST_FULL_MSG % { 'method_full_name': method_full_name, diff --git a/smoketest/views.py b/smoketest/views.py index 2755ace..039144e 100644 --- a/smoketest/views.py +++ b/smoketest/views.py @@ -2,6 +2,7 @@ from django.db import transaction from django.http import HttpResponse from django.views.generic import View +import functools import json import inspect import importlib @@ -41,7 +42,7 @@ def test_application(app): except ImportError: # no 'smokes' module for the app pass - except Exception, e: + except Exception as e: num_tests_errored += 1 errored_tests.append( 'Exception while importing smoke test script: %s' % e) @@ -59,7 +60,7 @@ def test_application(app): num_tests_errored += errored failed_tests = failed_tests + f_tests errored_tests = errored_tests + e_tests - except Exception, e: + except Exception as e: # probably an error in setUp() or tearDown() num_tests_errored += 1 e_tests.append('Exception during test: %s' % e) @@ -74,13 +75,13 @@ def test_application(app): def make_failed_report(result_sets): return "\n\n".join( - [f for f in reduce( + [f for f in functools.reduce( lambda x, y: x + y, [r.failed for r in result_sets])]) def make_errored_report(result_sets): return "\n\n".join( - [f for f in reduce( + [f for f in functools.reduce( lambda x, y: x + y, [r.errored for r in result_sets])]) @@ -120,7 +121,7 @@ def get(self, request): for app in settings.INSTALLED_APPS if app not in skip] finish = time.time() - all_passed = reduce( + all_passed = functools.reduce( lambda x, y: x & y, [r.passed() for r in result_sets]) num_test_classes = sum([r.num_test_classes for r in result_sets]) num_tests_run = sum([r.num_tests_run for r in result_sets]) @@ -154,10 +155,10 @@ def get(self, request): tests_passed=num_tests_passed, tests_failed=num_tests_failed, tests_errored=num_tests_errored, - failed_tests=reduce( + failed_tests=functools.reduce( lambda x, y: x + y, [r.failed for r in result_sets]), - errored_tests=reduce( + errored_tests=functools.reduce( lambda x, y: x + y, [r.errored for r in result_sets]), time=(finish - start) * 1000,