Skip to content

Commit

Permalink
Refactor parsing descriptions from probes and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scholtzan committed Mar 3, 2020
1 parent f9d85a2 commit 37f14d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 37 deletions.
13 changes: 5 additions & 8 deletions mozilla_schema_generator/probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ class Probe(object):
name_key = "name"
history_key = "history"

def __init__(self, identifier: str, definition: dict, description: str):
def __init__(self, identifier: str, definition: dict):
self.id = identifier
self.type = definition[self.type_key]
self.name = definition[self.name_key]
self.description = description

def get_type(self) -> str:
return self.type
Expand Down Expand Up @@ -77,11 +76,11 @@ class MainProbe(Probe):
"all": child_processes | parent_processes,
}

def __init__(self, identifier: str, definition: dict, description: str = None):
def __init__(self, identifier: str, definition: dict):
self._set_dates(definition[self.first_added_key])
self._set_definition(definition)
self._set_description(self.definition)
super().__init__(identifier, definition, self.description)
super().__init__(identifier, definition)

def _set_definition(self, full_defn: dict):
history = [d for arr in full_defn[self.history_key].values() for d in arr]
Expand Down Expand Up @@ -144,13 +143,11 @@ class GleanProbe(Probe):
all_pings_keywords = ("all-pings", "all_pings")
first_added_key = "first_added"

def __init__(
self, identifier: str, definition: dict, *, pings: List[str] = None, description: str = None
):
def __init__(self, identifier: str, definition: dict, *, pings: List[str] = None):
self._set_dates(definition)
self._set_definition(definition)
self._set_description(definition)
super().__init__(identifier, definition, description)
super().__init__(identifier, definition)

defn_pings = set(
[p for d in definition[self.history_key] for p in d.get("send_in_pings", ["metrics"])]
Expand Down
29 changes: 0 additions & 29 deletions tests/test_probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,32 +247,6 @@ def main_probe_all_childs_and_main_defn():

@pytest.fixture
def main_probe_all_defn():
return {
"first_added": {
"release": "2017-09-19 01:26:22"
},
"history": {
"nightly": [
{
"details": {
"keyed": False,
"kind": "string",
"record_in_processes": ["all"]
},
"versions": {
"first": "67",
"last": "70"
}
}
],
},
"name": "a11y.instantiators",
"type": "scalar"
}


@pytest.fixture
def main_probe_description():
return {
"first_added": {
"release": "2017-09-19 01:26:22"
Expand Down Expand Up @@ -336,7 +310,4 @@ def test_main_probe_all(self, main_probe_all_defn):
probe = MainProbe("scalar/test_probe", main_probe_all_defn)
assert probe.definition['details']['record_in_processes'] == \
{"main", "content", "gpu", "extension", "dynamic", "socket"}

def test_main_probe_description(self, main_probe_description):
probe = MainProbe("scalar/test_probe", main_probe_description)
assert probe.description == "Test description"

0 comments on commit 37f14d8

Please sign in to comment.