Filippo Giunchedi has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/379830 )

Change subject: webperf: Add navtiming tests to puppet.git:/tox.ini
......................................................................


webperf: Add navtiming tests to puppet.git:/tox.ini

Change-Id: I2fdb8e0b978b2406ebc386c716c6c4321aeff0d8
---
M Rakefile
M modules/webperf/files/navtiming.py
A modules/webperf/files/navtiming_test.py
M tox.ini
4 files changed, 64 insertions(+), 38 deletions(-)

Approvals:
  jenkins-bot: Verified
  Gilles: Looks good to me, but someone else must approve
  Filippo Giunchedi: Looks good to me, approved



diff --git a/Rakefile b/Rakefile
index bcd8c22..fc461a4 100644
--- a/Rakefile
+++ b/Rakefile
@@ -288,6 +288,15 @@
           end
           tasks << 'tox:admin'
         end
+        webperf_files = filter_files_by("modules/webperf/files/*.*")
+        unless webperf_files.empty?
+          desc 'Run tox for webperf'
+          task :webperf do
+            res = system("tox -e webperf")
+            raise 'Tests for webperf failed!' if !res
+          end
+          tasks << 'tox:webperf'
+        end
         tox_files = filter_files_by("*.py")
         unless tox_files.empty?
           desc 'Run flake8 on python files via tox'
diff --git a/modules/webperf/files/navtiming.py 
b/modules/webperf/files/navtiming.py
index d288852..6b75277 100755
--- a/modules/webperf/files/navtiming.py
+++ b/modules/webperf/files/navtiming.py
@@ -10,10 +10,6 @@
 import logging
 import re
 import socket
-import unittest
-import yaml
-
-from kafka import KafkaConsumer
 
 handlers = {}
 
@@ -402,6 +398,8 @@
 
 
 if __name__ == '__main__':
+    from kafka import KafkaConsumer
+
     ap = argparse.ArgumentParser(description='NavigationTiming subscriber')
     ap.add_argument('--brokers', required=True,
                     help='Comma-separated list of kafka brokers')
@@ -443,36 +441,3 @@
         raise RuntimeError('No messages received in %d seconds.' % 
kafka_consumer_timeout_seconds)
     finally:
         consumer.close()
-
-
-# ##### Tests ######
-# To run:
-#   python -m unittest -v navtiming
-#
-class TestNavTiming(unittest.TestCase):
-    def test_parse_ua(self):
-        with open('navtiming_ua_data.yaml') as file:
-            data = yaml.safe_load(file)
-            for case in data:
-                expect = tuple(case.split('.'))
-                uas = data.get(case)
-                for ua in uas:
-                    self.assertEqual(
-                        parse_ua(ua),
-                        expect
-                    )
-
-    def test_handlers(self):
-        with open('navtiming_fixture.yaml') as fixture_file:
-            fixture = yaml.safe_load(fixture_file)
-            actual = []
-            for meta in fixture:
-                f = handlers.get(meta['schema'])
-                assert f is not None
-                for stat in f(meta):
-                    actual.append(stat)
-            with open('navtiming_expected.txt') as expected_file:
-                self.assertItemsEqual(
-                    actual,
-                    expected_file.read().splitlines()
-                )
diff --git a/modules/webperf/files/navtiming_test.py 
b/modules/webperf/files/navtiming_test.py
new file mode 100644
index 0000000..c31c2cc
--- /dev/null
+++ b/modules/webperf/files/navtiming_test.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+
+import unittest
+import yaml
+import os
+
+import navtiming
+
+
+# ##### Tests ######
+# To run:
+#   python -m unittest -v navtiming_test
+# Or:
+#   python navtiming_test.py
+#
+class TestNavTiming(unittest.TestCase):
+    def test_parse_ua(self):
+        data_path = os.path.join(os.path.dirname(__file__), 
'navtiming_ua_data.yaml')
+        with open(data_path) as data_file:
+            data = yaml.safe_load(data_file)
+            for case in data:
+                expect = tuple(case.split('.'))
+                uas = data.get(case)
+                for ua in uas:
+                    self.assertEqual(
+                        navtiming.parse_ua(ua),
+                        expect
+                    )
+
+    def test_handlers(self):
+        fixture_path = os.path.join(os.path.dirname(__file__), 
'navtiming_fixture.yaml')
+        expected_path = os.path.join(os.path.dirname(__file__), 
'navtiming_expected.txt')
+        with open(fixture_path) as fixture_file:
+            fixture = yaml.safe_load(fixture_file)
+            actual = []
+            for meta in fixture:
+                f = navtiming.handlers.get(meta['schema'])
+                assert f is not None
+                for stat in f(meta):
+                    actual.append(stat)
+            with open(expected_path) as expected_file:
+                self.assertItemsEqual(
+                    actual,
+                    expected_file.read().splitlines()
+                )
+
+
+if __name__ == '__main__':
+    unittest.main(verbosity=2)
diff --git a/tox.ini b/tox.ini
index b32a194..cdccbc9 100644
--- a/tox.ini
+++ b/tox.ini
@@ -2,7 +2,7 @@
 minversion = 1.6
 skipsdist = True
 
-envlist = commit-message, py27, pep8
+envlist = webperf, commit-message, py27, pep8
 
 [flake8]
 max-line-length = 100
@@ -31,6 +31,9 @@
     -rmodules/admin/data/requirements.txt
 commands = nosetests modules/admin/data 
modules/mediawiki/files/apache/sites/redirects
 
+[testenv:webperf]
+commands = nosetests modules/webperf/files
+
 [testenv:commit-message]
 deps = commit-message-validator
 commands = commit-message-validator

-- 
To view, visit https://gerrit.wikimedia.org/r/379830
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2fdb8e0b978b2406ebc386c716c6c4321aeff0d8
Gerrit-PatchSet: 11
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Filippo Giunchedi <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Volans <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to