]> granicus.if.org Git - python/commitdiff
#16852: merge with 3.3.
authorEzio Melotti <ezio.melotti@gmail.com>
Thu, 10 Jan 2013 01:29:45 +0000 (03:29 +0200)
committerEzio Melotti <ezio.melotti@gmail.com>
Thu, 10 Jan 2013 01:29:45 +0000 (03:29 +0200)
1  2 
Lib/test/test_genericpath.py
Lib/test/test_posixpath.py
Misc/NEWS

index 060102df734049a4d82a65ec9e07d1615ab96ad9,fd8bc577ca85e836d85fd05e697a3c991f7c2a66..e967897d75774a091686234471c22e93d925172e
@@@ -190,87 -188,12 +188,93 @@@ class GenericTest
              support.unlink(support.TESTFN)
              safe_rmdir(support.TESTFN)
  
 +    @staticmethod
 +    def _create_file(filename):
 +        with open(filename, 'wb') as f:
 +            f.write(b'foo')
 +
 +    def test_samefile(self):
 +        try:
 +            test_fn = support.TESTFN + "1"
 +            self._create_file(test_fn)
 +            self.assertTrue(self.pathmodule.samefile(test_fn, test_fn))
 +            self.assertRaises(TypeError, self.pathmodule.samefile)
 +        finally:
 +            os.remove(test_fn)
 +
 +    @support.skip_unless_symlink
 +    def test_samefile_on_symlink(self):
 +        self._test_samefile_on_link_func(os.symlink)
 +
 +    def test_samefile_on_link(self):
 +        self._test_samefile_on_link_func(os.link)
 +
 +    def _test_samefile_on_link_func(self, func):
 +        try:
 +            test_fn1 = support.TESTFN + "1"
 +            test_fn2 = support.TESTFN + "2"
 +            self._create_file(test_fn1)
 +
 +            func(test_fn1, test_fn2)
 +            self.assertTrue(self.pathmodule.samefile(test_fn1, test_fn2))
 +            os.remove(test_fn2)
 +
 +            self._create_file(test_fn2)
 +            self.assertFalse(self.pathmodule.samefile(test_fn1, test_fn2))
 +        finally:
 +            os.remove(test_fn1)
 +            os.remove(test_fn2)
 +
 +    def test_samestat(self):
 +        try:
 +            test_fn = support.TESTFN + "1"
 +            self._create_file(test_fn)
 +            test_fns = [test_fn]*2
 +            stats = map(os.stat, test_fns)
 +            self.assertTrue(self.pathmodule.samestat(*stats))
 +        finally:
 +            os.remove(test_fn)
 +
 +    @support.skip_unless_symlink
 +    def test_samestat_on_symlink(self):
 +        self._test_samestat_on_link_func(os.symlink)
 +
 +    def test_samestat_on_link(self):
 +        self._test_samestat_on_link_func(os.link)
 +
 +    def _test_samestat_on_link_func(self, func):
 +        try:
 +            test_fn1 = support.TESTFN + "1"
 +            test_fn2 = support.TESTFN + "2"
 +            self._create_file(test_fn1)
 +            test_fns = (test_fn1, test_fn2)
 +            func(*test_fns)
 +            stats = map(os.stat, test_fns)
 +            self.assertTrue(self.pathmodule.samestat(*stats))
 +            os.remove(test_fn2)
 +
 +            self._create_file(test_fn2)
 +            stats = map(os.stat, test_fns)
 +            self.assertFalse(self.pathmodule.samestat(*stats))
 +
 +            self.assertRaises(TypeError, self.pathmodule.samestat)
 +        finally:
 +            os.remove(test_fn1)
 +            os.remove(test_fn2)
 +
 +    def test_sameopenfile(self):
 +        fname = support.TESTFN + "1"
 +        with open(fname, "wb") as a, open(fname, "wb") as b:
 +            self.assertTrue(self.pathmodule.sameopenfile(
 +                                a.fileno(), b.fileno()))
 +
+ class TestGenericTest(GenericTest, unittest.TestCase):
+     # Issue 16852: GenericTest can't inherit from unittest.TestCase
+     # for test discovery purposes; CommonTest inherits from GenericTest
+     # and is only meant to be inherited by others.
+     pathmodule = genericpath
 +
  # Following TestCase is not supposed to be run from test_genericpath.
  # It is inherited by other test modules (macpath, ntpath, posixpath).
  
index c394fd9b3938603fe120243b13f83c9394ed14e1,a16a957e6a799047ad607babfd24dcca4b62ced4..43442e5acce512f9f9c8a787e2b9e7c530e13805
@@@ -461,8 -518,13 +461,8 @@@ class PosixPathTest(unittest.TestCase)
          finally:
              os.getcwdb = real_getcwdb
  
 -    def test_sameopenfile(self):
 -        fname = support.TESTFN + "1"
 -        with open(fname, "wb") as a, open(fname, "wb") as b:
 -            self.assertTrue(posixpath.sameopenfile(a.fileno(), b.fileno()))
 -
  
- class PosixCommonTest(test_genericpath.CommonTest):
+ class PosixCommonTest(test_genericpath.CommonTest, unittest.TestCase):
      pathmodule = posixpath
      attributes = ['relpath', 'samefile', 'sameopenfile', 'samestat']
  
diff --cc Misc/NEWS
index 324d7218dde0ad5f3b383a60058c732a2b93a3d0,1d678dc93b030a06448de26fbd48c2e5fb4b6dcd..8e49199bdc65479bcb1a4931fd216339107010ba
+++ b/Misc/NEWS
@@@ -612,15 -408,11 +612,18 @@@ Extension Module
  Tests
  -----
  
 +- Issue #16836: Enable IPv6 support even if IPv6 is disabled on the build host.
 +
+ - Issue #16852: test_genericpath, test_posixpath, test_ntpath, and test_macpath
+   now work with unittest test discovery.  Patch by Zachary Ware.
  - Issue #16748: test_heapq now works with unittest test discovery.
  
 +- Issue #10646: Tests rearranged for os.samefile/samestat to check for not
 +  just symlinks but also hard links.
 +
 +- Issue #15302: Switch regrtest from using getopt to using argparse.
 +
  - Issue #15324: Fix regrtest parsing of --fromfile, --match, and --randomize
    options.