diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2017-07-17 11:09:34 -0400 |
---|---|---|
committer | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2017-07-17 11:09:34 -0400 |
commit | 58a3909a3f678dec7bd94bfb38f96756c970113e (patch) | |
tree | 96675ca63ab47a93aca816909805264e6667ea7b /buildscripts/ciconfig | |
parent | 27cf9fd7b31f043af913da135385367126f5691b (diff) | |
download | mongo-58a3909a3f678dec7bd94bfb38f96756c970113e.tar.gz |
SERVER-29642 SERVER-29643 Add Python tests for test lifecycle scripts.
For test_failures.py:
* Replaces HistoryReport with a TestHistory class that has
get_history_by_revision() and get_history_by_date() methods. They
both return a list of ReportEntry tuples that can be used to
construct a Report instance.
* Adds Python unit test cases for the Report and ReportEntry classes.
* Creates Wildcard class as separate concept from Missing class.
* Enables --sinceDate and --untilDate with a warning that the script
may not return a complete result set.
* Adds support for running the script with Python 3.
For update_test_lifecycle.py:
* Introduces Config namedtuple to represent the test lifecycle model.
* Adds Python unit tests cases for the update_tags() function.
* Takes advantage of the partial grouping so that computing summaries
for (test, task, variant), (test, task), and (test,) combinations do
not require re-processing the entire result set.
Diffstat (limited to 'buildscripts/ciconfig')
-rw-r--r-- | buildscripts/ciconfig/tags.py | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/buildscripts/ciconfig/tags.py b/buildscripts/ciconfig/tags.py index dbd090bc9a8..dfab58832fa 100644 --- a/buildscripts/ciconfig/tags.py +++ b/buildscripts/ciconfig/tags.py @@ -1,4 +1,5 @@ """Module to access and modify tag configuration files used by resmoke.""" + from __future__ import absolute_import from __future__ import print_function @@ -11,7 +12,7 @@ import yaml # Setup to preserve order in yaml.dump, see https://stackoverflow.com/a/8661021 def _represent_dict_order(self, data): - return self.represent_mapping('tag:yaml.org,2002:map', data.items()) + return self.represent_mapping("tag:yaml.org,2002:map", data.items()) yaml.add_representer(collections.OrderedDict, _represent_dict_order) # End setup @@ -20,17 +21,38 @@ yaml.add_representer(collections.OrderedDict, _represent_dict_order) class TagsConfig(object): """Represent a test tag configuration file.""" - def __init__(self, filename, cmp_func=None): - """Initialize a TagsConfig from a file. + def __init__(self, raw, cmp_func=None): + """Initialize a TagsConfig from a dict representing the associations between tests and tags. 'cmp_func' can be used to specify a comparison function that will be used when sorting tags. """ - with open(filename, "r") as fstream: - self.raw = yaml.safe_load(fstream) + + self.raw = raw self._conf = self.raw["selector"] self._conf_copy = copy.deepcopy(self._conf) self._cmp_func = cmp_func + @classmethod + def from_file(cls, filename, **kwargs): + """Return a TagsConfig from a file containing the associations between tests and tags. + + See TagsConfig.__init__() for the keyword arguments that can be specified. + """ + + with open(filename, "r") as fstream: + raw = yaml.safe_load(fstream) + + return cls(raw, **kwargs) + + @classmethod + def from_dict(cls, raw, **kwargs): + """Return a TagsConfig from a dict representing the associations between tests and tags. + + See TagsConfig.__init__() for the keyword arguments that can be specified. + """ + + return cls(copy.deepcopy(raw), **kwargs) + def get_test_kinds(self): """List the test kinds.""" return self._conf.keys() @@ -75,9 +97,14 @@ class TagsConfig(object): """ with open(filename, "w") as fstream: if preamble: - print(textwrap.fill(preamble, width=100, initial_indent="# ", + print(textwrap.fill(preamble, + width=100, + initial_indent="# ", subsequent_indent="# "), file=fstream) + + # We use yaml.safe_dump() in order avoid having strings being written to the file as + # "!!python/unicode ..." and instead have them written as plain 'str' instances. yaml.safe_dump(self.raw, fstream, default_flow_style=False) |