-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_latest.py
More file actions
44 lines (35 loc) · 1.23 KB
/
test_latest.py
File metadata and controls
44 lines (35 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import unittest
import latest
import time
import os
PATHSTEM = "/Users/jgilbert/extras/tmp/"
class TestLatest(unittest.TestCase):
def setUp(self):
self.path = PATHSTEM
self.file_names = ["file.old", "file.bak", "file.new"]
for fn in self.file_names:
f = open(self.path+fn, "w")
f.close()
time.sleep(1)
def test_latest_no_number(self):
"""
Ensure that calling the function with no arguments returns the single most
recently-created file.
"""
expected = ["file.new"]
latest_file = latest.latest(path=self.path)
self.assertEqual(latest_file, expected, "Most recently created file was not returned")
def test_latest_with_args(self):
"""
Ensure that calling the function with arguments of 2 and some directory
returns the two most recently-created files in the directory.
"""
expected = set(["file.new",
"file.bak"])
latest_files = set(latest.latest(2, self.path))
self.assertEqual(latest_files, expected)
def tearDown(self):
for fn in self.file_names:
os.remove(self.path + fn)
if __name__ == "__main__":
unittest.main()