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
This commit is contained in:
Ian Wienand 2018-11-22 11:05:33 +11:00
parent bc6f9f64d8
commit 0da1d3a419
4 changed files with 12 additions and 8 deletions

View File

View File

@ -27,15 +27,15 @@ class TestCacheUrl(base.ScriptTestBase):
source = 'http://fake/url' source = 'http://fake/url'
# Write fake data to the target file and return success # Write fake data to the target file and return success
self._stub_script('curl', 'echo "test" > ${3:7:100}\necho 200') self._stub_script('curl', 'echo "test" > ${3:7:100}\necho 200')
self._run_command(['elements/cache-url/bin/cache-url', self._run_command(
source, ['diskimage_builder/elements/cache-url/bin/cache-url',
target]) source, target])
self.assertTrue(os.path.exists(target)) self.assertTrue(os.path.exists(target))
modification_time = os.path.getmtime(target) modification_time = os.path.getmtime(target)
# Make sure that the timestamp would change if the file does # Make sure that the timestamp would change if the file does
time.sleep(1) time.sleep(1)
self._stub_script('curl', 'echo "304"') self._stub_script('curl', 'echo "304"')
self._run_command(['elements/cache-url/bin/cache-url', self._run_command(
source, ['diskimage_builder/elements/cache-url/bin/cache-url',
target]) source, target])
self.assertEqual(modification_time, os.path.getmtime(target)) self.assertEqual(modification_time, os.path.getmtime(target))

View File

@ -111,11 +111,15 @@ function generate_hooks () {
for dir in $(find $element_dir \ for dir in $(find $element_dir \
-follow -mindepth 1 -maxdepth 1 \ -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 copy_hooks_not_overwrite $dir
done done
for file in $(find $element_dir \ 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 cp -t $TMP_HOOKS_PATH -a $file
done done
done done