Skip to content

Commit

Permalink
Merge pull request #7 from ccnmtl/python3-support
Browse files Browse the repository at this point in the history
add python3 support
  • Loading branch information
nikolas committed Apr 22, 2016
2 parents 16d4d3d + db64ee5 commit 706f639
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions exceptionstest/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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'))
19 changes: 11 additions & 8 deletions main/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -34,28 +34,31 @@ 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. "
json_content_type = 'application/json'
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'])
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal = 1
2 changes: 1 addition & 1 deletion smoketest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 8 additions & 7 deletions smoketest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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])])


Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 706f639

Please sign in to comment.