Bug 1456415 - Test generated artifact definitions json. r=chutten
☠☠ backed out by 426038e8d757 ☠ ☠
authorJan-Erik Rediger <jrediger@mozilla.com>
Thu, 03 May 2018 08:29:00 +0300
changeset 473007 6b8dadbdc7d0cba584dc9d3665c7b4b8341bffa2
parent 473006 2bc9caa50c3b6ba52fa1749ea291894bf6cc6223
child 473008 67d5b919af152c3f2cb1c29e008cead6f47ecbbd
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten
bugs1456415
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1456415 - Test generated artifact definitions json. r=chutten MozReview-Commit-ID: IM9v7QS4Hiw
toolkit/components/telemetry/tests/python/python.ini
toolkit/components/telemetry/tests/python/test_gen_event_data_json.py
toolkit/components/telemetry/tests/python/test_gen_scalar_data_json.py
--- a/toolkit/components/telemetry/tests/python/python.ini
+++ b/toolkit/components/telemetry/tests/python/python.ini
@@ -1,2 +1,4 @@
+[test_gen_event_data_json.py]
+[test_gen_scalar_data_json.py]
 [test_histogramtools_non_strict.py]
-[test_histogramtools_strict.py]
\ No newline at end of file
+[test_histogramtools_strict.py]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/telemetry/tests/python/test_gen_event_data_json.py
@@ -0,0 +1,83 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import json
+import mozunit
+import sys
+import tempfile
+import unittest
+from StringIO import StringIO
+from os import path
+
+TELEMETRY_ROOT_PATH = path.abspath(path.join(path.dirname(__file__), path.pardir, path.pardir))
+sys.path.append(TELEMETRY_ROOT_PATH)
+import gen_event_data   # noqa: E402
+
+
+class TestEventDataJson(unittest.TestCase):
+
+    def test_JSON_definitions_generation(self):
+        EVENTS_YAML = """
+with.optout:
+  testme1:
+    objects: ["test1"]
+    bug_numbers: [1456415]
+    notification_emails: ["telemetry-client-dev@mozilla.org"]
+    record_in_processes: ["main"]
+    description: opt-out event
+    release_channel_collection: opt-out
+    expiry_version: never
+    extra_keys:
+      message: a message 1
+with.optin:
+  testme2:
+    objects: ["test2"]
+    bug_numbers: [1456415]
+    notification_emails: ["telemetry-client-dev@mozilla.org"]
+    record_in_processes: ["main"]
+    description: opt-in event
+    release_channel_collection: opt-in
+    expiry_version: never
+    extra_keys:
+      message: a message 2
+        """
+
+        EXPECTED_JSON = {
+            "with.optout": {
+                "testme1": {
+                    "objects": ["test1"],
+                    "expired": False,
+                    "methods": ["testme1"],
+                    "extra_keys": ["message"],
+                    "record_on_release": True
+                }
+            },
+            "with.optin": {
+                "testme2": {
+                    "objects": ["test2"],
+                    "expired": False,
+                    "methods": ["testme2"],
+                    "extra_keys": ["message"],
+                    "record_on_release": False
+                }
+            },
+        }
+
+        io = StringIO()
+        with tempfile.NamedTemporaryFile(suffix=".json", delete=True) as tmpfile:
+            # Write the event definition to the temporary file
+            tmpfile.write(EVENTS_YAML)
+            tmpfile.flush()
+
+            # Let the parser generate the artifact definitions
+            gen_event_data.generate_JSON_definitions(io, tmpfile.name)
+
+        event_definitions = json.loads(io.getvalue())
+
+        # Check that it generated the correct data
+        self.assertEqual(EXPECTED_JSON, event_definitions)
+
+
+if __name__ == '__main__':
+    mozunit.main()
new file mode 100644
--- /dev/null
+++ b/toolkit/components/telemetry/tests/python/test_gen_scalar_data_json.py
@@ -0,0 +1,78 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+import json
+import mozunit
+import sys
+import tempfile
+import unittest
+from StringIO import StringIO
+from os import path
+
+TELEMETRY_ROOT_PATH = path.abspath(path.join(path.dirname(__file__), path.pardir, path.pardir))
+sys.path.append(TELEMETRY_ROOT_PATH)
+import gen_scalar_data   # noqa: E402
+
+
+class TestScalarDataJson(unittest.TestCase):
+
+    def test_JSON_definitions_generation(self):
+        SCALARS_YAML = """
+newscalar:
+  withoptin:
+    bug_numbers:
+      - 1456415
+    description: opt-in scalar
+    expires: never
+    kind: uint
+    notification_emails: ["telemetry-client-dev@mozilla.org"]
+    record_in_processes: ["main"]
+    release_channel_collection: opt-in
+    keyed: false
+  withoptout:
+    bug_numbers:
+      - 1456415
+    description: opt-out scalar
+    expires: never
+    kind: string
+    notification_emails: ["telemetry-client-dev@mozilla.org"]
+    record_in_processes: ["main"]
+    release_channel_collection: opt-out
+    keyed: false
+        """
+
+        EXPECTED_JSON = {
+            "newscalar": {
+                "withoptout": {
+                    "kind": "nsITelemetry::SCALAR_TYPE_STRING",
+                    "expired": False,
+                    "record_on_release": True,
+                    "keyed": False
+                },
+                "withoptin": {
+                    "kind": "nsITelemetry::SCALAR_TYPE_COUNT",
+                    "expired": False,
+                    "record_on_release": False,
+                    "keyed": False
+                }
+            }
+        }
+
+        io = StringIO()
+        with tempfile.NamedTemporaryFile(suffix=".json", delete=True) as tmpfile:
+            # Write the scalar definition to the temporary file
+            tmpfile.write(SCALARS_YAML)
+            tmpfile.flush()
+
+            # Let the parser generate the artifact definitions
+            gen_scalar_data.generate_JSON_definitions(io, tmpfile.name)
+
+        scalar_definitions = json.loads(io.getvalue())
+
+        # Check that it generated the correct data
+        self.assertEqual(EXPECTED_JSON, scalar_definitions)
+
+
+if __name__ == '__main__':
+    mozunit.main()