From ba20871582f7926285e0f46273155aef06bbc39c Mon Sep 17 00:00:00 2001 From: regeciovad Date: Wed, 30 Sep 2015 13:57:28 +0200 Subject: [PATCH] Less hard-coded architecture in tests (fix #296) --- tests/unit/test_functional.py | 22 ++++++++++++++-------- tests/unit/test_plugins.py | 23 +++++++++++++++-------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/tests/unit/test_functional.py b/tests/unit/test_functional.py index fc804bc..a6d3e2a 100644 --- a/tests/unit/test_functional.py +++ b/tests/unit/test_functional.py @@ -1,9 +1,15 @@ from tests.support import RpgTestCase from rpg import Base +import re class FunctionalTest(RpgTestCase): + def find_match(self, expected, files): + output = {i: [r.pattern for r in expected if r.match(i)] + for i in set(files)} + return output + def test_c_project(self): base = Base() base.load_plugins() @@ -21,7 +27,6 @@ def test_c_project(self): expected_required_files = { '/usr/include/bits/wordsize.h', '/usr/include/bits/typesizes.h', - '/usr/lib/gcc/x86_64-redhat-linux/5.1.1/include/stdarg.h', '/usr/include/bits/stdio_lim.h', '/usr/include/bits/sys_errlist.h', '/usr/include/features.h', @@ -32,11 +37,12 @@ def test_c_project(self): '/usr/include/wchar.h', '/usr/include/stdio.h', '/usr/include/sys/cdefs.h', - '/usr/lib/gcc/x86_64-redhat-linux/5.1.1/include/stddef.h', '/usr/include/libio.h', - '/usr/include/gnu/stubs-64.h' + '/usr/lib/gcc/[^/]*-redhat-linux/\d+.\d+.\d+./include/stddef.h', + '/usr/include/gnu/stubs-64.h', + '/usr/lib/gcc/[^/]*-redhat-linux/\d+.\d+.\d+./include/stdarg.h' } - expected_build_required_files = expected_required_files + ref_re = [re.compile(r) for r in expected_required_files] dirs = [ "Makefile", "hello.c", @@ -44,10 +50,10 @@ def test_c_project(self): ] base.run_installed_source_analysis() self.assertEqual(set(["make"]), base.spec.BuildRequires) - self.assertEqual(expected_required_files, - set(base.spec.required_files)) - self.assertEqual(expected_build_required_files, - set(base.spec.build_required_files)) + output = self.find_match(ref_re, base.spec.required_files) + self.assertEqual(len(output), len(expected_required_files)) + output = self.find_match(ref_re, base.spec.build_required_files) + self.assertEqual(len(output), len(expected_required_files)) self.assertExistInDir(["Makefile", "hello.c"], base.extracted_dir) base.build_project() self.assertExistInDir(dirs, base.compiled_dir) diff --git a/tests/unit/test_plugins.py b/tests/unit/test_plugins.py index 85ce251..bfe07b4 100644 --- a/tests/unit/test_plugins.py +++ b/tests/unit/test_plugins.py @@ -13,8 +13,7 @@ from rpg.plugins.project_builder.cmake import CMakePlugin from rpg.plugins.project_builder.setuptools import SetuptoolsPlugin from rpg.plugins.project_builder.autotools import AutotoolsPlugin -from rpg.command import Command -from os.path import isfile, isdir +import re class MockSack: @@ -133,6 +132,11 @@ def test_files_to_pkgs(self): self.assertEqual({"python3-dnf"}, self.spec.BuildRequires) self.assertEqual(MockedLogging.called, 2) + def find_match(self, expected, files): + output = {i: [r.pattern for r in expected if r.match(i)] + for i in set(files)} + return output + def test_c(self): c_plug = CPlugin() c_plug.patched(self.test_project_dir, self.spec, self.sack) @@ -143,8 +147,6 @@ def test_c(self): "/usr/include/sys/cdefs.h", "/usr/include/bits/wordsize.h", "/usr/include/gnu/stubs.h", - "/usr/include/gnu/stubs-64.h", - "/usr/lib/gcc/x86_64-redhat-linux/5.1.1/include/stddef.h", "/usr/include/bits/stdlib-float.h", "/usr/include/stdio.h", "/usr/include/bits/types.h", @@ -152,12 +154,17 @@ def test_c(self): "/usr/include/libio.h", "/usr/include/_G_config.h", "/usr/include/wchar.h", - "/usr/lib/gcc/x86_64-redhat-linux/5.1.1/include/stdarg.h", "/usr/include/bits/stdio_lim.h", - "/usr/include/bits/sys_errlist.h" + "/usr/include/bits/sys_errlist.h", + '/usr/lib/gcc/[^/]*-redhat-linux/\d+.\d+.\d+./include/stddef.h', + '/usr/include/gnu/stubs-64.h', + '/usr/lib/gcc/[^/]*-redhat-linux/\d+.\d+.\d+./include/stdarg.h' ]) - self.assertEqual(self.spec.required_files, expected) - self.assertEqual(self.spec.build_required_files, expected) + ref_re = [re.compile(r) for r in expected] + output = self.find_match(ref_re, self.spec.required_files) + self.assertEqual(len(output), len(expected)) + output = self.find_match(ref_re, self.spec.build_required_files) + self.assertEqual(len(output), len(expected)) def test_cmake(self): cmakeplug = CMakePlugin()