commit c5dd5cbeff223295e36f9b8d4e4f349893b821ff Merge: 6164c62 743917a Author: Isis Lovecruft isis@torproject.org Date: Mon May 30 16:10:23 2016 +0000
Merge branch 'fix/18237' into develop
CHANGELOG | 8 ++++++++ bridgedb.conf | 2 ++ bridgedb/Main.py | 12 ++++++++++++ bridgedb/runner.py | 29 +++++++++++++++++++++++++++++ bridgedb/util.py | 21 +++++++++++++++++++++ test/test_util.py | 31 +++++++++++++++++++++++++++++++ 6 files changed, 103 insertions(+)
diff --cc test/test_util.py index f7a2245,848ce12..ea5d9ee --- a/test/test_util.py +++ b/test/test_util.py @@@ -71,8 -72,38 +72,38 @@@ class MiscLoggingUtilTests(unittest.Tes util.logging.info("BridgeDB's email address: bridges@torproject.org")
+ class FileUtilityTests(unittest.TestCase): + """Unittests for `bridgedb.util.deleteFilesOlderThan`.""" + + def setUp(self): + self._directory = self.id() + self.newfile = os.sep.join([self._directory, "newfile"]) + self.oldfile = os.sep.join([self._directory, "oldfile"]) + self.testfiles = [self.newfile, self.oldfile] + os.mkdir(self._directory) + + now = time.time() + + for fn in self.testfiles: + with open(fn, "w") as fd: + fd.flush() + + # Change the mtime of the "oldfile" to be two days old: + os.utime(self.oldfile, (now, now - (48 * 60 * 60))) + + def test_deleteFilesOlderThan_deletes_old_files(self): + """The function should delete appropriate files.""" + deleted = util.deleteFilesOlderThan(self.testfiles ,24 * 60 * 60) + self.assertIn(self.oldfile, deleted) + + def test_deleteFilesOlderThan_keeps_new_files(self): + """The function should delete appropriate files.""" + deleted = util.deleteFilesOlderThan(self.testfiles ,24 * 60 * 60) + self.assertNotIn(self.newfile, deleted) + + class LevenshteinDistanceTests(unittest.TestCase): - """Unittests for `bridgedb.util.levenshteinDistance.""" + """Unittests for `bridgedb.util.levenshteinDistance`."""
def test_levenshteinDistance_blank_blank(self): """The Levenshtein Distance between '' and '' should be 0."""
tor-commits@lists.torproject.org