Skip to content

Commit

Permalink
Less hard-coded architecture in tests (fix #296)
Browse files Browse the repository at this point in the history
  • Loading branch information
regeciovad committed Oct 2, 2015
1 parent 6eb4001 commit ba20871
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
22 changes: 14 additions & 8 deletions tests/unit/test_functional.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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',
Expand All @@ -32,22 +37,23 @@ 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",
"hello"
]
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)
Expand Down
23 changes: 15 additions & 8 deletions tests/unit/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -143,21 +147,24 @@ 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",
"/usr/include/bits/typesizes.h",
"/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()
Expand Down

0 comments on commit ba20871

Please sign in to comment.