← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~nskaggs/help-app/functional-test-template-improvements into lp:help-app

 

Nicholas Skaggs has proposed merging lp:~nskaggs/help-app/functional-test-template-improvements into lp:help-app.

Commit message:
Improve functional test templates; incorporate with build, fix layout

Requested reviews:
  Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot): continuous-integration
  Ubuntu Help app developers (help-app-dev)
Related bugs:
  Bug #1461477 in Ubuntu Help App: "Make sure functional tests have the relevant build run beforehand"
  https://bugs.launchpad.net/help-app/+bug/1461477
  Bug #1461478 in Ubuntu Help App: "Make functional tests part of the build process"
  https://bugs.launchpad.net/help-app/+bug/1461478

For more details, see:
https://code.launchpad.net/~nskaggs/help-app/functional-test-template-improvements/+merge/261626

Improve functional test templates; incorporate with build, fix layout
-- 
Your team Ubuntu Help app developers is requested to review the proposed merge of lp:~nskaggs/help-app/functional-test-template-improvements into lp:help-app.
=== modified file 'HACKING'
--- HACKING	2015-05-28 19:34:12 +0000
+++ HACKING	2015-06-10 14:17:00 +0000
@@ -171,7 +171,7 @@
     sudo apt-get install oxideqt-chromedriver
     sudo apt-add-repository ppa:canonical-platform-qa/selenium
     sudo apt-get update
-    sudo apt-get install python3-selenium
+    sudo apt-get install python3-selenium xvfb
 
 Run the tests:
 

=== modified file 'Makefile'
--- Makefile	2015-05-13 14:54:51 +0000
+++ Makefile	2015-06-10 14:17:00 +0000
@@ -43,7 +43,7 @@
 	@echo '                                                                       '
 	@echo 'Usage:                                                                 '
 	@echo '   make web                         (re)generate the (online) web site '
-	@echo '   make app                         (re)generate the (offline) content ' 
+	@echo '   make app                         (re)generate the (offline) content '
 	@echo '                                    for the phone app ("html" is an    '
 	@echo '                                    alias)                             '
 	@echo '   make click                       generate click for the phone app   '
@@ -56,8 +56,9 @@
 	@echo '                                                                       '
 
 check:
-	cd $(INTERNALS_DIR); ./run-tests
-	cd $(INTERNALS_DIR); ./run-other-tests
+	cd $(INTERNALS_DIR); ./run-code-tests
+	cd $(INTERNALS_DIR); ./run-unit-tests
+	cd $(INTERNALS_DIR); ./run-functional-tests
 
 translations:
 	cd $(INTERNALS_DIR); ./generate-translations

=== renamed file 'internals/run-other-tests' => 'internals/run-code-tests'
=== added file 'internals/run-functional-tests'
--- internals/run-functional-tests	1970-01-01 00:00:00 +0000
+++ internals/run-functional-tests	2015-06-10 14:17:00 +0000
@@ -0,0 +1,4 @@
+#!/bin/sh -e
+
+cd tests/functional
+autopilot3-sandbox-run help_app
\ No newline at end of file

=== renamed file 'internals/run-tests' => 'internals/run-unit-tests'
--- internals/run-tests	2015-03-19 13:22:42 +0000
+++ internals/run-unit-tests	2015-06-10 14:17:00 +0000
@@ -4,9 +4,9 @@
 import sys
 import unittest
 
-from pelicanconf import TOP_LEVEL_DIR
+from pelicanconf import INTERNALS_DIR
 
-test_directory = os.path.join(TOP_LEVEL_DIR, 'internals/tests')
+test_directory = os.path.join(INTERNALS_DIR, 'tests/unit')
 test_filename = 'test_*'
 if len(sys.argv) > 1:
     test_filename = sys.argv[1]

=== added file 'internals/tests/__init__.py'
=== added file 'internals/tests/build_utils.py'
--- internals/tests/build_utils.py	1970-01-01 00:00:00 +0000
+++ internals/tests/build_utils.py	2015-06-10 14:17:00 +0000
@@ -0,0 +1,49 @@
+import os
+import shutil
+import subprocess
+import tempfile
+
+import sys
+sys.path.insert(0, '../..')
+
+from pelicanconf import TOP_LEVEL_DIR
+import pelicanconf
+
+
+def clean_tempdir(tempdir):
+    if os.path.exists(tempdir):
+        shutil.rmtree(tempdir)
+
+
+class BuildRunner():
+    def __init__(self, build):
+        self.tempdir = tempfile.mkdtemp()
+        self.env = {}
+        self.build = build
+        self.html_files = []
+        self.rc = None
+        if self.build == 'app':
+            self.env = {'APP_DIR': self.tempdir}
+        if self.build == 'web':
+            self.env = {'OUTPUTDIR_WEB': self.tempdir}
+        self.pwd = os.getcwd()
+        top_level_dir = os.path.join(os.path.dirname(pelicanconf.__file__),
+                                     TOP_LEVEL_DIR)
+        os.chdir(top_level_dir)
+        self.run_build()
+        self.find_html_files()
+        self.html_path = os.path.commonprefix(self.html_files)
+
+    def run_build(self):
+        self.rc = subprocess.call(['make', '-es', self.build], env=self.env)
+        os.chdir(self.pwd)
+
+    def find_html_files(self):
+        for dirpath, dirnames, filenames in os.walk(self.tempdir):
+            self.html_files.extend([os.path.join(dirpath, fn)
+                                    for fn in filenames
+                                    if fn.endswith('.html')])
+
+    def __del__(self):
+        os.chdir(self.pwd)
+        clean_tempdir(self.tempdir)

=== added file 'internals/tests/functional/__init__.py'
=== modified file 'internals/tests/functional/help_app/tests/__init__.py'
--- internals/tests/functional/help_app/tests/__init__.py	2015-05-28 20:32:09 +0000
+++ internals/tests/functional/help_app/tests/__init__.py	2015-06-10 14:17:00 +0000
@@ -1,7 +1,6 @@
 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
 """ Autopilot tests """
-
 import os
 import subprocess
 
@@ -16,6 +15,11 @@
 from autopilot import platform
 from autopilot.testcase import AutopilotTestCase
 
+import sys
+sys.path.insert(0, '..')
+
+from build_utils import BuildRunner
+
 CURRENT_ARCHITECTURE = subprocess.check_output(
     ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip()
 CHROMEDRIVER_EXEC_PATH = \
@@ -69,7 +73,8 @@
 
     def setUp(self):
         super(HelpAppTest, self).setUp()
-        self.app = HelpApp(self.launch_app('../../../../../build/app/www'))
+        self.build_runner = BuildRunner('web')
+        self.app = HelpApp(self.launch_app(self.build_runner.html_path))
         self.driver = self.launch_webdriver()
 
 
@@ -79,5 +84,6 @@
 
     def setUp(self):
         super(HelpWebTest, self).setUp()
-        self.app = HelpApp(self.launch_app('../../../../../build/web/www'))
+        self.build_runner = BuildRunner('app')
+        self.app = HelpApp(self.launch_app(self.build_runner.html_path))
         self.driver = self.launch_webdriver()

=== renamed file 'internals/tests/functional/help_app/tests/test_app_launch.py' => 'internals/tests/functional/help_app/tests/test_app.py'
--- internals/tests/functional/help_app/tests/test_app_launch.py	2015-05-28 20:32:09 +0000
+++ internals/tests/functional/help_app/tests/test_app.py	2015-06-10 14:17:00 +0000
@@ -1,16 +1,13 @@
 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
-from help_app.tests import HelpAppTest, HelpWebTest
+from help_app.tests import HelpAppTest
 from testtools.matchers import NotEquals
 
 
-class LaunchTestApp(HelpAppTest):
-
-    def test_basic_launch(self):
-        self.assertThat(self.app, NotEquals(None))
-
-
-class LaunchTestWeb(HelpWebTest):
+class TestApp(HelpAppTest):
+    def setUp(self):
+        super(TestApp, self).setUp()
+        self.assertEquals(self.app.build_runner.rc, 0)
 
     def test_basic_launch(self):
         self.assertThat(self.app, NotEquals(None))

=== added file 'internals/tests/functional/help_app/tests/test_web.py'
--- internals/tests/functional/help_app/tests/test_web.py	1970-01-01 00:00:00 +0000
+++ internals/tests/functional/help_app/tests/test_web.py	2015-06-10 14:17:00 +0000
@@ -0,0 +1,13 @@
+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
+
+from help_app.tests import HelpWebTest
+from testtools.matchers import NotEquals
+
+
+class TestWeb(HelpWebTest):
+    def setUp(self):
+        super(TestWeb, self).setUp()
+        self.assertEquals(self.app.build_runner.rc, 0)
+
+    def test_basic_launch(self):
+        self.assertThat(self.app, NotEquals(None))

=== added directory 'internals/tests/unit'
=== renamed file 'internals/tests/test_files.py' => 'internals/tests/unit/test_files.py'
=== renamed file 'internals/tests/test_links.py' => 'internals/tests/unit/test_links.py'
--- internals/tests/test_links.py	2015-05-13 12:32:34 +0000
+++ internals/tests/unit/test_links.py	2015-06-10 14:17:00 +0000
@@ -1,51 +1,21 @@
 import codecs
 from html.parser import HTMLParser
 import os
-import shutil
-import subprocess
 import tempfile
 from unittest import TestCase
 
 from translations.utils import (
     link_is_anchor,
     link_is_local,
-    use_top_level_dir,
-)
-
-
-def clean_tempdir(tempdir):
-    if os.path.exists(tempdir):
-        shutil.rmtree(tempdir)
-
-
-class BuildRunner():
-    def __init__(self, build):
-        self.tempdir = tempfile.mkdtemp()
-        self.env = {}
-        self.build = build
-        self.html_files = []
-        self.rc = None
-        if self.build == 'app':
-            self.env = {'APP_DIR': self.tempdir}
-        if self.build == 'web':
-            self.env = {'OUTPUTDIR_WEB': self.tempdir}
-        self.pwd = use_top_level_dir()
-        self.run_build()
-        self.find_html_files()
-
-    def run_build(self):
-        self.rc = subprocess.call(['make', '-es', self.build], env=self.env)
-        os.chdir(self.pwd)
-
-    def find_html_files(self):
-        for dirpath, dirnames, filenames in os.walk(self.tempdir):
-            self.html_files.extend([os.path.join(dirpath, fn)
-                                    for fn in filenames
-                                    if fn.endswith('.html')])
-
-    def __del__(self):
-        os.chdir(self.pwd)
-        clean_tempdir(self.tempdir)
+)
+
+import sys
+sys.path.insert(0, '..')
+
+from build_utils import (
+    BuildRunner,
+    clean_tempdir,
+)
 
 
 class MyHTMLParser(HTMLParser):

=== renamed file 'internals/tests/test_markdown.py' => 'internals/tests/unit/test_markdown.py'
=== renamed file 'internals/tests/test_translations.py' => 'internals/tests/unit/test_translations.py'