def test_simple_run(tmpdir, qitest_action): """ Test Simple Run """ ls = qisys.command.find_program("ls") tests = [{"name": "ls", "cmd": [ls], "timeout": 1}] qitest_json = tmpdir.join("qitest.json") qitest_json.write(json.dumps(tests)) qitest_action("run", cwd=tmpdir.strpath)
def test_setting_build_prefix(qitest_action, qibuild_action, tmpdir): """ Test Setting Build Prefix """ prefix = tmpdir.join("prefix") qibuild_action.add_test_project("testme") qibuild_action("configure", "testme", "--build-prefix", prefix.strpath) qibuild_action("make", "testme", "--build-prefix", prefix.strpath) qitest_action("run", "testme", "-k", "ok", "--build-prefix", prefix.strpath) test_results = prefix.join("build-sys-%s" % (TARGET), "testme", "sdk", "test-results") assert test_results.join("ok.xml").check(file=True)
def test_action_coverage(qibuild_action, qitest_action): """ Test Action Coverage """ gcovr = qisys.command.find_program("gcovr", raises=False) if not gcovr: return qibuild_action.add_test_project("cov") qibuild_action("configure", "cov", "--coverage") qibuild_action("make", "cov") qitest_action("run", "cov", "--coverage")
def test_simple_run(tmpdir, qitest_action): """ Test Simple Run """ ls = qisys.command.find_program("ls") tests = [ {"name": "ls", "cmd": [ls], "timeout": 1} ] qitest_json = tmpdir.join("qitest.json") qitest_json.write(json.dumps(tests)) qitest_action("run", cwd=tmpdir.strpath)
def test_setting_build_prefix(qitest_action, qibuild_action, tmpdir): prefix = tmpdir.join("prefix") qibuild_action.add_test_project("testme") qibuild_action("configure", "testme", "--build-prefix", prefix.strpath) qibuild_action("make", "testme", "--build-prefix", prefix.strpath) qitest_action("run", "testme", "-k", "ok", "--build-prefix", prefix.strpath) test_results = prefix.join("build-sys-%s-%s" % (platform.system().lower(), platform.machine().lower()), "testme", "sdk", "test-results") assert test_results.join("ok.xml").check(file=True)
def test_simple(qitest_action, record_messages): """ Test Simple """ testme_proj = qitest_action.add_test_project("testme") qitest_action("collect") pytest_json = os.path.join(testme_proj.path, "pytest.json") tests = qitest.conf.parse_tests(pytest_json) names = [x["name"] for x in tests] assert set(names) == set([ "testme.test.test_foo", "testme.test.test_bar", "testme.test.subfolder.test_spam"])
def test_simple(qitest_action, record_messages): """ Test Simple """ testme_proj = qitest_action.add_test_project("testme") qitest_action("collect") pytest_json = os.path.join(testme_proj.path, "pytest.json") tests = qitest.conf.parse_tests(pytest_json) names = [x["name"] for x in tests] assert set(names) == set([ "testme.test.test_foo", "testme.test.test_bar", "testme.test.subfolder.test_spam" ])
def test_simple(qitest_action, tmpdir, record_messages): """ Test Simple """ tests = [ {"name": "foo", "gtest": True}, {"name": "test_bar"}, {"name": "test_baz", "pytest": True} ] qitest_json = tmpdir.join("qitest.json") qitest_json.write(json.dumps(tests)) qitest_action("list", cwd=tmpdir.strpath) assert record_messages.find(r"foo.*\(invalid name\)") assert record_messages.find(r"test_bar.*\(no type\)")
def test_setting_output_dir_with_project(qitest_action, qibuild_action, tmpdir): test_out = tmpdir.join("test-out", "testme") qibuild_action.add_test_project("testme") qibuild_action("configure", "testme") qibuild_action("make", "testme") qitest_action("run", "testme", "-k", "ok", "--root-output-dir", test_out.strpath) ok_xml = test_out.join("testme", "test-results", "ok.xml") assert ok_xml.check(file=True) retcode = qitest_action("run", "testme", "-k", "fail", "--root-output-dir", test_out.strpath, retcode=True) assert not ok_xml.check(file=True)
def test_setting_output_dir_without_project(qitest_action, qibuild_action, tmpdir): dest = tmpdir.join("dest") qibuild_action.add_test_project("testme") qibuild_action("configure", "testme") qibuild_action("make", "testme") qibuild_action("install", "--with-tests", "testme", dest.strpath) qitest_json = dest.join("qitest.json") out = tmpdir.join("out") qitest_action("run", "-k", "ok", "--qitest-json", qitest_json.strpath, "--root-output-dir", out.strpath) assert out.join("test-results", "ok.xml").check(file=True)
def test_run_last_failed(tmpdir, qitest_action, record_messages): """ Test Run Last Failed """ test_one = tmpdir.join("test_one.py") test_one.write("import sys; sys.exit(1)") test_two = tmpdir.join("test_two.py") test_two.write("") qitest_json = tmpdir.join("qitest.json") tests = [ { "name": "test_one", "cmd": [sys.executable, test_one.strpath], "timeout": 1 }, { "name": "test_two", "cmd": [sys.executable, test_two.strpath], "timeout": 1 }, ] qitest_json.write(json.dumps(tests)) qitest_action.chdir(tmpdir) qitest_action("run", retcode=True) record_messages.reset() qitest_action("run", "--last-failed", retcode=True) assert not record_messages.find(r"\(2/2\) test_two") assert record_messages.find(r"\(1/1\) test_one") test_one.write("") record_messages.reset() qitest_action("run", "--last-failed", retcode=True) qitest_action("run", "--last-failed", retcode=True) assert record_messages.find("No failing tests found")
def test_repeat_until_fail(tmpdir, qitest_action): """ Test Repeat Until Fail """ ls = qisys.command.find_program("ls") rm = qisys.command.find_program("rm") food = tmpdir.join("foo") food.write("this is foo\n") tests = [ { "name": "ls", "cmd": [ls, food.strpath], "timeout": 1 }, { "name": "rm", "cmd": [rm, food.strpath], "timeout": 1 }, ] qitest_json = tmpdir.join("qitest.json") qitest_json.write(json.dumps(tests)) rc = qitest_action("run", "--repeat-until-fail", "2", cwd=tmpdir.strpath, retcode=True) assert rc != 0
def test_exclude(tmpdir, qitest_action): """ Test Exclude """ tests = [ {"name": "foo", "cmd": [sys.executable, "--version"]}, {"name": "bar", "cmd": [sys.executable, "-c", "import sys ; sys.exit(1)"]} ] qitest_json = tmpdir.join("qitest.json") qitest_json.write(json.dumps(tests)) rc = qitest_action("run", "--exclude", "bar", cwd=tmpdir.strpath, retcode=True) assert rc == 0
def test_ignore_timeouts(qitest_action, tmpdir): """ Test Ignore TimeOuts """ qitest_json = tmpdir.join("qitest.json") sleep_cmd = qisys.command.find_program("sleep") qitest_json.write(""" [ {"name": "test_one", "cmd" : ["%s", "2"], "timeout" : 1} ] """ % sleep_cmd) rc = qitest_action("run", "--qitest-json", qitest_json.strpath, "--ignore-timeouts", retcode=True) assert rc == 0
def test_repeat_until_fail(tmpdir, qitest_action): """ Test Repeat Until Fail """ ls = qisys.command.find_program("ls") rm = qisys.command.find_program("rm") food = tmpdir.join("foo") food.write("this is foo\n") tests = [ {"name": "ls", "cmd": [ls, food.strpath], "timeout": 1}, {"name": "rm", "cmd": [rm, food.strpath], "timeout": 1}, ] qitest_json = tmpdir.join("qitest.json") qitest_json.write(json.dumps(tests)) rc = qitest_action("run", "--repeat-until-fail", "2", cwd=tmpdir.strpath, retcode=True) assert rc != 0
def test_exclude(tmpdir, qitest_action): """ Test Exclude """ tests = [{ "name": "foo", "cmd": [sys.executable, "--version"] }, { "name": "bar", "cmd": [sys.executable, "-c", "import sys ; sys.exit(1)"] }] qitest_json = tmpdir.join("qitest.json") qitest_json.write(json.dumps(tests)) rc = qitest_action("run", "--exclude", "bar", cwd=tmpdir.strpath, retcode=True) assert rc == 0
def test_no_capture(tmpdir, qitest_action): """ Test No Capture """ if not sys.stdout.isatty(): # The test will fail anyway return test_tty = tmpdir.join("test_tty.py") test_tty.write(""" import sys if not sys.stdout.isatty(): sys.exit("sys.stdout is not a tty") """) tests = [ {"name": "test_tty", "cmd": [sys.executable, test_tty.strpath], "timeout": 1} ] qitest_json = tmpdir.join("qitest.json") qitest_json.write(json.dumps(tests)) rc = qitest_action("run", "--no-capture", cwd=tmpdir.strpath, retcode=True) assert rc == 0
def test_no_capture(tmpdir, qitest_action): """ Test No Capture """ if not sys.stdout.isatty(): # The test will fail anyway return test_tty = tmpdir.join("test_tty.py") test_tty.write(""" import sys if not sys.stdout.isatty(): sys.exit("sys.stdout is not a tty") """) tests = [{ "name": "test_tty", "cmd": [sys.executable, test_tty.strpath], "timeout": 1 }] qitest_json = tmpdir.join("qitest.json") qitest_json.write(json.dumps(tests)) rc = qitest_action("run", "--no-capture", cwd=tmpdir.strpath, retcode=True) assert rc == 0
def test_run_last_failed(tmpdir, qitest_action, record_messages): """ Test Run Last Failed """ test_one = tmpdir.join("test_one.py") test_one.write("import sys; sys.exit(1)") test_two = tmpdir.join("test_two.py") test_two.write("") qitest_json = tmpdir.join("qitest.json") tests = [ {"name": "test_one", "cmd": [sys.executable, test_one.strpath], "timeout": 1}, {"name": "test_two", "cmd": [sys.executable, test_two.strpath], "timeout": 1}, ] qitest_json.write(json.dumps(tests)) qitest_action.chdir(tmpdir) qitest_action("run", retcode=True) record_messages.reset() qitest_action("run", "--last-failed", retcode=True) assert not record_messages.find(r"\(2/2\) test_two") assert record_messages.find(r"\(1/1\) test_one") test_one.write("") record_messages.reset() qitest_action("run", "--last-failed", retcode=True) qitest_action("run", "--last-failed", retcode=True) assert record_messages.find("No failing tests found")