2009-12-10 11:29:03 -04:00
|
|
|
"""Tests for distutils.dep_util."""
|
|
|
|
import unittest
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
|
|
|
|
from distutils.dep_util import newer, newer_pairwise, newer_group
|
|
|
|
from distutils.errors import DistutilsFileError
|
|
|
|
from distutils.tests import support
|
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
To comply with the 2.x doc style, the methods in trace.rst use brackets around
optional arguments. The rest is a mostly straight merge, modulo support changed
to test_support and use of the old super call style in test_tuple.
........
r86236 | eric.araujo | 2010-11-06 03:44:43 +0100 (sam., 06 nov. 2010) | 2 lines
Make sure each test can be run standalone (./python Lib/distutils/tests/x.py)
........
r86240 | eric.araujo | 2010-11-06 05:11:59 +0100 (sam., 06 nov. 2010) | 2 lines
Prevent ResourceWarnings in test_gettext
........
r86332 | eric.araujo | 2010-11-08 19:15:17 +0100 (lun., 08 nov. 2010) | 4 lines
Add missing NEWS entry for a fix committed by Senthil.
All recent modifications to distutils should now be covered in NEWS.
........
r86340 | eric.araujo | 2010-11-08 22:48:23 +0100 (lun., 08 nov. 2010) | 2 lines
This was actually fixed for the previous alpha.
........
r87271 | eric.araujo | 2010-12-15 20:09:58 +0100 (mer., 15 déc. 2010) | 2 lines
Improve trace documentation (#9264). Patch by Eli Bendersky.
........
r87273 | eric.araujo | 2010-12-15 20:30:15 +0100 (mer., 15 déc. 2010) | 2 lines
Use nested method directives, rewrap long lines, fix whitespace.
........
r87447 | eric.araujo | 2010-12-23 20:13:05 +0100 (jeu., 23 déc. 2010) | 2 lines
Fix typo in superclass method name
........
2011-02-02 20:12:18 -04:00
|
|
|
from test.test_support import run_unittest
|
2009-12-10 11:29:03 -04:00
|
|
|
|
|
|
|
class DepUtilTestCase(support.TempdirManager, unittest.TestCase):
|
|
|
|
|
|
|
|
def test_newer(self):
|
2009-12-10 15:29:53 -04:00
|
|
|
|
2009-12-10 11:29:03 -04:00
|
|
|
tmpdir = self.mkdtemp()
|
2009-12-10 15:29:53 -04:00
|
|
|
new_file = os.path.join(tmpdir, 'new')
|
|
|
|
old_file = os.path.abspath(__file__)
|
|
|
|
|
|
|
|
# Raise DistutilsFileError if 'new_file' does not exist.
|
|
|
|
self.assertRaises(DistutilsFileError, newer, new_file, old_file)
|
|
|
|
|
|
|
|
# Return true if 'new_file' exists and is more recently modified than
|
|
|
|
# 'old_file', or if 'new_file' exists and 'old_file' doesn't.
|
|
|
|
self.write_file(new_file)
|
|
|
|
self.assertTrue(newer(new_file, 'I_dont_exist'))
|
|
|
|
self.assertTrue(newer(new_file, old_file))
|
|
|
|
|
|
|
|
# Return false if both exist and 'old_file' is the same age or younger
|
|
|
|
# than 'new_file'.
|
|
|
|
self.assertFalse(newer(old_file, new_file))
|
2009-12-10 11:29:03 -04:00
|
|
|
|
|
|
|
def test_newer_pairwise(self):
|
|
|
|
tmpdir = self.mkdtemp()
|
|
|
|
sources = os.path.join(tmpdir, 'sources')
|
|
|
|
targets = os.path.join(tmpdir, 'targets')
|
|
|
|
os.mkdir(sources)
|
|
|
|
os.mkdir(targets)
|
|
|
|
one = os.path.join(sources, 'one')
|
|
|
|
two = os.path.join(sources, 'two')
|
2009-12-10 15:29:53 -04:00
|
|
|
three = os.path.abspath(__file__) # I am the old file
|
2009-12-10 11:29:03 -04:00
|
|
|
four = os.path.join(targets, 'four')
|
|
|
|
self.write_file(one)
|
|
|
|
self.write_file(two)
|
2009-12-10 15:29:53 -04:00
|
|
|
self.write_file(four)
|
2009-12-10 11:29:03 -04:00
|
|
|
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(newer_pairwise([one, two], [three, four]),
|
|
|
|
([one],[three]))
|
2009-12-10 11:29:03 -04:00
|
|
|
|
|
|
|
def test_newer_group(self):
|
|
|
|
tmpdir = self.mkdtemp()
|
|
|
|
sources = os.path.join(tmpdir, 'sources')
|
|
|
|
os.mkdir(sources)
|
|
|
|
one = os.path.join(sources, 'one')
|
|
|
|
two = os.path.join(sources, 'two')
|
|
|
|
three = os.path.join(sources, 'three')
|
2009-12-10 15:29:53 -04:00
|
|
|
old_file = os.path.abspath(__file__)
|
2009-12-10 11:29:03 -04:00
|
|
|
|
2009-12-10 15:29:53 -04:00
|
|
|
# return true if 'old_file' is out-of-date with respect to any file
|
2009-12-10 11:29:03 -04:00
|
|
|
# listed in 'sources'.
|
|
|
|
self.write_file(one)
|
|
|
|
self.write_file(two)
|
|
|
|
self.write_file(three)
|
2009-12-10 15:29:53 -04:00
|
|
|
self.assertTrue(newer_group([one, two, three], old_file))
|
|
|
|
self.assertFalse(newer_group([one, two, old_file], three))
|
2009-12-10 11:29:03 -04:00
|
|
|
|
|
|
|
# missing handling
|
|
|
|
os.remove(one)
|
2009-12-10 15:29:53 -04:00
|
|
|
self.assertRaises(OSError, newer_group, [one, two, old_file], three)
|
2009-12-10 11:29:03 -04:00
|
|
|
|
2009-12-10 15:29:53 -04:00
|
|
|
self.assertFalse(newer_group([one, two, old_file], three,
|
2009-12-10 11:29:03 -04:00
|
|
|
missing='ignore'))
|
|
|
|
|
2009-12-10 15:29:53 -04:00
|
|
|
self.assertTrue(newer_group([one, two, old_file], three,
|
2009-12-10 11:29:03 -04:00
|
|
|
missing='newer'))
|
|
|
|
|
|
|
|
|
|
|
|
def test_suite():
|
|
|
|
return unittest.makeSuite(DepUtilTestCase)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
To comply with the 2.x doc style, the methods in trace.rst use brackets around
optional arguments. The rest is a mostly straight merge, modulo support changed
to test_support and use of the old super call style in test_tuple.
........
r86236 | eric.araujo | 2010-11-06 03:44:43 +0100 (sam., 06 nov. 2010) | 2 lines
Make sure each test can be run standalone (./python Lib/distutils/tests/x.py)
........
r86240 | eric.araujo | 2010-11-06 05:11:59 +0100 (sam., 06 nov. 2010) | 2 lines
Prevent ResourceWarnings in test_gettext
........
r86332 | eric.araujo | 2010-11-08 19:15:17 +0100 (lun., 08 nov. 2010) | 4 lines
Add missing NEWS entry for a fix committed by Senthil.
All recent modifications to distutils should now be covered in NEWS.
........
r86340 | eric.araujo | 2010-11-08 22:48:23 +0100 (lun., 08 nov. 2010) | 2 lines
This was actually fixed for the previous alpha.
........
r87271 | eric.araujo | 2010-12-15 20:09:58 +0100 (mer., 15 déc. 2010) | 2 lines
Improve trace documentation (#9264). Patch by Eli Bendersky.
........
r87273 | eric.araujo | 2010-12-15 20:30:15 +0100 (mer., 15 déc. 2010) | 2 lines
Use nested method directives, rewrap long lines, fix whitespace.
........
r87447 | eric.araujo | 2010-12-23 20:13:05 +0100 (jeu., 23 déc. 2010) | 2 lines
Fix typo in superclass method name
........
2011-02-02 20:12:18 -04:00
|
|
|
run_unittest(test_suite())
|