def SetUp1(test_run):
    print 'running first setup method for test_run %s' % test_run.name


def SetUp2(test_run):
    print 'running second setup method for test_run %s' % test_run.name


def TearDown1(test_run):
    print 'running first teardown method for test_run %s' % test_run.name


def TearDown2(test_run):
    print 'running second teardown method for test_run %s' % test_run.name


if __name__ == '__main__':
    # To run a test method directly
    ctx = checkers.DefaultContext(TestOnePlusOneEqualsTwo)
    TestOnePlusOneEqualsTwo(ctx)
    checkers.RunTest(TestOnePlusOneEqualsTwo)
    # Extra arguments just get ignored by checkers, but the more
    # correct behavior would probably be to have this raise an error.
    checkers.RunTest(TestOnePlusOneEqualsTwo, Calculator())

    # ctx = checkers.DefaultContext(TestTwoPlusTwoEqualsFour)
    # TestTwoPlusTwoEqualsFour(Calculator())
    checkers.RunTest(TestTwoPlusTwoEqualsFour, Calculator())

    pyunit.main(CreateTestRun())
def BuildTestCase(number_text, number_value):
  proto_text = TEST_CASE_PROTO % (number_text, number_value,
                                  number_value, MODULE_NAME)
  test_case = checkers.TestCase.Parse(proto_text)
  return test_case


# @checkers.TestTemplate
# @checkers.TestData('n', checkers.Decimal, 'The number dividing 0.')
def TestZeroDividedByNEquals0(n):
  """Test template that verifies that 0 divided by any non-zero number is 0."""
  print '0 / %d = 0' % n
  quotient = 0 / n
  AssertThat(quotient, Is(EqualTo(0)))


TEST_DATA = {'One': 1, 'Two': 2, 'NegativeOne': -1, 'OneMillion': 1000000}


def CreateTestRun():
  """Test run that will execute the defined test."""
  test_run = checkers.TestRun()
  for number, value in TEST_DATA.iteritems():
    test_case = BuildTestCase(number, value)
    test_run.LoadTestCase(test_case)
    return test_run


if __name__ == '__main__':
  pyunit.main(CreateTestRun())
Exemple #3
0
#     limitations under the License.

"""Example Checkers test run that checks 1 + 1 = 2."""

from checkers.examples.quickstart import divide_tests
from checkers.examples.quickstart.calculator import Calculator
from checkers.python import checkers
from checkers.python.integrations.pyunit import pyunit


def CreateTestRun1():
  """Test run that will execute the defined test."""
  test_run = checkers.TestRun('calculator1')
  test_run.components.Register('calculator', Calculator())
  test_suite = checkers.TestSuite.FromProto(divide_tests.ParseTestSuiteProto())
  test_run.LoadTestSuite(test_suite)
  return test_run


def CreateTestRun2():
  """Test run that will execute the defined test."""
  test_run = checkers.TestRun('calculator2')
  test_run.components.Register('calculator', Calculator())
  test_suite = checkers.TestSuite.FromProto(divide_tests.ParseTestSuiteProto())
  test_run.LoadTestSuite(test_suite)
  return test_run


if __name__ == '__main__':
  pyunit.main([CreateTestRun1(), CreateTestRun2()])