def testcase_naming(): example = Tests() @example.test def simple(): pass @example.test def simple(): """Duplicate name, should have ``_2`` appended.""" class Test(TestBase): @test def simple(): """Another duplicate, should have ``_3`` appended.""" Test = example.register(Test) # Python 2.5 @example.test def test_something(): """Already prepended with ``test_`` - should be used verbatim.""" example.test(lambda self: None) TestCase = example.test_case() assert TestCase.test_simple assert TestCase.test_simple_2 assert TestCase.test_simple_3 assert TestCase.test_something assert TestCase.test_lambda
def unittest(): """Compatibility with Python's unittest package""" signals = set() example = Tests() @example.test def simple(): signals.add("one") class Test(TestBase): @test def simple(self): signals.add("two") Test = example.register(Test) # Python 2.5 # unittest.TestCase TestCase = example.test_case() TestCase("test_simple").debug() assert signals == set(["one"]) # unittest.TestSuite test_suite = example.test_suite() signals.clear() test_suite.debug() assert signals == set(["one", "two"])
def testcase_naming(): example = Tests() @example.test def simple(): pass @example.test def simple(): """Duplicate name, should have ``_2`` appended.""" class Test(TestBase): @test def simple(): """Another duplicate, should have ``_3`` appended.""" Test = example.register(Test) # Python 2.5 @example.test def test_something(): """Already prepended with ``test_`` - should be used verbatim.""" example.test(lambda self: None) TestCase = example.test_case() assert TestCase.test_simple assert TestCase.test_simple_2 assert TestCase.test_simple_3 assert TestCase.test_something assert TestCase.test_lambda
def unittest(): """Compatibility with Python's unittest package""" signals = set() example = Tests() @example.test def simple(): signals.add("one") class Test(TestBase): @test def simple(self): signals.add("two") Test = example.register(Test) # Python 2.5 # unittest.TestCase TestCase = example.test_case() TestCase("test_simple").debug() assert signals == set(["one"]) # unittest.TestSuite test_suite = example.test_suite() signals.clear() test_suite.debug() assert signals == set(["one", "two"])
def conditional(): """@test_if(condition)""" col = Tests() class TestClass(TestBase): @test def foo(self): pass @test_if(True) def bar(self): pass @test_if(False) def baz(self): assert False col.register(TestClass) result = TestReporter() col.run(result) assert len(result.failed) == 0 assert len(result.succeeded) == 2
def conditional(): """@test_if(condition)""" col = Tests() class TestClass(TestBase): @test def foo(self): pass @test_if(True) def bar(self): pass @test_if(False) def baz(self): assert False col.register(TestClass) result = TestReporter() col.run(result) assert len(result.failed) == 0 assert len(result.succeeded) == 2
def decorative(): """@Tests().register(TestBase)""" col = Tests() assert len(col) == 0 class DecoratedTest(TestBase): @test def noop(self): pass @test def nothing(self): pass DecoratedTest = col.register(DecoratedTest) assert issubclass(DecoratedTest, TestBase) == True assert len(col) == 2
def decorative(): """@Tests().register(TestBase)""" col = Tests() assert len(col) == 0 class DecoratedTest(TestBase): @test def noop(self): pass @test def nothing(self): pass DecoratedTest = col.register(DecoratedTest) assert issubclass(DecoratedTest, TestBase) == True assert len(col) == 2
with Assert.raises(ValueError): aresult.get() @test def callback_errback(self): testruns = (['callback', True], ['errback', False]) for kwarg, success in testruns: l = [] callback = lambda obj, l=l: l.append(obj) aresult = AsyncResult(**{kwarg: callback}) assert not aresult.ready aresult.set('foo', success=success) Assert(len(l)) == 1 Assert(l[0]) == 'foo' @test def repr(self): aresult = AsyncResult() Assert(repr(aresult)) == 'AsyncResult()' aresult = AsyncResult(callback=1) Assert(repr(aresult)) == 'AsyncResult(callback=1)' aresult = AsyncResult(errback=1) Assert(repr(aresult)) == 'AsyncResult(errback=1)' aresult = AsyncResult(callback=1, errback=2) Assert(repr(aresult)) == 'AsyncResult(callback=1, errback=2)' tests.register(TestAsyncResult)
from flask import Flask from attest import Tests def make_debug_app(): app = Flask(__name__) app.config['TESTING'] = True return app from feedbacktests import commons, commons_blueprint tests = Tests() tests.register(commons.tests) tests.register(commons_blueprint.tests)
def update(self, writer, remaining_width, **kwargs): self.update_called = True writer = TerminalWriter(StringIO()) progressbar = ProgressBar([], writer) widget = MyWidget() widget.finish(progressbar, writer.get_width()) assert widget.update_called @test def repr(self): widget = Widget() Assert(repr(widget)) == 'Widget()' tests.register(TestWidget) @tests.test def test_text_widget(): writer = TerminalWriter(StringIO()) progressbar = ProgressBar([], writer) widget = TextWidget('foobar') assert widget.provides_size_hint Assert(widget.size_hint(progressbar)) == len('foobar') Assert(widget.init(progressbar, writer.get_width())) == 'foobar' Assert(widget.update(progressbar, writer.get_width())) == 'foobar' Assert(widget.finish(progressbar, writer.get_width())) == 'foobar' Assert(repr(widget)) == "TextWidget('foobar')"
Assert(func(1)(b=2)(3, 4, 5)) == (1, 2, 3, (4, 5)) Assert(func(a=1)(b=2)(3, 4, 5)) == (1, 2, 3, (4, 5)) Assert(func(a=1, b=2)(3, 4, 5)) == (1, 2, 3, (4, 5)) @test def arbitary_keyword_arguments(self): func = curried(lambda a, b, c, **kwargs: (a, b, c, kwargs)) Assert(func(1, 2, 3)) == (1, 2, 3, {}) with Assert.raises(TypeError): func(1, 2)(3, c=4) Assert(func(1, 2, 3, foo=4)) == (1, 2, 3, dict(foo=4)) Assert(func(1)(2, 3, foo=4)) == (1, 2, 3, dict(foo=4)) Assert(func(1, 2)(3, foo=4)) == (1, 2, 3, dict(foo=4)) @test def mixed_arbitary_arguments(self): func = curried(lambda a, b, c, *args, **kwargs: (a, b, c, args, kwargs)) Assert(func(1, 2, 3)) == (1, 2, 3, (), {}) Assert(func(1, 2, 3, 4, 5)) == (1, 2, 3, (4, 5), {}) Assert(func(1, 2, 3, foo=4)) == (1, 2, 3, (), dict(foo=4)) Assert(func(1, 2, 3, 4, foo=5)) == (1, 2, 3, (4, ), dict(foo=5)) tests.register(TestCurried) @tests.test def test_fmap(): Assert(list(fmap(2, [lambda x: 2 * x, lambda x: 3 * x]))) == [4, 6] Assert(list(fmap(1, [(lambda x: x * 2, lambda x: x + 1)]))) == [4]
Assert(func(a=1)(b=2)(3, 4, 5)) == (1, 2, 3, (4, 5)) Assert(func(a=1, b=2)(3, 4, 5)) == (1, 2, 3, (4, 5)) @test def arbitary_keyword_arguments(self): func = curried(lambda a, b, c, **kwargs: (a, b, c, kwargs)) Assert(func(1, 2, 3)) == (1, 2, 3, {}) with Assert.raises(TypeError): func(1, 2)(3, c=4) Assert(func(1, 2, 3, foo=4)) == (1, 2, 3, dict(foo=4)) Assert(func(1)(2, 3, foo=4)) == (1, 2, 3, dict(foo=4)) Assert(func(1, 2)(3, foo=4)) == (1, 2, 3, dict(foo=4)) @test def mixed_arbitary_arguments(self): func = curried(lambda a, b, c, *args, **kwargs: (a, b, c, args, kwargs)) Assert(func(1, 2, 3)) == (1, 2, 3, (), {}) Assert(func(1, 2, 3, 4, 5)) == (1, 2, 3, (4, 5), {}) Assert(func(1, 2, 3, foo=4)) == (1, 2, 3, (), dict(foo=4)) Assert(func(1, 2, 3, 4, foo=5)) == (1, 2, 3, (4, ), dict(foo=5)) tests.register(TestCurried) @tests.test def test_fmap(): Assert(list(fmap(2, [lambda x: 2 * x, lambda x: 3 * x]))) == [4, 6] Assert(list(fmap(1, [(lambda x: x * 2, lambda x: x + 1)]))) == [4]
import doctest import os from attest import Tests from . import (session, types, hash, list, set, sortedset, transaction, threadlocal) tests = Tests() tests.register(session.tests) tests.register(types.tests) tests.register(hash.tests) tests.register(list.tests) tests.register(set.tests) tests.register(sortedset.tests) tests.register(transaction.tests) tests.register(threadlocal.tests) @tests.test def doctest_types(): from sider import types assert 0 == doctest.testmod(types)[0] @tests.test def doctest_datetime(): from sider import datetime assert 0 == doctest.testmod(datetime)[0] exttest_count = 0
Assert.issubclass(Bar, Foo) Assert.isinstance(Bar(), Foo) @test def api_works_cleanly(self): class Foo(object): __metaclass__ = ABCMeta class Bar(object): pass Foo.register(Bar) tests.register(TestABCMeta) @tests.test_if(GE_PYTHON_26) def test_abstract_class_meta(): class Foo(object): __metaclass__ = ABCMeta class Bar(object): __metaclass__ = AbstractClassMeta virtual_superclasses = [Foo] class Baz(object): __metaclass__ = VirtualSubclassMeta
Assert.issubclass(Bar, Foo) Assert.isinstance(Bar(), Foo) @test def api_works_cleanly(self): class Foo(object): __metaclass__ = ABCMeta class Bar(object): pass Foo.register(Bar) tests.register(TestABCMeta) @tests.test_if(GE_PYTHON_26) def test_abstract_class_meta(): class Foo(object): __metaclass__ = ABCMeta class Bar(object): __metaclass__ = AbstractClassMeta virtual_superclasses = [Foo] class Baz(object): __metaclass__ = VirtualSubclassMeta
@test_if(GE_PYTHON_26) def dir(self): class Foo(object): bar = None def spam(self): pass def eggs(self): pass proxy_cls = as_proxy(type('FooProxy', (object, ), {})) Assert(dir(Foo)) == dir(proxy_cls(Foo)) tests.register(TestAsProxy) @tests.test def test_get_wrapped(): proxy_cls = as_proxy(type('FooProxy', (object, ), {})) wrapped = 1 Assert(get_wrapped(proxy_cls(wrapped))).is_(wrapped) class TestLazyProxy(TestBase): @test def special(self): p = LazyProxy(lambda: 1) Assert(p + p) == 2 Assert(p + 1) == 2
from attest import Tests from . import resource, image, color tests = Tests() tests.register(resource.tests) tests.register(image.tests) tests.register(color.tests)
from __future__ import absolute_import from attest import Tests from . import transaction, unit tests = Tests() tests.register(transaction.tests) tests.register(unit.tests)
from flask import Flask from attest import Tests def make_debug_app(): app = Flask(__name__) app.config['TESTING'] = True return app from feedbacktests import commons, commons_blueprint tests = Tests() tests.register(commons.tests) tests.register(commons_blueprint.tests)
@test_if(GE_PYTHON_26) def dir(self): class Foo(object): bar = None def spam(self): pass def eggs(self): pass proxy_cls = as_proxy(type('FooProxy', (object, ), {})) Assert(dir(Foo)) == dir(proxy_cls(Foo)) tests.register(TestAsProxy) @tests.test def test_get_wrapped(): proxy_cls = as_proxy(type('FooProxy', (object, ), {})) wrapped = 1 Assert(get_wrapped(proxy_cls(wrapped))).is_(wrapped) class TestLazyProxy(TestBase): @test def special(self): p = LazyProxy(lambda: 1) Assert(p + p) == 2 Assert(p + 1) == 2
@test def basics(self): cache = LRUCache(maxsize=2) cache[1] = 2 cache[3] = 4 cache[5] = 6 Assert(cache.items()) == [(3, 4), (5, 6)] @test def repr(self): cache = LRUCache() Assert(repr(cache)) == 'LRUCache({}, inf)' tests.register(TestLRUCache) class TestLFUCache(TestBase): @test def basics(self): cache = LFUCache(maxsize=2) cache[1] = 2 cache[3] = 4 cache[3] cache[5] = 6 Assert(cache.items()) == [(1, 2), (5, 6)] @test def repr(self): cache = LFUCache()
from __future__ import absolute_import from attest import AssertImportHook, Tests AssertImportHook.enable() from . import (lib, readers, filters, filters_builtin, helpers, imprt, views, utils, entry, content, core, search) testsuite = Tests() testsuite.register(lib.TestHTMLParser) testsuite.register(readers.tt) testsuite.register(filters.TestFilterlist) testsuite.register(filters.TestFilterTree) testsuite.register(filters_builtin.tt) testsuite.register(filters_builtin.Hyphenation) testsuite.register(helpers.Helpers) testsuite.register(imprt.Import) testsuite.register(imprt.RSS) testsuite.register(imprt.Atom) testsuite.register(imprt.WordPress) testsuite.register(views.Tag) testsuite.register(utils.TestMetadata) testsuite.register(utils.tt) testsuite.register(entry.TestEntry) testsuite.register(content.SingleEntry) testsuite.register(content.MultipleEntries) testsuite.register(core.Cache) testsuite.register(search.tt)
class Response(object): pass @proxy.context def prepare_new_proxy(): yield ResponseProxy(Response) @proxy.test def is_instance_of_the_target(proxy): assert isinstance(proxy, Response) return proxy suite.register(response_stack_suite) suite.register(response_proxy_suite) @suite.test def response_proxies_property_descriptors(): with get(httpbin('get')): assert response.ok == True assert response.json['url'] == httpbin('get') @suite.test def nested_context_managers(): with get(httpbin('get')): assert response.request.method == 'GET' with post(httpbin('post')):
from attest import Tests from plastic.version import VERSION, VERSION_INFO from . import app, config, context, message, rendering, resourcedir tests = Tests() tests.register(app.tests) tests.register(config.tests) tests.register(context.tests) tests.register(message.tests) tests.register(rendering.tests) tests.register(resourcedir.tests) @tests.test def version(): """VERSION_INFO should be a tuple like (1, 2, 3) and VERSION should be a string like '1.2.3'. """ assert map(int, VERSION.split('.')) == list(VERSION_INFO)
from attest import Tests from acrylamid.specs import (lib, readers, filters, filters_builtin, helpers, imprt, views, utils, entry, content, core, search) testsuite = Tests() testsuite.register(lib.TestHTMLParser) testsuite.register(readers.tt) testsuite.register(filters.TestFilterlist) testsuite.register(filters.TestFilterTree) testsuite.register(filters_builtin.tt) testsuite.register(filters_builtin.Hyphenation) testsuite.register(helpers.Helpers) testsuite.register(imprt.Import) testsuite.register(imprt.RSS) testsuite.register(imprt.Atom) testsuite.register(imprt.WordPress) testsuite.register(views.Tag) testsuite.register(utils.TestMetadata) testsuite.register(entry.TestEntry) testsuite.register(content.SingleEntry) testsuite.register(content.MultipleEntries) testsuite.register(core.Cache) testsuite.register(search.tt)
from attest import Tests from . import protocol, replication, sharding suite = Tests() suite.register(protocol.suite) suite.register(replication.suite) suite.register(sharding.suite) @suite.test def version(): import redispace assert redispace.VERSION == '0.1.1'
Assert(new - old) > times[0][1] @test def basics(self): cache = LRUCache(maxsize=2) cache[1] = 2 cache[3] = 4 cache[5] = 6 Assert(cache.items()) == [(3, 4), (5, 6)] @test def repr(self): cache = LRUCache() Assert(repr(cache)) == 'LRUCache({}, inf)' tests.register(TestLRUCache) class TestLFUCache(TestBase): @test def basics(self): cache = LFUCache(maxsize=2) cache[1] = 2 cache[3] = 4 cache[3] cache[5] = 6 Assert(cache.items()) == [(1, 2), (5, 6)] @test def repr(self): cache = LFUCache()
# coding: utf-8 from __future__ import absolute_import from attest import Tests from os import path from glob import glob __all__ = [m for m in [path.basename(f)[:-3] for f in glob(path.dirname(__file__) + '/*.py')] if m not in ['__init__']] from . import * tests = Tests() for module in __all__: tests.register("trex.self_tests.%s.tests" % module)
import datetime import numbers import re from attest import Tests from wand.version import (MAGICK_VERSION, MAGICK_VERSION_INFO, MAGICK_VERSION_NUMBER, MAGICK_RELEASE_DATE, MAGICK_RELEASE_DATE_STRING) from . import color, image, resource tests = Tests() tests.register(resource.tests) # it must be the first tests.register(color.tests) tests.register(image.tests) @tests.test def version(): """Test version strings.""" match = re.match('^ImageMagick\s+\d+\.\d+\.\d+(?:-\d+)?', MAGICK_VERSION) assert match assert isinstance(MAGICK_VERSION_INFO, tuple) assert (len(MAGICK_VERSION_INFO) == match.group(0).count('.') + match.group(0).count('-') + 1) assert all(isinstance(v, int) for v in MAGICK_VERSION_INFO) assert isinstance(MAGICK_VERSION_NUMBER, numbers.Integral) assert isinstance(MAGICK_RELEASE_DATE, datetime.date) assert (MAGICK_RELEASE_DATE_STRING == MAGICK_RELEASE_DATE.strftime('%Y-%m-%d'))
def update(self, writer, remaining_width, **kwargs): self.update_called = True writer = TerminalWriter(StringIO()) progressbar = ProgressBar([], writer) widget = MyWidget() widget.finish(progressbar, writer.get_width()) assert widget.update_called @test def repr(self): widget = Widget() Assert(repr(widget)) == 'Widget()' tests.register(TestWidget) @tests.test def test_text_widget(): writer = TerminalWriter(StringIO()) progressbar = ProgressBar([], writer) widget = TextWidget('foobar') assert widget.provides_size_hint Assert(widget.size_hint(progressbar)) == len('foobar') Assert(widget.init(progressbar, writer.get_width())) == 'foobar' Assert(widget.update(progressbar, writer.get_width())) == 'foobar' Assert(widget.finish(progressbar, writer.get_width())) == 'foobar' Assert(repr(widget)) == "TextWidget('foobar')"