def _mock_update3(_): return { fh.day_format(datetime.datetime.utcnow()): 19, fh.day_format(datetime.datetime.utcnow() - datetime.timedelta(days=18)): 5, fh.day_format(datetime.datetime.utcnow() - datetime.timedelta(days=27)): 2, fh.day_format(datetime.datetime.utcnow() - datetime.timedelta(days=28)): 2, fh.day_format(datetime.datetime.utcnow() - datetime.timedelta(days=100)): 1, fh.day_format(datetime.datetime.utcnow() - datetime.timedelta(days=200)): 1}
def test_update_freq(self): # tests updating the files for frequency fh.update_frequency = self.norm_update now = fh.day_format(datetime.datetime.now()) _, freq_path = tempfile.mkstemp() freq_dir, freq_file = freq_path.rsplit(os.path.sep, 1) def _get_freq(): return freq_file self.shell_ctx.config.config_dir = freq_dir self.shell_ctx.config.get_frequency = _get_freq # with a file json_freq = fh.update_frequency(self.shell_ctx) self.assertEqual(json_freq, {now: 1}) json_freq = fh.update_frequency(self.shell_ctx) self.assertEqual(json_freq, {now: 2}) if os.path.exists(freq_path): os.remove(freq_path)
def test_update_freq(self): # tests updating the files for frequency fh.update_frequency = self.norm_update now = fh.day_format(datetime.datetime.now()) fd, freq_path = tempfile.mkstemp() freq_dir, freq_file = freq_path.rsplit(os.path.sep, 1) def _get_freq(): return freq_file self.shell_ctx.config.config_dir = freq_dir self.shell_ctx.config.get_frequency = _get_freq # with a file json_freq = fh.update_frequency(self.shell_ctx) self.assertEqual(json_freq, {now: 1}) json_freq = fh.update_frequency(self.shell_ctx) self.assertEqual(json_freq, {now: 2}) if os.path.exists(freq_path): os.close(fd) os.remove(freq_path)
def test_update_freq_no_file(self): # tests updating the files for frequency with no file written fh.update_frequency = self.norm_update fd, freq_path = tempfile.mkstemp() freq_dir, freq_file = freq_path.rsplit(os.path.sep, 1) def _get_freq(): return freq_file self.shell_ctx.config.config_dir = freq_dir self.shell_ctx.config.get_frequency = _get_freq if os.path.exists(freq_path): os.close(fd) os.remove(freq_path) # without a file already written json_freq = fh.update_frequency(self.shell_ctx) now = fh.day_format(datetime.datetime.now()) self.assertEqual(json_freq, {now: 1}) if os.path.exists(freq_path): os.remove(freq_path)
def _mock_update2(_): return { fh.day_format(datetime.datetime.utcnow()): 2, fh.day_format(datetime.datetime.utcnow() - datetime.timedelta(days=2)): 1}
def _mock_update(_): return {fh.day_format(datetime.datetime.utcnow()): 1}