def test_existing_submodule(self): # try_imports('thing.another', foo) imports 'thing' and returns it if # it's a module that exists. result = try_imports(["os.path"], object()) import os self.assertThat(result, Is(os.path))
def test_existing_module(self): # try_imports('thing', foo) imports 'thing' and returns it if it's a # module that exists. result = try_imports(["os"], object()) import os self.assertThat(result, Is(os))
def test_fallback_submodule(self): result = try_imports(['os.doesntexist', 'os.path']) import os self.assertThat(result, Is(os.path))
def test_nonexistent_submodule(self): # try_imports('thing.another', foo) imports 'thing' and returns foo if # 'another' doesn't exist. marker = object() result = try_imports(['os.doesntexist'], marker) self.assertThat(result, Is(marker))
def test_existing_submodule(self): # try_imports('thing.another', foo) imports 'thing' and returns it if # it's a module that exists. result = try_imports(['os.path'], object()) import os self.assertThat(result, Is(os.path))
def test_existing_module(self): # try_imports('thing', foo) imports 'thing' and returns it if it's a # module that exists. result = try_imports(['os'], object()) import os self.assertThat(result, Is(os))
def test_fallback(self): result = try_imports(['doesntexist', 'os']) import os self.assertThat(result, Is(os))
def test_doesnt_exist(self): # try_imports('thing', foo) returns foo if 'thing' doesn't exist. marker = object() result = try_imports(['doesntexist'], marker) self.assertThat(result, Is(marker))
def test_fallback(self): result = try_imports(["doesntexist", "os"]) import os self.assertThat(result, Is(os))
'StringIO', 'BytesIO', 'unicode_output_stream', ] import codecs import linecache import locale import os import re import sys import traceback from testtools.helpers import try_imports StringIO = try_imports(['StringIO.StringIO', 'io.StringIO']) BytesIO = try_imports(['io.BytesIO', 'BytesIO']) __u_doc = """A function version of the 'u' prefix. This is needed becayse the u prefix is not usable in Python 3 but is required in Python 2 to get a unicode object. To migrate code that was written as u'\u1234' in Python 2 to 2+3 change it to be _u('\u1234'). The Python 3 interpreter will decode it appropriately and the no-op _u for Python 3 lets it through, in Python 2 we then call unicode-escape in the _u function. """ if sys.version_info > (3, 0):
# Copyright (c) 2010-2011 Testtools authors. See LICENSE for details. """Tests for the distutils test command logic.""" from distutils.dist import Distribution from testtools.helpers import try_import, try_imports fixtures = try_import('fixtures') StringIO = try_imports(['StringIO.StringIO', 'io.StringIO']) import testtools from testtools import TestCase from testtools.distutilscmd import TestCommand if fixtures: class SampleTestFixture(fixtures.Fixture): """Creates testtools.runexample temporarily.""" def __init__(self): self.package = fixtures.PythonPackage( 'runexample', [('__init__.py', """ from testtools import TestCase class TestFoo(TestCase): def test_bar(self): pass def test_quux(self): pass def test_suite(): from unittest import TestLoader
# Copyright (c) 2009-2011 testtools developers. See LICENSE for details. """Test suites and related things.""" __metaclass__ = type __all__ = [ 'ConcurrentTestSuite', 'iterate_tests', 'sorted_tests', ] from testtools.helpers import safe_hasattr, try_imports Queue = try_imports(['Queue.Queue', 'queue.Queue']) import threading import unittest import testtools def iterate_tests(test_suite_or_case): """Iterate through all of the test cases in 'test_suite_or_case'.""" try: suite = iter(test_suite_or_case) except TypeError: yield test_suite_or_case else: for test in suite: for subtest in iterate_tests(test): yield subtest
'StringIO', 'reraise', 'unicode_output_stream', ] import codecs import linecache import locale import os import re import sys import traceback from testtools.helpers import try_imports BytesIO = try_imports(['StringIO.StringIO', 'io.BytesIO']) StringIO = try_imports(['StringIO.StringIO', 'io.StringIO']) try: from testtools import _compat2x as _compat _compat except SyntaxError: from testtools import _compat3x as _compat reraise = _compat.reraise __u_doc = """A function version of the 'u' prefix. This is needed becayse the u prefix is not usable in Python 3 but is required in Python 2 to get a unicode object.
# Copyright (c) 2009-2011 testtools developers. See LICENSE for details. """Test suites and related things.""" __metaclass__ = type __all__ = [ 'ConcurrentTestSuite', 'iterate_tests', ] from testtools.helpers import try_imports Queue = try_imports(['Queue.Queue', 'queue.Queue']) import threading import unittest import testtools def iterate_tests(test_suite_or_case): """Iterate through all of the test cases in 'test_suite_or_case'.""" try: suite = iter(test_suite_or_case) except TypeError: yield test_suite_or_case else: for test in suite: for subtest in iterate_tests(test): yield subtest