Skip to content

Commit

Permalink
Merge pull request #1 from ojii/py27
Browse files Browse the repository at this point in the history
Python 2.7 support
  • Loading branch information
ojii committed Jan 15, 2016
2 parents ee5e5a0 + 5ef7a30 commit 14ecb85
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 33 deletions.
16 changes: 12 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
sudo: false
language: python
cache: pip
python:
- 3.3
- 2.7
- 3.4
- 3.5
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
script: python setup.py test
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
install:
- "pip install -U django flask flask-testing 'selenium!=2.48.0' slimit nose"
- "pip uninstall ply -y"
- "pip install ply==3.4"
script: nosetests viceroy/tests/
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
author_email='ojiidotch@gmail.com',
description='',
install_requires=[
'selenium',
'selenium!=2.49.0',
'slimit',
],
tests_require=[
'Django',
'flask-testing',
'flask',
],
test_suite='viceroy.tests',
include_package_data=True,
zip_safe=False,
classifiers=[
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
)
4 changes: 2 additions & 2 deletions viceroy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ def viceroy_get_results(cls):

@classmethod
def setUpClass(cls):
super().setUpClass()
super(ViceroyTestCase, cls).setUpClass()
cls.viceroy_cache = cls.viceroy_get_results()

@classmethod
def tearDownClass(cls):
if hasattr(cls, 'viceroy_cache'):
del cls.viceroy_cache
super().tearDownClass()
super(ViceroyTestCase, cls).tearDownClass()


def test_method_proxy(full_name, short_name):
Expand Down
4 changes: 2 additions & 2 deletions viceroy/contrib/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def viceroy_server(cls):
def setUpClass(cls):
django.setup()
settings.VICEROY_TESTING = True
super().setUpClass()
super(ViceroyDjangoTestCase, cls).setUpClass()

@classmethod
def tearDownClass(cls):
super().tearDownClass()
super(ViceroyDjangoTestCase, cls).tearDownClass()
settings.VICEROY_TESTING = False
6 changes: 6 additions & 0 deletions viceroy/contrib/flask.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import contextlib
import logging
import multiprocessing
Expand All @@ -8,6 +9,11 @@

from viceroy.api import ViceroyTestCase

try:
ConnectionRefusedError
except NameError:
ConnectionRefusedError = socket.error


def _server_started(port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand Down
12 changes: 8 additions & 4 deletions viceroy/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ def __init__(self, source):

def __iter__(self):
for node in self.tree:
yield from self.visit(node)
for foo in self.visit(node):
yield foo

def visit(self, node):
method_name = 'visit_{}'.format(node.__class__.__name__)
handler = getattr(self, method_name, self.visit_children)
yield from handler(node)
for foo in handler(node):
yield foo

def visit_children(self, node):
for child in node:
yield from self.visit(child)
for foo in self.visit(child):
yield foo

def visit_FunctionCall(self, node):
key = node.identifier.to_ecma()
Expand All @@ -34,7 +37,8 @@ def visit_FunctionCall(self, node):
yield argument(node)
else:
yield self.extract_name(node.args[argument])
yield from self.visit_children(node)
for foo in self.visit_children(node):
yield foo

def extract_name(self, node):
if isinstance(node, String):
Expand Down
20 changes: 6 additions & 14 deletions viceroy/tests/core.py → viceroy/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from viceroy.constants import VICEROY_JS_PATH
from viceroy.contrib.flask import ViceroyFlaskTestCase
from viceroy.scanner import BaseScanner

from .utils import ViceroyScanner

ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
SUCCESS_TESTS_FILE_PATH = os.path.join(
Expand Down Expand Up @@ -60,17 +60,6 @@ def fail():
class BaseTestCase(ViceroyFlaskTestCase):
viceroy_flask_app = test_app


class ViceroyScanner(BaseScanner):
test_methods = {
'VICEROY.store_result': 0,
'VICEROY.success': 0,
'VICEROY.fail': 0,
'VICEROY.skip': 0,
'VICEROY.start_test': 0,
}


ViceroySuccessTests = build_test_case(
'ViceroySuccessTests',
SUCCESS_TESTS_FILE_PATH,
Expand All @@ -85,10 +74,13 @@ class ViceroyFailureTests(build_test_case('Base', FAIL_TESTS_FILE_PATH,

@unittest.expectedFailure
def test_test_fail(self):
super().test_test_fail()
super(ViceroyFailureTests, self).test_test_fail()

def test_test_error(self):
self.assertRaises(JavascriptError, super().test_test_error)
self.assertRaises(
JavascriptError,
super(ViceroyFailureTests, self).test_test_error
)


class TestScanner(unittest.TestCase):
Expand Down
9 changes: 5 additions & 4 deletions viceroy/tests/django.py → viceroy/tests/test_django.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import os

os.environ['DJANGO_SETTINGS_MODULE'] = 'viceroy.tests.djangoapp.settings'
Expand All @@ -7,7 +8,7 @@

from viceroy.api import build_test_case
from viceroy.contrib.django import ViceroyDjangoTestCase
from .core import ViceroyScanner
from .utils import ViceroyScanner

root = os.path.abspath(os.path.dirname(__file__))
test_file = os.path.join(root, 'djangoapp', 'static', 'tests.js')
Expand All @@ -18,12 +19,12 @@ class DatabaseTestCase(ViceroyDjangoTestCase):
def setUpClass(cls):
django.setup()
cls.old_config = setup_databases(0, False)
super().setUpClass()
super(DatabaseTestCase, cls).setUpClass()

@classmethod
def tearDownClass(cls):
super().tearDownClass()
old_names, mirrors = cls.old_config
super(DatabaseTestCase, cls).tearDownClass()
old_names = cls.old_config
for connection, old_name, destroy in old_names:
if destroy:
connection.creation.destroy_test_db(old_name, verbosity=0)
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions viceroy/tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from viceroy.scanner import BaseScanner


class ViceroyScanner(BaseScanner):
test_methods = {
'VICEROY.store_result': 0,
'VICEROY.success': 0,
'VICEROY.fail': 0,
'VICEROY.skip': 0,
'VICEROY.start_test': 0,
}

0 comments on commit 14ecb85

Please sign in to comment.