Skip to content

Commit

Permalink
Merge pull request #14 from NextThought/test_cleanup
Browse files Browse the repository at this point in the history
Cleanup test modules.
  • Loading branch information
jamadden committed Oct 23, 2017
2 parents 8dd2d96 + 8904f3b commit accb826
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 79 deletions.
24 changes: 15 additions & 9 deletions src/nti/testing/tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Tests for base.py.
.. $Id$
"""

from __future__ import print_function, absolute_import, division
__docformat__ = "restructuredtext en"
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

logger = __import__('logging').getLogger(__name__)
# stdlib imports
import unittest

#disable: accessing protected members, too many methods
#pylint: disable=W0212,R0904
from nti.testing import base
from nti.testing.matchers import has_attr

import unittest
from hamcrest import assert_that
from hamcrest import is_

from nti.testing import base
from nti.testing.matchers import has_attr
__docformat__ = "restructuredtext en"

logger = __import__('logging').getLogger(__name__)

#disable: accessing protected members, too many methods
#pylint: disable=W0212,R0904

class TestBase(unittest.TestCase):

Expand Down Expand Up @@ -85,6 +90,7 @@ def test_thing(self):
def test_shared_configuring_base(self):
import zope.traversing.tests.test_traverser
class MyTest(base.SharedConfiguringTestBase):
layer = None # replaced by metaclass
set_up_packages = ('zope.component',
('configure.zcml', 'zope.component'),
zope.traversing.tests.test_traverser)
Expand Down
28 changes: 14 additions & 14 deletions src/nti/testing/tests/test_layers.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
.. $Id$
Test for layers.py.
"""

from __future__ import print_function, absolute_import, division
__docformat__ = "restructuredtext en"
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

logger = __import__('logging').getLogger(__name__)
# stdlib imports
import unittest

#disable: accessing protected members, too many methods
#pylint: disable=W0212,R0904
from nti.testing import layers

import unittest
from hamcrest import assert_that
from hamcrest import is_

from nti.testing import layers
__docformat__ = "restructuredtext en"


class TestLayers(unittest.TestCase):

def test_find_test(self):

def foo():
def func():
assert_that(layers.find_test(), is_(self))

foo()
func()

def via_test(test):
foo()
func()

via_test(self)

Expand Down Expand Up @@ -60,5 +59,6 @@ def test_configuring_layer_mixin(self):
class Layer(layers.ConfiguringLayerMixin):
set_up_packages = ('zope.component',)

for meth in 'setUp', 'tearDown', 'testSetUp', 'testTearDown', 'setUpPackages', 'tearDownPackages':
for meth in ('setUp', 'tearDown', 'testSetUp', 'testTearDown',
'setUpPackages', 'tearDownPackages'):
getattr(Layer, meth)()
34 changes: 6 additions & 28 deletions src/nti/testing/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,23 @@
from __future__ import print_function, division, absolute_import
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import unittest
# stdlib imports
import doctest
import os
import re
from zope.testing import renormalizing
import unittest


class TestImport(unittest.TestCase):
def test_import(self):
for name in ('base', 'layers', 'matchers', 'time'):
__import__('nti.testing.' + name)

checker = renormalizing.RENormalizing([
# Python 3 bytes add a "b".
(re.compile(r'b(".*?")'), r"\1"),
(re.compile(r"b('.*?')"), r"\1"),
# Windows shows result from 'u64' as long?
(re.compile(r"(\d+)L"), r"\1"),
# Python 3 adds module name to exceptions.
(re.compile("ZODB.POSException.ConflictError"), r"ConflictError"),
(re.compile("ZODB.POSException.POSKeyError"), r"POSKeyError"),
(re.compile("ZODB.POSException.ReadConflictError"), r"ReadConflictError"),
(re.compile("ZODB.POSException.Unsupported"), r"Unsupported"),
(re.compile("ZODB.interfaces.BlobError"), r"BlobError"),
# XXX document me
(re.compile(r'\%(sep)s\%(sep)s' % dict(sep=os.path.sep)), '/'),
(re.compile(r'\%(sep)s' % dict(sep=os.path.sep)), '/'),
])


def test_suite():
here = os.path.dirname(__file__)

suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestImport))
suite = unittest.defaultTestLoader.loadTestsFromName(__name__)
suite.addTest(doctest.DocFileSuite(
'test_component_cleanup_broken.txt'))

Expand All @@ -46,10 +29,5 @@ def test_suite():
readme,
module_relative=False,
optionflags=doctest.ELLIPSIS,
checker=checker,
))
return suite


if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
34 changes: 17 additions & 17 deletions src/nti/testing/tests/test_matchers.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
.. $Id$
Tests for matchers.py.
"""

from __future__ import print_function, absolute_import, division
__docformat__ = "restructuredtext en"
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

logger = __import__('logging').getLogger(__name__)
# stdlib imports
import unittest

#disable: accessing protected members, too many methods
#pylint: disable=W0212,R0904,inherit-non-class
# XXX: Fix these
# pylint:disable=wrong-import-position,wrong-import-order,bad-whitespace
from nti.testing import matchers

import unittest
from hamcrest import assert_that
from hamcrest import is_
from hamcrest import calling

from hamcrest import raises

from nti.testing import base
from nti.testing import matchers
__docformat__ = "restructuredtext en"


#pylint:disable=inherit-non-class


class TestMatchers(unittest.TestCase):

Expand Down Expand Up @@ -81,7 +80,7 @@ def test_verifiably_provides(self):
class IThing(interface.Interface):
thing = interface.Attribute("thing")

def method():
def method(): # pylint:disable=no-method-argument
"method"

@interface.implementer(IThing)
Expand All @@ -97,7 +96,8 @@ def method(self):

broken_thing = Thing()
broken_thing.method = None
assert_that(calling(assert_that).with_args(broken_thing, matchers.verifiably_provides(IThing)),
assert_that(calling(assert_that).with_args(broken_thing,
matchers.verifiably_provides(IThing)),
raises(AssertionError, "violates its contract"))

del Thing.thing
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_dict(self):
raises(AssertionError, "instance of int"))

def test_in_context(self):

# pylint:disable=attribute-defined-outside-init
class Thing(object):
pass

Expand Down
20 changes: 9 additions & 11 deletions src/nti/testing/tests/test_time.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function, absolute_import, division
__docformat__ = "restructuredtext en"
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

logger = __import__('logging').getLogger(__name__)
# stdlib imports
import unittest

#disable: accessing protected members, too many methods
#pylint: disable=W0212,R0904
from nti.testing.time import reset_monotonic_time
from nti.testing.time import time_monotonically_increases

import unittest
from hamcrest import assert_that
from hamcrest import is_
from hamcrest import greater_than
from hamcrest import greater_than_or_equal_to
from hamcrest import is_
from hamcrest import less_than

from nti.testing.time import time_monotonically_increases, reset_monotonic_time
__docformat__ = "restructuredtext en"

class TestTime(unittest.TestCase):

Expand Down Expand Up @@ -115,6 +116,3 @@ def f3():
after_third = f3()
current_real = time.time()
assert_that(current_real, is_(greater_than_or_equal_to(after_third)))

if __name__ == '__main__':
unittest.main()

0 comments on commit accb826

Please sign in to comment.