+import sys
+import subprocess
+
+
+def run_command(args):
+ result = subprocess.run(" ".join(args), shell=True,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ result.stdout = result.stdout.decode("ASCII", errors='ignore')
+ result.stderr = result.stderr.decode("ASCII", errors='ignore')
+ return result
+
+
+def rmv_cmd(trgt):
+ """Remove target with force"""
+ result = run_command(["rm", "-rf", trgt])
+ if result.returncode != 0:
+ raise Exception("Removing {} before testing failed!".
+ format(os.path.dirname(os.path.realpath(__file__))
+ + trgt))
+
+
+def cleanup():
+ """Delete files created by unit tests"""
+ script_path = os.path.dirname(os.path.realpath(__file__))
+ test_dir = os.path.join(script_path, tests_config.MAIN_DIRECTORY_OF_UNIT_TESTS)
+ result = run_command(["cd", test_dir])
+ if result.returncode != 0:
+ raise Exception("Cleanup before testing failed!")
+
+ # r=root, d=directories, f = files
+ for r, d, f in os.walk(test_dir):
+ for file in f:
+ if '_generated_wrap' in file:
+ rmv_cmd(file)
+
+ rmv_cmd("preprocessed_sources_repository")
+ rmv_cmd("sources_to_test_repository")
+ rmv_cmd("build")
+
+ result = run_command(["cd", script_path])
+ if result.returncode != 0:
+ raise Exception("Cleanup before testing failed!")
+
+
+cleanup()