From ca7d9830b2fcc1a8fa2b4537a0edc63aa4bfdd18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Sun, 26 May 2019 14:32:37 +0200 Subject: [PATCH] extract common method --- tests/python_bindings/CMake_tests/cmake_test.py | 10 ++++++---- .../CompileCommands_tests/compile_commands_test.py | 5 ++--- tests/python_bindings/jucipp_test.py | 5 +++++ 3 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 tests/python_bindings/jucipp_test.py diff --git a/tests/python_bindings/CMake_tests/cmake_test.py b/tests/python_bindings/CMake_tests/cmake_test.py index f413afb..777efee 100644 --- a/tests/python_bindings/CMake_tests/cmake_test.py +++ b/tests/python_bindings/CMake_tests/cmake_test.py @@ -1,12 +1,14 @@ from Jucipp import CMake +from jucipp_test import assert_equal + def run(project_path): cmake = CMake(project_path) - assert project_path == cmake.project_path, "Construction of CMake failed" + assert_equal(project_path, cmake.project_path) default_build_path = project_path + "/build" - assert cmake.update_default_build(default_build_path) == True, "Update of default build failed" + assert_equal(True, cmake.update_default_build(default_build_path)) executable = cmake.get_executable(default_build_path, project_path) - assert executable == default_build_path + "/cmake_project", "Invalid executable" + assert_equal(default_build_path + "/cmake_project", executable) default_debug_path = project_path + "/debug" - assert cmake.update_debug_build(default_debug_path), "Update of debug build failed" + assert_equal(True, cmake.update_debug_build(default_debug_path)) executable = cmake.get_executable(default_debug_path, project_path) diff --git a/tests/python_bindings/CompileCommands_tests/compile_commands_test.py b/tests/python_bindings/CompileCommands_tests/compile_commands_test.py index 9ef2592..3a90b6c 100644 --- a/tests/python_bindings/CompileCommands_tests/compile_commands_test.py +++ b/tests/python_bindings/CompileCommands_tests/compile_commands_test.py @@ -2,8 +2,7 @@ from Jucipp import CompileCommands from os import path -def assert_equal(expected, actual): - assert actual == expected, "Expected: " + expected + ", got " + actual +from jucipp_test import assert_equal def run(project_path, slash): build_path = project_path + slash + "build" @@ -35,4 +34,4 @@ def run(project_path, slash): arguments = CompileCommands.get_arguments(build_path, project_path + slash + "main.cpp") argument = arguments.pop() - assert_equal(build_path, argument) \ No newline at end of file + assert_equal(build_path, argument) diff --git a/tests/python_bindings/jucipp_test.py b/tests/python_bindings/jucipp_test.py new file mode 100644 index 0000000..5584728 --- /dev/null +++ b/tests/python_bindings/jucipp_test.py @@ -0,0 +1,5 @@ +""" Shared test methods """ + +def assert_equal(expected, actual): + """ Assert two variables for equality with an useful error message """ + assert actual == expected, "Expected: " + expected + ", got " + actual