Example #1
0
def test_load_suite_from_module_missing_suite_decorator(tmpdir):
    file = tmpdir.join("mysuite.py")
    file.write("""
import lemoncheesecake.api as lcc

class mysuite:
    @lcc.test("My Test")
    def mytest(self):
        pass
""")

    with pytest.raises(InvalidSuiteError):
        load_suite_from_file(file.strpath)
Example #2
0
def test_load_suite_from_module_with_hooks(tmpdir):
    file = tmpdir.join("mysuite.py")
    file.write("""import lemoncheesecake.api as lcc

SUITE = {
    "description": "My Suite"
}

def setup_suite():
    return 1

def teardown_suite():
    return 2

def setup_test(test):
    return 3

def teardown_test(test, status):
    return 4

@lcc.test('My Test')
def mytest():
    pass
""")
    suite = load_suite_from_file(file.strpath)
    assert suite.get_hook("setup_suite")() == 1
    assert suite.get_hook("teardown_suite")() == 2
    assert suite.get_hook("setup_test")(suite.get_tests()[0]) == 3
    assert suite.get_hook("teardown_test")(suite.get_tests()[0], "passed") == 4
Example #3
0
def test_load_suite_from_module(tmpdir):
    file = tmpdir.join("mysuite.py")
    file.write("""SUITE = {
    "description": "My Suite"
}
""")
    suite = load_suite_from_file(file.strpath)
    assert suite.name == "mysuite"
    assert suite.description == "My Suite"
Example #4
0
def build_suite_from_module(module_content):
    fd, filename = tempfile.mkstemp(suffix=".py")
    fh = open(filename, "w")
    fh.write("import lemoncheesecake.api as lcc\n")
    fh.write("from lemoncheesecake.matching import *\n")
    fh.write("SUITE = {'description': 'My Suite'}\n\n")
    fh.write(module_content)
    fh.close()
    os.close(fd)
    suite = load_suite_from_file(filename)
    _remove_py_file(filename)

    return suite
Example #5
0
def test_load_suite_from_module_with_fixture_dependencies(tmpdir):
    file = tmpdir.join("mysuite.py")
    file.write("""import lemoncheesecake.api as lcc

SUITE = {
    "description": "My Suite"
}

foo = lcc.inject_fixture()
""")

    suite = load_suite_from_file(file.strpath)
    fixture_names = suite.get_fixtures()
    assert fixture_names == ["foo"]
Example #6
0
def test_load_suite_from_module_with_test_function(tmpdir):
    file = tmpdir.join("mysuite.py")
    file.write("""import lemoncheesecake.api as lcc

SUITE = {
    "description": "My Suite"
}

@lcc.test('My Test')
def mytest():
    pass
""")
    suite = load_suite_from_file(file.strpath)
    test = suite.get_tests()[0]
    assert test.name == "mytest"
    assert test.description == "My Test"
Example #7
0
def test_load_suite_from_module_with_all_metadata(tmpdir):
    file = tmpdir.join("mysuite.py")
    file.write("""SUITE = {
    "description": "My Suite",
    "tags": ["foo", "bar"],
    "properties": {"bar": "baz"},
    "links": [("http://u.r.l/1234", None), ("http://u.r.l/1235", "#1235")],
}
""")
    suite = load_suite_from_file(file.strpath)
    assert suite.name == "mysuite"
    assert suite.description == "My Suite"
    assert suite.tags == ["foo", "bar"]
    assert suite.properties == {"bar": "baz"}
    assert suite.links == [("http://u.r.l/1234", None),
                           ("http://u.r.l/1235", "#1235")]
Example #8
0
def test_load_suite_from_module_suites_order(tmpdir):
    file = tmpdir.join("mysuite.py")
    file.write("""
import lemoncheesecake.api as lcc


SUITE = {
    "description": "My Suite"
}


@lcc.suite("a")
class a:
    @lcc.test("test")
    def test(self):
        pass


@lcc.suite("d")
class d:
    @lcc.test("test")
    def test(self):
        pass


@lcc.suite("c")
class c:
    @lcc.test("test")
    def test(self):
        pass


@lcc.suite("b")
class b:
    @lcc.test("test")
    def test(self):
        pass
""")

    suite = load_suite_from_file(file.strpath)
    suites = suite.get_suites()

    assert suites[0].name == "a"
    assert suites[1].name == "d"
    assert suites[2].name == "c"
    assert suites[3].name == "b"
Example #9
0
def test_load_suite_from_module_with_sub_suite(tmpdir):
    file = tmpdir.join("mysuite.py")
    file.write("""import lemoncheesecake.api as lcc

SUITE = {
    "description": "My Suite"
}

@lcc.suite('Sub Suite')
class subsuite:
    @lcc.test("My Test")
    def mytest(self):
        pass
""")
    suite = load_suite_from_file(file.strpath)
    sub_suite = suite.get_suites()[0]
    assert sub_suite.name == "subsuite"
    assert sub_suite.description == "Sub Suite"
Example #10
0
def test_load_suite_from_module_tests_order(tmpdir):
    file = tmpdir.join("mysuite.py")
    file.write("""
import lemoncheesecake.api as lcc


SUITE = {
    "description": "My Suite"
}


@lcc.test("a")
def a():
    pass


@lcc.test("d")
def d():
    pass


@lcc.test("c")
def c():
    pass


@lcc.test("b")
def b():
    pass
""")

    suite = load_suite_from_file(file.strpath)
    tests = suite.get_tests()

    assert tests[0].name == "a"
    assert tests[1].name == "d"
    assert tests[2].name == "c"
    assert tests[3].name == "b"
Example #11
0
def test_load_suite_from_module_missing_suite_definition(tmpdir):
    file = tmpdir.join("mysuite.py")
    file.write("")

    with pytest.raises(ModuleImportError):
        load_suite_from_file(file.strpath)
Example #12
0
def test_load_suite_from_file_invalid_class(tmpdir):
    file = tmpdir.join("anothersuite.py")
    file.write(build_test_module())
    with pytest.raises(ModuleImportError):
        load_suite_from_file(file.strpath)
Example #13
0
def test_load_suite_from_file_invalid_module(tmpdir):
    file = tmpdir.join("doesnotexist.py")
    with pytest.raises(ModuleImportError):
        load_suite_from_file(file.strpath)
Example #14
0
def test_load_suite_from_file(tmpdir):
    file = tmpdir.join("mysuite.py")
    file.write(build_test_module())
    klass = load_suite_from_file(file.strpath)
    assert klass.name == "mysuite"