mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
Bug 1404401 - ignore presence of target_task_config.json in tests; r=ahal
I *think* the modifications to MockedOpen are correct, but I'm not sure.. MozReview-Commit-ID: 6vTZBtdQ1dz --HG-- extra : rebase_source : 2d2008f87640747ef831d000bf13a4b1b7fcd338
This commit is contained in:
parent
9f2dd4775e
commit
0d5ca56ea5
@ -135,6 +135,9 @@ class MockedOpen(object):
|
||||
|
||||
will thus open the virtual file instance for the file 'foo' to f.
|
||||
|
||||
If the content of a file is given as None, then that file will be
|
||||
represented as not existing (even if it does, actually, exist).
|
||||
|
||||
MockedOpen also masks writes, so that creating or replacing files
|
||||
doesn't touch the file system, while subsequently opening the file
|
||||
will return the recorded content.
|
||||
@ -154,7 +157,10 @@ class MockedOpen(object):
|
||||
if 'w' in mode:
|
||||
file = MockedFile(self, absname)
|
||||
elif absname in self.files:
|
||||
file = MockedFile(self, absname, self.files[absname])
|
||||
content = self.files[absname]
|
||||
if content is None:
|
||||
raise IOError(2, 'No such file or directory')
|
||||
file = MockedFile(self, absname, content)
|
||||
elif 'a' in mode:
|
||||
file = MockedFile(self, absname, self.open(name, 'r').read())
|
||||
else:
|
||||
@ -183,17 +189,16 @@ class MockedOpen(object):
|
||||
|
||||
def _wrapped_exists(self, p):
|
||||
return (self._wrapped_isfile(p) or
|
||||
self._wrapped_isdir(p) or
|
||||
self._orig_path_exists(p))
|
||||
self._wrapped_isdir(p))
|
||||
|
||||
def _wrapped_isfile(self, p):
|
||||
p = normcase(p)
|
||||
if p in self.files:
|
||||
return True
|
||||
return self.files[p] is not None
|
||||
|
||||
abspath = normcase(os.path.abspath(p))
|
||||
if abspath in self.files:
|
||||
return True
|
||||
return self.files[abspath] is not None
|
||||
|
||||
return self._orig_path_isfile(p)
|
||||
|
||||
@ -207,7 +212,7 @@ class MockedOpen(object):
|
||||
if any(f.startswith(abspath) for f in self.files):
|
||||
return True
|
||||
|
||||
return self._orig_path_exists(p)
|
||||
return self._orig_path_isdir(p)
|
||||
|
||||
|
||||
def main(*args, **kwargs):
|
||||
|
@ -46,6 +46,8 @@ class TestDecision(unittest.TestCase):
|
||||
|
||||
class TestGetDecisionParameters(unittest.TestCase):
|
||||
|
||||
ttc_file = os.path.join(os.getcwd(), 'try_task_config.json')
|
||||
|
||||
def setUp(self):
|
||||
self.options = {
|
||||
'base_repository': 'https://hg.mozilla.org/mozilla-unified',
|
||||
@ -61,7 +63,8 @@ class TestGetDecisionParameters(unittest.TestCase):
|
||||
}
|
||||
|
||||
def test_simple_options(self):
|
||||
params = decision.get_decision_parameters(self.options)
|
||||
with MockedOpen({self.ttc_file: None}):
|
||||
params = decision.get_decision_parameters(self.options)
|
||||
self.assertEqual(params['pushlog_id'], 143)
|
||||
self.assertEqual(params['build_date'], 1503691511)
|
||||
self.assertEqual(params['moz_build_date'], '20170825200511')
|
||||
@ -71,13 +74,15 @@ class TestGetDecisionParameters(unittest.TestCase):
|
||||
|
||||
def test_no_email_owner(self):
|
||||
self.options['owner'] = 'ffxbld'
|
||||
params = decision.get_decision_parameters(self.options)
|
||||
with MockedOpen({self.ttc_file: None}):
|
||||
params = decision.get_decision_parameters(self.options)
|
||||
self.assertEqual(params['owner'], 'ffxbld@noreply.mozilla.org')
|
||||
|
||||
def test_try_options(self):
|
||||
self.options['message'] = 'try: -b do -t all'
|
||||
self.options['project'] = 'try'
|
||||
params = decision.get_decision_parameters(self.options)
|
||||
with MockedOpen({self.ttc_file: None}):
|
||||
params = decision.get_decision_parameters(self.options)
|
||||
self.assertEqual(params['try_mode'], 'try_option_syntax')
|
||||
self.assertEqual(params['try_options']['build_types'], 'do')
|
||||
self.assertEqual(params['try_options']['unittests'], 'all')
|
||||
@ -85,9 +90,8 @@ class TestGetDecisionParameters(unittest.TestCase):
|
||||
|
||||
def test_try_task_config(self):
|
||||
ttc = {'tasks': ['a', 'b'], 'templates': {}}
|
||||
ttc_file = os.path.join(os.getcwd(), 'try_task_config.json')
|
||||
self.options['project'] = 'try'
|
||||
with MockedOpen({ttc_file: json.dumps(ttc)}):
|
||||
with MockedOpen({self.ttc_file: json.dumps(ttc)}):
|
||||
params = decision.get_decision_parameters(self.options)
|
||||
self.assertEqual(params['try_mode'], 'try_task_config')
|
||||
self.assertEqual(params['try_options'], None)
|
||||
|
Loading…
x
Reference in New Issue
Block a user