mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1456415 - Test generated artifact definitions json. r=chutten
MozReview-Commit-ID: IM9v7QS4Hiw --HG-- extra : histedit_source : 21739f42e1bb480f7566e1107c1da7f6a0f4993e
This commit is contained in:
parent
686a5dd037
commit
9af9052231
@ -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]
|
||||
[test_histogramtools_strict.py]
|
||||
|
@ -0,0 +1,88 @@
|
||||
# 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 os
|
||||
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()
|
||||
try:
|
||||
tmpfile = tempfile.NamedTemporaryFile(suffix=".json", delete=False)
|
||||
# Write the event definition to the temporary file
|
||||
tmpfile.write(EVENTS_YAML)
|
||||
tmpfile.close()
|
||||
|
||||
# Let the parser generate the artifact definitions
|
||||
gen_event_data.generate_JSON_definitions(io, tmpfile.name)
|
||||
finally:
|
||||
if tmpfile:
|
||||
os.unlink(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()
|
@ -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 os
|
||||
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()
|
||||
try:
|
||||
tmpfile = tempfile.NamedTemporaryFile(suffix=".json", delete=False)
|
||||
# Write the scalar definition to the temporary file
|
||||
tmpfile.write(SCALARS_YAML)
|
||||
tmpfile.close()
|
||||
|
||||
# Let the parser generate the artifact definitions
|
||||
gen_scalar_data.generate_JSON_definitions(io, tmpfile.name)
|
||||
finally:
|
||||
if tmpfile:
|
||||
os.unlink(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()
|
Loading…
Reference in New Issue
Block a user