diff --git a/britney2/policies/sruadtregression.py b/britney2/policies/sruadtregression.py index 17b56fb..fd23968 100644 --- a/britney2/policies/sruadtregression.py +++ b/britney2/policies/sruadtregression.py @@ -35,11 +35,6 @@ class SRUADTRegressionPolicy(BasePolicy, Rest): with open(self.state_filename, encoding='utf-8') as data: self.state = json.load(data) self.log('Loaded state file %s' % self.state_filename) - tmp = self.state_filename + '.new' - if os.path.exists(tmp): - with open(tmp, encoding='utf-8') as data: - self.state.update(json.load(data)) - self.restore_state() # Remove any old entries from the statefile self.cleanup_state() @@ -134,19 +129,9 @@ class SRUADTRegressionPolicy(BasePolicy, Rest): if series not in self.state[distro]: self.state[distro][series] = {} self.state[distro][series][source] = version - tmp = self.state_filename + '.new' - with open(tmp, 'w', encoding='utf-8') as data: + with open(self.state_filename, 'w', encoding='utf-8') as data: json.dump(self.state, data) - def restore_state(self): - try: - os.rename(self.state_filename + '.new', self.state_filename) - # If we haven't written any state, don't clobber the old one - except FileNotFoundError: - pass - - self.log('Wrote SRU ADT regression state to %s' % self.state_filename) - def cleanup_state(self): '''Remove all no-longer-valid package entries from the statefile''' for distro_name in self.state: diff --git a/tests/test_sruadtregression.py b/tests/test_sruadtregression.py index 218e713..66af41c 100755 --- a/tests/test_sruadtregression.py +++ b/tests/test_sruadtregression.py @@ -189,6 +189,13 @@ class T(unittest.TestCase): } self.assertDictEqual(pol.state, expected_state) log.assert_called_with('Sending ADT regression message to LP: #2 regarding testpackage/55.0 in zazzy') + # But also test if the state has been correctly recorded to the + # state file + state_path = os.path.join( + options.unstable, 'sru_regress_inform_state') + with open(state_path) as f: + saved_state = json.load(f) + self.assertDictEqual(saved_state, expected_state) @patch('smtplib.SMTP') @patch('britney2.policies.sruadtregression.SRUADTRegressionPolicy.bugs_from_changes', return_value={1, 2})