def test_does_not_touch_nonexisting_directory(self, rm, lstat, isfile, listdir, exists): exists.return_value = False supplier._prune(root_path="/tmp/test", max_age_days=7) assert listdir.call_count == 0, "attempted to list a non-existing directory"
def test_prunes_old_files(self, rm, lstat, isfile, listdir, exists): exists.return_value = True listdir.return_value = ["elasticsearch-6.8.0.tar.gz", "some-subdir", "elasticsearch-7.3.0-darwin-x86_64.tar.gz"] isfile.side_effect = [True, False, True] now = datetime.datetime.now(tz=datetime.timezone.utc) ten_days_ago = now - datetime.timedelta(days=10) one_day_ago = now - datetime.timedelta(days=1) lstat.side_effect = [ # elasticsearch-6.8.0.tar.gz PruneTests.LStat(st_ctime=int(ten_days_ago.timestamp())), # elasticsearch-7.3.0-darwin-x86_64.tar.gz PruneTests.LStat(st_ctime=int(one_day_ago.timestamp())) ] supplier._prune(root_path="/tmp/test", max_age_days=7) rm.assert_called_with("/tmp/test/elasticsearch-6.8.0.tar.gz")