Change date format to seconds-since-epoch

ubuntu/dry-run
Colin Watson 11 years ago committed by Iain Lane
parent 964e414dbe
commit 4e59e3fb6a

@ -271,14 +271,13 @@ class AgePolicy(BasePolicy):
super().__init__('age', options, suite_info, {SuiteClass.PRIMARY_SOURCE_SUITE})
self._min_days = mindays
self._min_days_default = None # initialised later
# britney's "day" begins at 7pm (we want aging to occur in the 22:00Z run and we run Britney 2-4 times a day)
# NB: _date_now is used in tests
time_now = time.time()
if hasattr(self.options, 'fake_runtime'):
time_now = int(self.options.fake_runtime)
self.logger.info("overriding runtime with fake_runtime %d" % time_now)
self._date_now = int(((time_now / (60*60)) - 19) / 24)
self._date_now = int(time_now)
self._dates = {}
self._urgencies = {}
self._default_urgency = self.options.default_urgency
@ -336,7 +335,7 @@ class AgePolicy(BasePolicy):
elif self._dates[source_name][0] != source_data_srcdist.version:
self._dates[source_name] = (source_data_srcdist.version, self._date_now)
days_old = self._date_now - self._dates[source_name][1]
days_old = (self._date_now - self._dates[source_name][1]) / 60 / 60 / 24
min_days = self._min_days[urgency]
for bounty in excuse.bounty:
if excuse.bounty[bounty]:

@ -1,6 +1,6 @@
# <source> <version> <seen-at-day>
# <source> <version> <seen-at-timestamp>
# NB: The default "day" for the tests is 10. For urgency medium, this implies
# setting <seen-at-day> to 0-5 is passing while 6-10 is too young.
out-of-date-version 1.5 5
almost-aged-properly 2.0 6
aged-properly 2.0 5
out-of-date-version 1.5 342000
almost-aged-properly 2.0 428400
aged-properly 2.0 342000

@ -46,6 +46,7 @@ def initialize_policy(test_name, policy_class, *args, **kwargs):
adt_success_bounty=3,
adt_regression_penalty=False,
adt_retry_url_mech='run_id',
fake_runtime=774000,
**kwargs)
suite_info = Suites(
Suite(SuiteClass.TARGET_SUITE, target, os.path.join(test_dir, target), ''),
@ -234,10 +235,6 @@ class TestAgePolicy(unittest.TestCase):
'low': 10,
}
@classmethod
def reset_age(cls, policy, effective_date=10):
policy._date_now = effective_date
def test_missing_age_file(self):
age_file = os.path.join(POLICY_DATA_BASE_DIR, 'age', 'missing-age-file', 'age-policy-dates')
assert not os.path.exists(age_file)
@ -273,7 +270,6 @@ class TestAgePolicy(unittest.TestCase):
def test_age_old_version_aged(self):
src_name = 'out-of-date-version'
policy = initialize_policy('age/basic', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS)
self.reset_age(policy)
age_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_TEMPORARILY, src_name)
assert age_policy_info['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY]
assert age_policy_info['current-age'] == 0
@ -281,7 +277,6 @@ class TestAgePolicy(unittest.TestCase):
def test_age_almost_aged(self):
src_name = 'almost-aged-properly'
policy = initialize_policy('age/basic', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS)
self.reset_age(policy)
age_policy_info = apply_src_policy(policy, PolicyVerdict.REJECTED_TEMPORARILY, src_name)
assert age_policy_info['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY]
assert age_policy_info['current-age'] == 4
@ -289,7 +284,6 @@ class TestAgePolicy(unittest.TestCase):
def test_age_aged_properly(self):
src_name = 'aged-properly'
policy = initialize_policy('age/basic', AgePolicy, TestAgePolicy.DEFAULT_MIN_DAYS)
self.reset_age(policy)
age_policy_info = apply_src_policy(policy, PolicyVerdict.PASS, src_name)
assert age_policy_info['age-requirement'] == TestAgePolicy.DEFAULT_MIN_DAYS[DEFAULT_URGENCY]
assert age_policy_info['current-age'] == 5

Loading…
Cancel
Save