Ejemplo n.º 1
0
def test_test_call_fixtures():
  tracker = set()

  def foo_setup():
    tracker.add('foo_setup')

  def bar_setup(context):
    if context:
      tracker.add('bar_setup')

  def foo_teardown():
    tracker.add('foo_teardown')

  def bar_teardown(context):
    if context:
      tracker.add('bar_teardown')

  @checkers.setup(foo_setup, bar_setup)
  @checkers.teardown(foo_teardown, bar_teardown)
  @checkers.test
  def dummy_test():
    tracker.add('dummy_test')

  context_factory = _dummy_context_factory
  tc = test_case.TestCase(dummy_test, context_factory)
  result = tc()
  asserts.are_equal(result.status, test_result.TestResultStatus.PASSED)
  asserts.has_length(tracker, 5)
Ejemplo n.º 2
0
def test_test_call_fixtures():
    tracker = set()

    def foo_setup():
        tracker.add('foo_setup')

    def bar_setup(context):
        if context:
            tracker.add('bar_setup')

    def foo_teardown():
        tracker.add('foo_teardown')

    def bar_teardown(context):
        if context:
            tracker.add('bar_teardown')

    @checkers.setup(foo_setup, bar_setup)
    @checkers.teardown(foo_teardown, bar_teardown)
    @checkers.test
    def dummy_test():
        tracker.add('dummy_test')

    context_factory = _dummy_context_factory
    tc = test_case.TestCase(dummy_test, context_factory)
    result = tc()
    asserts.are_equal(result.status, test_result.TestResultStatus.PASSED)
    asserts.has_length(tracker, 5)
Ejemplo n.º 3
0
def test_context_init():
  tc = _DummyTestCase()
  tr = _DummyTestRun()
  ctx = context.Context(tc, tr)
  asserts.are_same(tc, ctx.test_case)
  asserts.are_same(tr, ctx.test_run)
  asserts.are_equal(len(ctx.variables), 1)
  asserts.is_in('context', ctx.variables)
Ejemplo n.º 4
0
def test_test_call_failure_from_assertion():
  @checkers.test
  def dummy_test():
    asserts.is_true(False)

  context_factory = _dummy_context_factory
  tc = test_case.TestCase(dummy_test, context_factory)
  result = tc()
  asserts.are_equal(result.status, test_result.TestResultStatus.FAILED)
Ejemplo n.º 5
0
def test_test_call_error_from_exception():
  @checkers.test
  def dummy_test():
    raise ValueError('just raising a random exception...')

  context_factory = _dummy_context_factory
  tc = test_case.TestCase(dummy_test, context_factory)
  result = tc()
  asserts.are_equal(result.status, test_result.TestResultStatus.ERROR)
Ejemplo n.º 6
0
def test_test_call_error_from_exception():
    @checkers.test
    def dummy_test():
        raise ValueError('just raising a random exception...')

    context_factory = _dummy_context_factory
    tc = test_case.TestCase(dummy_test, context_factory)
    result = tc()
    asserts.are_equal(result.status, test_result.TestResultStatus.ERROR)
Ejemplo n.º 7
0
def test_test_call_failure_from_assertion():
    @checkers.test
    def dummy_test():
        asserts.is_true(False)

    context_factory = _dummy_context_factory
    tc = test_case.TestCase(dummy_test, context_factory)
    result = tc()
    asserts.are_equal(result.status, test_result.TestResultStatus.FAILED)
Ejemplo n.º 8
0
def test_test_case_init():
  test = _dummy_test
  context_factory = _dummy_context_factory
  tc = test_case.TestCase(test, context_factory)
  asserts.are_equal(tc.name, '_dummy_test')
  asserts.are_equal(tc.full_name, 'test_case_test._dummy_test')
  asserts.are_same(tc.test, test)
  asserts.is_not_none(tc.context)
  asserts.is_empty(tc.description)
  asserts.is_empty(tc.test_suites)
Ejemplo n.º 9
0
def test_test_run_init():
    run = test_run.TestRun('foo')
    asserts.are_equal(run.name, 'foo')
    asserts.is_empty(run.variables)
    asserts.is_empty(run.setup)
    asserts.is_empty(run.teardown)
    asserts.is_empty(run.test_case_setup)
    asserts.is_empty(run.test_case_teardown)
    asserts.is_empty(run.test_suites)
    asserts.is_empty(run.parameterizations)
Ejemplo n.º 10
0
def test_test_run_init():
  run = test_run.TestRun('foo')
  asserts.are_equal(run.name, 'foo')
  asserts.is_empty(run.variables)
  asserts.is_empty(run.setup)
  asserts.is_empty(run.teardown)
  asserts.is_empty(run.test_case_setup)
  asserts.is_empty(run.test_case_teardown)
  asserts.is_empty(run.test_suites)
  asserts.is_empty(run.parameterizations)
Ejemplo n.º 11
0
def test_test_case_init():
    test = _dummy_test
    context_factory = _dummy_context_factory
    tc = test_case.TestCase(test, context_factory)
    asserts.are_equal(tc.name, '_dummy_test')
    asserts.are_equal(tc.full_name, 'test_case_test._dummy_test')
    asserts.are_same(tc.test, test)
    asserts.is_not_none(tc.context)
    asserts.is_empty(tc.description)
    asserts.is_empty(tc.test_suites)
Ejemplo n.º 12
0
def test_registry_indexers():
  reg = registry.Registry()
  reg.register('foo', 2)
  reg.register('bar', 4)
  reg.register('baz.quux', 8)
  asserts.are_equal(reg['foo'], 2)
  asserts.are_equal(reg['bar'], 4)
  asserts.are_equal(reg['baz.quux'], 8)
Ejemplo n.º 13
0
def test_registry_indexers():
    reg = registry.Registry()
    reg.register('foo', 2)
    reg.register('bar', 4)
    reg.register('baz.quux', 8)
    asserts.are_equal(reg['foo'], 2)
    asserts.are_equal(reg['bar'], 4)
    asserts.are_equal(reg['baz.quux'], 8)
Ejemplo n.º 14
0
def test_registry_attributes():
  reg = registry.Registry()
  reg.register('foo', 2)
  reg.register('bar', 4)
  reg.register('baz.quux', 8)
  asserts.are_equal(reg.foo, 2)
  asserts.are_equal(reg.bar, 4)
  asserts.are_equal(reg.baz__DOT__quux, 8)
Ejemplo n.º 15
0
def test_registry_attributes():
    reg = registry.Registry()
    reg.register('foo', 2)
    reg.register('bar', 4)
    reg.register('baz.quux', 8)
    asserts.are_equal(reg.foo, 2)
    asserts.are_equal(reg.bar, 4)
    asserts.are_equal(reg.baz__DOT__quux, 8)
Ejemplo n.º 16
0
def test_test_init():
    t = Test('foo', 'bar.foo', 'foo bar test')
    asserts.are_equal(t.name, 'foo')
    asserts.are_equal(t.full_name, 'bar.foo')
    asserts.are_equal(t.description, 'foo bar test')
    asserts.is_empty(t.decorator_parameterizations)
    asserts.is_empty(t.setup)
    asserts.is_empty(t.teardown)
    asserts.is_empty(t.test_suite_names)
Ejemplo n.º 17
0
def test_test_init():
  t = Test('foo', 'bar.foo', 'foo bar test')
  asserts.are_equal(t.name, 'foo')
  asserts.are_equal(t.full_name, 'bar.foo')
  asserts.are_equal(t.description, 'foo bar test')
  asserts.is_empty(t.decorator_parameterizations)
  asserts.is_empty(t.setup)
  asserts.is_empty(t.teardown)
  asserts.is_empty(t.test_suite_names)
Ejemplo n.º 18
0
def test_test_clone():
    original = Test('foo', 'bar.foo', 'foo bar test')
    clone = original.clone()
    asserts.are_equal(clone.name, 'foo')
    asserts.are_equal(clone.full_name, 'bar.foo')
    asserts.are_equal(clone.description, 'foo bar test')
    asserts.is_empty(clone.decorator_parameterizations)
    asserts.is_empty(clone.setup)
    asserts.is_empty(clone.teardown)
    asserts.is_empty(clone.test_suite_names)
Ejemplo n.º 19
0
def test_context_init_with_args():
  tc = _DummyTestCase()
  tr = _DummyTestRun()
  ctx = context.Context(tc, tr, foo='foo', bar=2)
  asserts.are_same(tc, ctx.test_case)
  asserts.are_same(tr, ctx.test_run)
  asserts.are_equal(len(ctx.variables), 3)
  asserts.are_equal(ctx.variables.foo, 'foo')
  asserts.are_equal(ctx.variables.bar, 2)
  asserts.is_in('context', ctx.variables)
Ejemplo n.º 20
0
def test_test_clone():
  original = Test('foo', 'bar.foo', 'foo bar test')
  clone = original.clone()
  asserts.are_equal(clone.name, 'foo')
  asserts.are_equal(clone.full_name, 'bar.foo')
  asserts.are_equal(clone.description, 'foo bar test')
  asserts.is_empty(clone.decorator_parameterizations)
  asserts.is_empty(clone.setup)
  asserts.is_empty(clone.teardown)
  asserts.is_empty(clone.test_suite_names)
Ejemplo n.º 21
0
def test_find_module_name_short():
  name = modules.find_module_name(asserts, fully_qualified=False)
  asserts.are_equal('asserts', name)
Ejemplo n.º 22
0
def test_test_suite_from_module():
  module = sys.modules[__name__]
  suite = test_suite.TestSuite.from_module(module)
  asserts.is_not_empty(suite)
  asserts.are_equal(suite.name, 'test_suite_test')
Ejemplo n.º 23
0
def test_test_suite_init():
  ts = test_suite.TestSuite('foo', 'foo description')
  asserts.are_equal(ts.name, 'foo')
  asserts.are_equal(ts.description, 'foo description')
  asserts.is_none(ts.test_run)
Ejemplo n.º 24
0
def test_test_result_status_error():
    asserts.are_equal(test_result.TestResultStatus.ERROR, 'ERROR')
Ejemplo n.º 25
0
def test_test_result_status_error():
  asserts.are_equal(test_result.TestResultStatus.ERROR, 'ERROR')
Ejemplo n.º 26
0
def test_registry_register_with_len():
    reg = registry.Registry()
    reg.register('foo', 2)
    reg.register('bar', 4)
    reg.register('baz.quux', 8)
    asserts.are_equal(len(reg), 3)
Ejemplo n.º 27
0
def test_registry_values():
    reg = registry.Registry()
    reg.register('foo', 2)
    reg.register('bar', 4)
    reg.register('baz.quux', 8)
    asserts.are_equal(reg.values(), [2, 4, 8])
Ejemplo n.º 28
0
def test_add_1_1_2(calculator):
    asserts.are_equal(calculator.add(2, 2), 4)
    print "1 + 1 = 2"
Ejemplo n.º 29
0
def test_assert_equal_bad(x, y):
    with asserts.expect_exception(AssertionError):
        asserts.are_equal(x, y)
def test_subtract(calculator, x, y, expected):
  asserts.are_equal(calculator.subtract(x, y), expected)
  print '%d - %d = %d' % (x, y, expected)
def test_add(calculator, x, y, expected):
  asserts.are_equal(calculator.add(x, y), expected)
  print '%d + %d = %d' % (x, y, expected)
Ejemplo n.º 32
0
def test_add_2_2_4(calculator):
    asserts.are_equal(calculator.add(2, 2), 4)
    print "2 + 2 = 4"
Ejemplo n.º 33
0
def test_find_module_name_from_name():
  name = modules.find_module_name_from_name(__name__)
  asserts.are_equal('modules_test', name)
Ejemplo n.º 34
0
def test_test_run_from_module():
    module = sys.modules[__name__]
    run = test_run.TestRun.from_module(module)
    asserts.is_not_empty(run.tests)
    asserts.are_equal(run.name, 'test_run_test')
Ejemplo n.º 35
0
def test_tests_from_module():
  module = sys.modules[__name__]
  tests = modules.tests_from_module(module)
  asserts.are_equal(len(tests), 4)
Ejemplo n.º 36
0
def test_test_result_status_passed():
  asserts.are_equal(test_result.TestResultStatus.PASSED, 'PASSED')
Ejemplo n.º 37
0
def test_assert_equal_ok(x, y):
    asserts.are_equal(x, y)
Ejemplo n.º 38
0
def test_add_4_8_12(calculator):
    asserts.are_equal(calculator.add(4, 8), 12)
    print "4 + 8 = 12"
Ejemplo n.º 39
0
def test_registry_keys():
    reg = registry.Registry()
    reg.register('foo', 2)
    reg.register('bar', 4)
    reg.register('baz.quux', 8)
    asserts.are_equal(reg.keys(), ['foo', 'bar', 'baz.quux'])
Ejemplo n.º 40
0
def test_registry_keys():
  reg = registry.Registry()
  reg.register('foo', 2)
  reg.register('bar', 4)
  reg.register('baz.quux', 8)
  asserts.are_equal(reg.keys(), ['foo', 'bar', 'baz.quux'])
Ejemplo n.º 41
0
def test_registry_unregister_with_present_key():
    reg = registry.Registry()
    reg.register('foo', 4)
    asserts.are_equal(len(reg), 1)
    reg.unregister('foo')
    asserts.is_empty(reg)
Ejemplo n.º 42
0
def test_registry_unregister_with_present_key():
  reg = registry.Registry()
  reg.register('foo', 4)
  asserts.are_equal(len(reg), 1)
  reg.unregister('foo')
  asserts.is_empty(reg)
Ejemplo n.º 43
0
def test_parameterization_init():
    param = parameterization.Parameterization('name')
    asserts.are_equal(param.name, 'name')
    asserts.is_empty(param.variables)
Ejemplo n.º 44
0
def test_parameterization_init():
  param = parameterization.Parameterization('name')
  asserts.are_equal(param.name, 'name')
  asserts.is_empty(param.variables)
Ejemplo n.º 45
0
def test_test_result_status_failed():
  asserts.are_equal(test_result.TestResultStatus.FAILED, 'FAILED')
Ejemplo n.º 46
0
def test_parameterization_with_variables():
    variables = {'foo': 0, 'bar': 2, 'baz': 4, 'quux': 8}
    param = parameterization.Parameterization('name', variables)
    asserts.are_equal(param.name, 'name')
    asserts.has_length(param.variables, 4)
Ejemplo n.º 47
0
def test_test_run_from_module():
  module = sys.modules[__name__]
  run = test_run.TestRun.from_module(module)
  asserts.is_not_empty(run.tests)
  asserts.are_equal(run.name, 'test_run_test')
Ejemplo n.º 48
0
def test_double(x, expected):
    asserts.are_equal(x + x, expected)
    asserts.are_equal(x * 2, expected)
Ejemplo n.º 49
0
def test_registry_register_with_len():
  reg = registry.Registry()
  reg.register('foo', 2)
  reg.register('bar', 4)
  reg.register('baz.quux', 8)
  asserts.are_equal(len(reg), 3)
Ejemplo n.º 50
0
def test_add(x, y, expected):
    asserts.are_equal(x + y, expected)
Ejemplo n.º 51
0
def test_find_module_name():
    module = sys.modules[__name__]
    name = modules.find_module_name(module)
    asserts.are_equal('modules_test', name)
Ejemplo n.º 52
0
def test_find_module_name():
  module = sys.modules[__name__]
  name = modules.find_module_name(module)
  asserts.are_equal('modules_test', name)
Ejemplo n.º 53
0
def test_registry_values():
  reg = registry.Registry()
  reg.register('foo', 2)
  reg.register('bar', 4)
  reg.register('baz.quux', 8)
  asserts.are_equal(reg.values(), [2, 4, 8])
Ejemplo n.º 54
0
def test_find_module_name_short():
    name = modules.find_module_name(asserts, fully_qualified=False)
    asserts.are_equal('asserts', name)
Ejemplo n.º 55
0
def test_subtract(x, y, expected):
    return asserts.are_equal(x - y, expected)
Ejemplo n.º 56
0
def test_find_module_name_from_name():
    name = modules.find_module_name_from_name(__name__)
    asserts.are_equal('modules_test', name)
Ejemplo n.º 57
0
def test_parameterization_with_variables():
  variables = {'foo': 0, 'bar': 2, 'baz': 4, 'quux': 8}
  param = parameterization.Parameterization('name', variables)
  asserts.are_equal(param.name, 'name')
  asserts.has_length(param.variables, 4)
Ejemplo n.º 58
0
def test_tests_from_module():
    module = sys.modules[__name__]
    tests = modules.tests_from_module(module)
    asserts.are_equal(len(tests), 4)