Esempio n. 1
0
def test_basic_schema_fail():
    """Wrong type provided."""
    should_raise(SchemaError, First, kwargs=dict(a=1.0),
                 pattern=re.compile(r".*\n.*should be instance of 'int'.*",
                                    re.MULTILINE))
    should_raise(SchemaError, First, kwargs=dict(d=1.0),
                 pattern=re.compile(r".*Wrong keys? 'd'.*"))
Esempio n. 2
0
def test_testplan():
    """TODO."""
    from testplan.base import TestplanParser as MyParser
    plan = Testplan(name='MyPlan',
                    port=800,
                    parse_cmdline=False,
                    parser=MyParser)
    assert plan._cfg.name == 'MyPlan'
    assert plan._cfg.port == 800
    assert plan._cfg.runnable == TestRunner
    assert plan.cfg.name == 'MyPlan'
    assert plan._runnable.cfg.name == 'MyPlan'
    # Argument of manager but not of runnable.
    should_raise(AttributeError, getattr, args=(plan._runnable.cfg, 'port'))

    assert isinstance(plan.status, TestRunnerStatus)
    assert isinstance(plan._runnable.status, TestRunnerStatus)

    assert 'local_runner' in plan.resources
    assert isinstance(plan.add(DummyTest()), uuid.UUID)

    assert plan.add(DummyTest(name='alice'), uid=123) == 123
    assert plan.add(DummyTest(name='bob')) == 'bob'

    assert 'pool' not in plan.resources
    plan.add_resource(MyPool(name='pool'))
    assert 'pool' in plan.resources

    def task():
        return DummyTest(name='tom')

    assert isinstance(plan.add(task, resource='pool'), uuid.UUID)
    assert isinstance(plan.add(task, resource='pool'), uuid.UUID)

    assert len(plan.resources['local_runner']._input) == 3
    for key in (123, 'bob'):
        assert key in plan.resources['local_runner']._input
    assert len(plan.resources['pool']._input) == 2

    res = plan.run()
    assert res.run is True

    assert plan.resources['local_runner'].get(
        'bob').custom == 'DummyTestResult[bob]'
    assert plan.resources['local_runner'].get(
        123).custom == 'DummyTestResult[alice]'
    for key in plan.resources['pool']._input.keys():
        assert plan.resources['pool'].get(key).custom == 'DummyTestResult[tom]'

    results = plan.result.test_results.values()
    expected = [
        'DummyTestResult[None]', 'DummyTestResult[alice]',
        'DummyTestResult[tom]', 'DummyTestResult[tom]', 'DummyTestResult[bob]'
    ]
    for res in results:
        should_raise(AttributeError, getattr, args=(res, 'decorated_value'))
        assert res.run is True
        assert res.custom in expected
        expected.remove(res.custom)
    assert len(expected) == 0
Esempio n. 3
0
def test_skip_if_signature():
    pattern = re.compile(r'.*Expected <lambda>\(suite\), not <lambda>\(_\).*')
    try:
        should_raise(MethodSignatureMismatch,
                     incorrent_skip_if_signature1,
                     pattern=pattern)
    finally:
        # Reset the global __TESTCASES__ list so that it doesn't contain a
        # "case1" entry.
        suite.__TESTCASES__ = []
Esempio n. 4
0
def test_lambda_failing():
    """Lambdas in schema."""
    for value in (0, 1):
        should_raise(SchemaError, LambdaConfig, kwargs=dict(a=value),
                     pattern=re.compile(r".*\n.*should evaluate to True",
                                        re.MULTILINE))
    for value in (object, '1'):
        should_raise(SchemaError, LambdaConfig, kwargs=dict(b=value),
                     pattern=re.compile(r".*\n.*should evaluate to True",
                                        re.MULTILINE))
Esempio n. 5
0
def test_testcase_signature():
    pattern = re.compile((r".*Expected case1\(self, env, result\), "
                          r"not case1\(self, envs, result\).*"))
    should_raise(MethodSignatureMismatch,
                 incorrect_case_signature1,
                 pattern=pattern)
    pattern = re.compile((r".*Expected case1\(self, env, result\), "
                          r"not case1\(self, env, results\).*"))
    should_raise(MethodSignatureMismatch,
                 incorrect_case_signature2,
                 pattern=pattern)
Esempio n. 6
0
def test_send_receive_with_none_context():
    server = TCPServer(name='server', host='localhost', port=0)

    client = TCPClient(name='client',
                       host=context('server', '{{host}}'),
                       port=context('server', '{{port}}'))
    assert server.port is None
    server.start()
    server._wait_started()
    assert server.port != 0
    should_raise(ValueError, client.start)
    server.stop()
    server._wait_stopped()
Esempio n. 7
0
def test_skip_if_signature():
    pattern = re.compile(r'.*Expected <lambda>\(suite\), not <lambda>\(_\).*')
    should_raise(MethodSignatureMismatch,
                 incorrent_skip_if_signature1,
                 pattern=pattern)
Esempio n. 8
0
def test_testplan():
    """TODO."""
    from testplan.base import TestplanParser as MyParser

    plan = TestplanMock(name="MyPlan", port=800, parser=MyParser)
    assert plan._cfg.name == "MyPlan"
    assert plan._cfg.port == 800
    assert plan._cfg.runnable == TestRunner
    assert plan.cfg.name == "MyPlan"
    assert plan._runnable.cfg.name == "MyPlan"
    # Argument of manager but not of runnable.
    should_raise(AttributeError, getattr, args=(plan._runnable.cfg, "port"))

    assert isinstance(plan.status, TestRunnerStatus)
    assert isinstance(plan._runnable.status, TestRunnerStatus)

    assert "local_runner" in plan.resources
    task_uid = plan.add(DummyTest())
    assert isinstance(task_uid, str) and len(task_uid) == 36  # uuid.uuid4()

    assert plan.add(DummyTest(name="alice")) == "alice"
    assert plan.add(DummyTest(name="bob")) == "bob"

    assert "pool" not in plan.resources
    plan.add_resource(MyPool(name="pool"))
    assert "pool" in plan.resources

    def task():
        return DummyTest(name="tom")

    assert isinstance(plan.add(task, resource="pool"), str)
    with pytest.raises(ValueError):
        assert plan.add(task, resource="pool")  # duplicate target uid

    assert len(plan.resources["local_runner"]._input) == 3
    for key in ("alice", "bob"):
        assert key in plan.resources["local_runner"]._input
    assert len(plan.resources["pool"]._input) == 1

    res = plan.run()
    assert res.run is True

    assert (plan.resources["local_runner"].get("bob").custom ==
            "DummyTestResult[bob]")
    assert (plan.resources["local_runner"].get("alice").custom ==
            "DummyTestResult[alice]")
    for key in plan.resources["pool"]._input.keys():
        assert plan.resources["pool"].get(key).custom == "DummyTestResult[tom]"

    results = plan.result.test_results.values()
    expected = [
        "DummyTestResult[None]",
        "DummyTestResult[alice]",
        "DummyTestResult[tom]",
        "DummyTestResult[bob]",
    ]
    for res in results:
        should_raise(AttributeError, getattr, args=(res, "decorated_value"))
        assert res.run is True
        assert res.custom in expected
        expected.remove(res.custom)
    assert len(expected) == 0