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