[Fuego] [PATCH 2/8] Replace working_dir arg with resources_dir and output_dir

Guilherme Campos Camargo guicc at profusion.mobi
Wed May 2 14:20:46 UTC 2018


The generic working_dir argument has been replaced with two separate
arguments: resources_dir and output_dir, the first being the root for
the assets used by the test cases and the second being the location
where test temporary files will be stored (as diff and test images from
CheckScreenshot).

Signed-off-by: Guilherme Campos Camargo <guicc at profusion.mobi>
---
 .../Functional.fuego_release_test/README.md   | 23 ++++----
 .../fuego_test.sh                             |  5 +-
 .../Functional.fuego_release_test/test_run.py | 57 ++++++++++++-------
 3 files changed, 49 insertions(+), 36 deletions(-)

diff --git a/engine/tests/Functional.fuego_release_test/README.md b/engine/tests/Functional.fuego_release_test/README.md
index 01942ba..d9cb7b6 100644
--- a/engine/tests/Functional.fuego_release_test/README.md
+++ b/engine/tests/Functional.fuego_release_test/README.md
@@ -45,19 +45,20 @@ installation directory.
 See examples below:
 
 Test a `Fuego` version that's located at `~/fuego` and use the current
-directory as working-dir (location where test assets will be saved and looked
-for (screenshots, for example).
+directory as resources-dir - location where test assets will be looked for
+(screenshots, for example) - and as output dir (where temporary files resulted
+from the test will be stored).
 ```
-$ ./test_run.py -w . ~/fuego
+$ ./test_run.py -d . -o . ~/fuego
 ```
 
 Same as above, but do not remove (neither stops) the `fuego-container` after
-the execution of the tests. You'll be able to access the inner Jenkins (Fuego
-that runs inside Fuego) through `${fuego_container_ip}:8080/fuego`. The
-`fuego_container ip` is dynamically set by docker, and is displayed in the
-first lines of the output of the script.
+the execution of the tests, and use `/tmp` as output dir (default). You'll be
+able to access the inner Jenkins (Fuego that runs inside Fuego) through
+`${fuego_container_ip}:8080/fuego`. The `fuego_container ip` is dynamically set
+by docker, and is displayed in the first lines of the output of the script.
 ```
-$ ./test_run.py --no-rm-container -p 8080 -w . ~/fuego
+$ ./test_run.py --no-rm-container -p 8080 -d . ~/fuego
 ```
 
 Output example with the IP of the container:
@@ -133,9 +134,11 @@ CheckScreenshot(By.CLASS_NAME, 'page_generated',
 Take a full screenshot and compare with the image in
 `screenshots/full_screenshot.png` using the ignore-mask
 `screenshots/full_screenshot_mask.png`. The viewport resolution can be set on
-the SeleniumContext constructor.
+the SeleniumContext constructor. Store the temporary files
+(`full_screenshot.diff.png` and `full_screenshot.test.png`) in '~/tmp'.
 ```
 CheckScreenshot(ref_img='screenshots/full_screenshot.png',
+                output_dir='~/tmp',
                 rm_images_on_success=False,
                 mask_img='screenshots/full_screenshot_mask.png',
                 threshold=0.01),
@@ -144,7 +147,7 @@ CheckScreenshot(ref_img='screenshots/full_screenshot.png',
 Note that the test by default does not store the currently captured screenshot
 and the diff image in case of success. If you'd like to see those images, set
 `rm_images_on_success` to False, and those images will be available in the
-working directory (script's -w argument).
+output directory (script's -o argument - defaults to `/tmp`).
 
 ## Helpers
 
diff --git a/engine/tests/Functional.fuego_release_test/fuego_test.sh b/engine/tests/Functional.fuego_release_test/fuego_test.sh
index e87d6a4..05b4b7b 100755
--- a/engine/tests/Functional.fuego_release_test/fuego_test.sh
+++ b/engine/tests/Functional.fuego_release_test/fuego_test.sh
@@ -18,13 +18,10 @@ function test_build {
     echo "Cloning fuego-core from ${fuego_core_repo}:${fuego_core_branch}"
     git clone --depth 1 --single-branch --branch "${fuego_core_branch}" \
         "${fuego_core_repo}" "${fuego_release_dir}/fuego-core"
-
-    echo "Copying assets from ${TEST_HOME} to the buildzone."
-    cp -r "${TEST_HOME}/screenshots" .
 }
 
 function test_run {
-    sudo -n "${TEST_HOME}/test_run.py" "${fuego_release_dir}/fuego" -w .
+    sudo -n "${TEST_HOME}/test_run.py" "${fuego_release_dir}/fuego" -d ${TEST_HOME} -o .
     if [ "${?}" = 0 ]; then
         report "echo ok 1 fuego release test"
     else
diff --git a/engine/tests/Functional.fuego_release_test/test_run.py b/engine/tests/Functional.fuego_release_test/test_run.py
index 044c0d3..02c5f07 100755
--- a/engine/tests/Functional.fuego_release_test/test_run.py
+++ b/engine/tests/Functional.fuego_release_test/test_run.py
@@ -160,11 +160,12 @@ class CheckText(SeleniumCommand):
 
 
 class CheckScreenshot(SeleniumCommand):
-    def __init__(self, ref_img, locator=None, pattern=None, mask_img=None,
-                 diff_img=None, expected_result=True, threshold=0.0,
-                 rm_images_on_success=True):
-        def add_suffix(filename, suffix):
-            head, sep, tail = ref_img.rpartition('.')
+    def __init__(self, ref_img, output_dir='/tmp', locator=None,
+                 pattern=None, mask_img=None, expected_result=True,
+                 threshold=0.0, rm_images_on_success=True):
+        def basename_with_suffix(filename, suffix):
+            basename = os.path.basename(filename)
+            head, sep, tail = basename.rpartition('.')
             if sep:
                 return head + sep + suffix + '.' + tail
 
@@ -178,12 +179,11 @@ class CheckScreenshot(SeleniumCommand):
         self.threshold = threshold
         self.rm_images_on_success = rm_images_on_success
 
-        if diff_img is None:
-            self.diff_img_path = add_suffix(ref_img, 'diff')
-        else:
-            self.diff_img_path = diff_img
-
-        self.test_img_path = add_suffix(ref_img, 'test')
+        # Output files
+        self.diff_img_path = os.path.join(
+            output_dir, basename_with_suffix(ref_img, 'diff'))
+        self.test_img_path = os.path.join(
+            output_dir, basename_with_suffix(ref_img, 'test'))
 
     def compare_cmd_magick_v7(test_img, ref_img, mask_img, diff_img):
         """
@@ -687,6 +687,7 @@ def main():
     DEFAULT_INSTALL_SCRIPT = 'install.sh'
     DEFAULT_START_SCRIPT = 'fuego-host-scripts/docker-start-container.sh'
     DEFAULT_JENKINS_PORT = 8080
+    DEFAULT_OUTPUT_DIR = '/tmp'
 
     @atexit.register
     def cleanup():
@@ -698,12 +699,17 @@ def main():
     def get_abs_working_dirs():
         abs_install_dir = os.path.abspath(args.install_dir)
 
-        if args.working_dir:
-            abs_working_dir = os.path.abspath(args.working_dir)
+        if args.resources_dir:
+            abs_resources_dir = os.path.abspath(args.resources_dir)
+        else:
+            abs_resources_dir = abs_install_dir
+
+        if args.output_dir:
+            abs_output_dir = os.path.abspath(args.output_dir)
         else:
-            abs_working_dir = abs_install_dir
+            abs_output_dir = abs_output_dir
 
-        return abs_install_dir, abs_working_dir
+        return abs_install_dir, abs_resources_dir, abs_output_dir
 
     def execute_tests(timeout):
         LOGGER.info("Starting tests...")
@@ -733,10 +739,14 @@ def main():
     parser = argparse.ArgumentParser()
     parser.add_argument('install_dir', help="The directory where the install "
                         "script resides.", type=str)
-    parser.add_argument('-w', '--working_dir', help="The working directory. "
-                        "Location of the test assets and where test results "
-                        "will be stored. Defaults to install_dir.",
+    parser.add_argument('-d', '--resources_dir', help="Root directory for " +
+                        " test assets, as reference screenshots and other "
+                        " resources. Defaults to install_dir.",
                         default=None, type=str)
+    parser.add_argument('-o', '--output_dir', help="Location in which " +
+                        "temporary files generated by test cases will be " +
+                        "stored. Defaults to '%s'." % DEFAULT_OUTPUT_DIR,
+                        default=DEFAULT_OUTPUT_DIR, type=str)
     parser.add_argument('-s', '--install-script',
                         help="The script that will be used to install the " +
                         "docker image. Defaults to '%s'" %
@@ -770,7 +780,8 @@ def main():
                         default=True, action='store_false')
     args = parser.parse_args()
 
-    args.install_dir, args.working_dir = get_abs_working_dirs()
+    args.install_dir, args.resources_dir, args.output_dir = \
+        get_abs_working_dirs()
 
     LOGGER.debug("Changing working dir to '%s'", args.install_dir)
     os.chdir(args.install_dir)
@@ -794,9 +805,9 @@ def main():
         LOGGER.error("Selenium session failed to start")
         return 1
 
-    if os.getcwd != args.working_dir:
-        LOGGER.debug("Changing working dir to '%s'", args.working_dir)
-        os.chdir(args.working_dir)
+    if os.getcwd != args.resources_dir:
+        LOGGER.debug("Changing working dir to '%s'", args.resources_dir)
+        os.chdir(args.resources_dir)
 
     COMMANDS_TO_TEST = [
         # Set Selenium Browser root
@@ -842,12 +853,14 @@ def main():
 
         # Compare screenshot of an element of Jenkins UI
         CheckScreenshot(ref_img='screenshots/side-panel-tasks.png',
+                        output_dir=args.output_dir,
                         locator=By.ID, pattern='tasks',
                         rm_images_on_success=True,
                         threshold=0.1),
 
         # Compare screenshot of an element of Jenkins UI ignoring an area
         CheckScreenshot(ref_img='screenshots/footer.png',
+                        output_dir=args.output_dir,
                         locator=By.CLASS_NAME, pattern='col-md-18',
                         rm_images_on_success=False,
                         mask_img='screenshots/footer_mask.png',
-- 
2.17.0



More information about the Fuego mailing list