ยปCore Development>Code coverage>Lib/distutils/tests/test_dep_util.py

Python code coverage for Lib/distutils/tests/test_dep_util.py

#countcontent
1n/a"""Tests for distutils.dep_util."""
2n/aimport unittest
3n/aimport os
4n/a
5n/afrom distutils.dep_util import newer, newer_pairwise, newer_group
6n/afrom distutils.errors import DistutilsFileError
7n/afrom distutils.tests import support
8n/afrom test.support import run_unittest
9n/a
10n/aclass DepUtilTestCase(support.TempdirManager, unittest.TestCase):
11n/a
12n/a def test_newer(self):
13n/a
14n/a tmpdir = self.mkdtemp()
15n/a new_file = os.path.join(tmpdir, 'new')
16n/a old_file = os.path.abspath(__file__)
17n/a
18n/a # Raise DistutilsFileError if 'new_file' does not exist.
19n/a self.assertRaises(DistutilsFileError, newer, new_file, old_file)
20n/a
21n/a # Return true if 'new_file' exists and is more recently modified than
22n/a # 'old_file', or if 'new_file' exists and 'old_file' doesn't.
23n/a self.write_file(new_file)
24n/a self.assertTrue(newer(new_file, 'I_dont_exist'))
25n/a self.assertTrue(newer(new_file, old_file))
26n/a
27n/a # Return false if both exist and 'old_file' is the same age or younger
28n/a # than 'new_file'.
29n/a self.assertFalse(newer(old_file, new_file))
30n/a
31n/a def test_newer_pairwise(self):
32n/a tmpdir = self.mkdtemp()
33n/a sources = os.path.join(tmpdir, 'sources')
34n/a targets = os.path.join(tmpdir, 'targets')
35n/a os.mkdir(sources)
36n/a os.mkdir(targets)
37n/a one = os.path.join(sources, 'one')
38n/a two = os.path.join(sources, 'two')
39n/a three = os.path.abspath(__file__) # I am the old file
40n/a four = os.path.join(targets, 'four')
41n/a self.write_file(one)
42n/a self.write_file(two)
43n/a self.write_file(four)
44n/a
45n/a self.assertEqual(newer_pairwise([one, two], [three, four]),
46n/a ([one],[three]))
47n/a
48n/a def test_newer_group(self):
49n/a tmpdir = self.mkdtemp()
50n/a sources = os.path.join(tmpdir, 'sources')
51n/a os.mkdir(sources)
52n/a one = os.path.join(sources, 'one')
53n/a two = os.path.join(sources, 'two')
54n/a three = os.path.join(sources, 'three')
55n/a old_file = os.path.abspath(__file__)
56n/a
57n/a # return true if 'old_file' is out-of-date with respect to any file
58n/a # listed in 'sources'.
59n/a self.write_file(one)
60n/a self.write_file(two)
61n/a self.write_file(three)
62n/a self.assertTrue(newer_group([one, two, three], old_file))
63n/a self.assertFalse(newer_group([one, two, old_file], three))
64n/a
65n/a # missing handling
66n/a os.remove(one)
67n/a self.assertRaises(OSError, newer_group, [one, two, old_file], three)
68n/a
69n/a self.assertFalse(newer_group([one, two, old_file], three,
70n/a missing='ignore'))
71n/a
72n/a self.assertTrue(newer_group([one, two, old_file], three,
73n/a missing='newer'))
74n/a
75n/a
76n/adef test_suite():
77n/a return unittest.makeSuite(DepUtilTestCase)
78n/a
79n/aif __name__ == "__main__":
80n/a run_unittest(test_suite())