Skip to content
This repository has been archived by the owner on Feb 18, 2019. It is now read-only.

Commit

Permalink
issues 15 and 16
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Hammel committed Aug 3, 2012
1 parent f7f59aa commit 2a639e8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
46 changes: 40 additions & 6 deletions dzclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,44 @@ class DatazillaResult(object):
Currently, the results are a dictionary of
{"testsuite":{"testname":[values], ...}}
Each suite may also have an options dictionary
"""
def __init__(self, results=None):
def __init__(self, results=None, results_aux=None, options=None):
self.results = results or {}
self.results_aux = results_aux or {}
self.options = options or {}

def add_testsuite(self, suite_name, results=None):
def add_testsuite(self, suite_name, results=None, results_aux=None, options=None):
"""Add a testsuite of {"testname":[values],...} to the results."""
self.results[suite_name] = results or {}
self.results_aux[suite_name] = results_aux or {}
self.options[suite_name] = options or {}

def add_test_results(self, suite_name, test_name, values):
"""Add a list of result values to the given testsuite/testname pair."""
suite = self.results.setdefault(suite_name, {})
suite.setdefault(test_name, []).extend(values)

def add_auxiliary_results(self, suite_name, results_name, values):
"""Add auxiliary results for a test suite"""
suite = self.results_aux.setdefault(suite_name, {})
suite.setdefault(results_name, []).extend(values)

def join_results(self, results):
"""Add a dictionary of {"suite":{"name":[values], ...}} to results."""
for suite_name, tests in results.items():
"""merge an existing DatazillaResult instance with this one"""

for suite_name, tests in results.results.items():
suite = self.results.setdefault(suite_name, {})
for test_name, values in tests.items():
suite.setdefault(test_name, []).extend(values)
for suite_name, results_aux in results.results_aux.items():
suite = self.results_aux.setdefault(suite_name, {})
for results_name, values in results_aux.items():
suite.setdefault(results_name, []).extend(values)
for suite_name, options in results.options.items():
self.options.setdefault(suite_name, {}).update(options)


class DatazillaResultsCollection(object):
"""DatazillaResultsCollection manages test information and serialization to JSON"""
Expand All @@ -49,7 +68,16 @@ def __init__(self, machine_name="", os="", os_version="", platform="",
build_name="", version="", revision="", branch="", id="",
test_date=None):
"""
- id : the build ID for which the dzresults are for; a unique identifier to which these results belong
- machine_name: host name of the test machine
- os: name of the os of the test machine ('linux', 'win', 'mac')
- os_version: long string of os version
- platform: processor name, e.g. x86_64
- build_name: name of the product under test, e.g. Firefox
- version: version of the product under test
- revision: source stamp of the product, if available
- branch: branch of the product under test
- id: the build ID for which the dzresults are for; a unique identifier to which these results belong
- test_date: time stamp (seconds since epoch) of the test run, or now if not specified
"""

self.machine_name = machine_name
Expand All @@ -68,7 +96,7 @@ def __init__(self, machine_name="", os="", os_version="", platform="",

def add_datazilla_result(self, res):
"""Join a DatazillaResult object to the results."""
self.results.join_results(res.results)
self.results.join_results(res)

def datasets(self):
"""Return the datasets in JSON serializable form"""
Expand Down Expand Up @@ -97,6 +125,12 @@ def datasets(self):
dataset = deepcopy(perf_json)
dataset['testrun']['suite'] = suite
dataset['results'] = deepcopy(data)
options = self.results.options.get(suite)
if options:
dataset['testrun']['options'] = deepcopy(options)
results_aux = self.results.results_aux.get(suite)
if results_aux:
dataset['results_aux'] = deepcopy(results_aux)
datasets.append(dataset)

return datasets
Expand Down
11 changes: 9 additions & 2 deletions dzclient/tests/test_datazilla_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,23 @@ def test_add_test_results(self):
self.assertEqual(res.results, {"suite": {"test": [1, 2, 3]}})


def test_add_auxiliary_results(self):
"""Can add auxiliary results to a suite"""
res = DatazillaResult()
res.add_auxiliary_results("suite", "name", [1, 2, 3])
self.assertEqual(res.results_aux, {"suite": {"name": [1, 2, 3]}})


def test_join_results(self):
"""Can merge a full results dictionary into this result."""
res = DatazillaResult({"suite1": {"test1a": [1]}})

res.join_results(
res.join_results(DatazillaResult(
{
"suite1": {"test1a": [2], "test1b": [3]},
"suite2": {"test2a": [4]},
}
)
))

self.assertEqual(
res.results,
Expand Down

0 comments on commit 2a639e8

Please sign in to comment.