From: Ezio Melotti Date: Thu, 10 Jan 2013 01:29:45 +0000 (+0200) Subject: #16852: merge with 3.3. X-Git-Tag: v3.4.0a1~1669 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=11b3a6056fd67862311f3992bfea5442ef011821;p=python #16852: merge with 3.3. --- 11b3a6056fd67862311f3992bfea5442ef011821 diff --cc Lib/test/test_genericpath.py index 060102df73,fd8bc577ca..e967897d75 --- a/Lib/test/test_genericpath.py +++ b/Lib/test/test_genericpath.py @@@ -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). diff --cc Lib/test/test_posixpath.py index c394fd9b39,a16a957e6a..43442e5acc --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@@ -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 324d7218dd,1d678dc93b..8e49199bdc --- a/Misc/NEWS +++ 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.