From 0da1d3a419d4301fecb7a788ae0a6f8b52d18436 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Thu, 22 Nov 2018 11:05:33 +1100 Subject: [PATCH] Fix unit tests for elements It looks like we dropped running these probably when we moved the elements around. For testtools to find the test scripts we need to add the __init__.py files to make the directories look like modules. Also prevent copying any .pyc or cache files in as hooks. Change-Id: I66d5f6ee62cc4d9ee14c64e819b4db57d035d09f --- diskimage_builder/elements/__init__.py | 0 .../elements/cache-url/tests/test_cache_url.py | 12 ++++++------ diskimage_builder/elements/svc-map/__init__.py | 0 diskimage_builder/lib/common-functions | 8 ++++++-- 4 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 diskimage_builder/elements/__init__.py create mode 100644 diskimage_builder/elements/svc-map/__init__.py diff --git a/diskimage_builder/elements/__init__.py b/diskimage_builder/elements/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/diskimage_builder/elements/cache-url/tests/test_cache_url.py b/diskimage_builder/elements/cache-url/tests/test_cache_url.py index 8f389e06..e3ac0522 100644 --- a/diskimage_builder/elements/cache-url/tests/test_cache_url.py +++ b/diskimage_builder/elements/cache-url/tests/test_cache_url.py @@ -27,15 +27,15 @@ class TestCacheUrl(base.ScriptTestBase): source = 'http://fake/url' # Write fake data to the target file and return success self._stub_script('curl', 'echo "test" > ${3:7:100}\necho 200') - self._run_command(['elements/cache-url/bin/cache-url', - source, - target]) + self._run_command( + ['diskimage_builder/elements/cache-url/bin/cache-url', + source, target]) self.assertTrue(os.path.exists(target)) modification_time = os.path.getmtime(target) # Make sure that the timestamp would change if the file does time.sleep(1) self._stub_script('curl', 'echo "304"') - self._run_command(['elements/cache-url/bin/cache-url', - source, - target]) + self._run_command( + ['diskimage_builder/elements/cache-url/bin/cache-url', + source, target]) self.assertEqual(modification_time, os.path.getmtime(target)) diff --git a/diskimage_builder/elements/svc-map/__init__.py b/diskimage_builder/elements/svc-map/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/diskimage_builder/lib/common-functions b/diskimage_builder/lib/common-functions index 48b90897..09b81795 100644 --- a/diskimage_builder/lib/common-functions +++ b/diskimage_builder/lib/common-functions @@ -111,11 +111,15 @@ function generate_hooks () { for dir in $(find $element_dir \ -follow -mindepth 1 -maxdepth 1 \ - -type d -not -name tests); do + -type d \ + -not -name tests \ + -not -name __pycache__); do copy_hooks_not_overwrite $dir done for file in $(find $element_dir \ - -follow -maxdepth 1 -type f); do + -follow -maxdepth 1 \ + -type f \ + -not -name '*.pyc'); do cp -t $TMP_HOOKS_PATH -a $file done done