Replace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests.

This commit is contained in:
Florent Xicluna 2010-03-31 22:01:03 +00:00
parent ad59833649
commit 6257a7bbb2
21 changed files with 112 additions and 226 deletions

View file

@ -23,14 +23,8 @@ class TestMacostools(unittest.TestCase):
rfp.close()
def tearDown(self):
try:
os.unlink(test_support.TESTFN)
except:
pass
try:
os.unlink(TESTFN2)
except:
pass
test_support.unlink(test_support.TESTFN)
test_support.unlink(TESTFN2)
def compareData(self):
fp = open(test_support.TESTFN, 'r')
@ -53,36 +47,25 @@ class TestMacostools(unittest.TestCase):
def test_touched(self):
# This really only tests that nothing unforeseen happens.
import warnings
with warnings.catch_warnings():
warnings.filterwarnings('ignore', 'macostools.touched*',
DeprecationWarning)
with test_support.check_warnings(('macostools.touched*',
DeprecationWarning), quiet=True):
macostools.touched(test_support.TESTFN)
if sys.maxint < 2**32:
def test_copy(self):
try:
os.unlink(TESTFN2)
except:
pass
test_support.unlink(TESTFN2)
macostools.copy(test_support.TESTFN, TESTFN2)
self.assertEqual(self.compareData(), '')
if sys.maxint < 2**32:
def test_mkalias(self):
try:
os.unlink(TESTFN2)
except:
pass
test_support.unlink(TESTFN2)
macostools.mkalias(test_support.TESTFN, TESTFN2)
fss, _, _ = Carbon.File.ResolveAliasFile(TESTFN2, 0)
self.assertEqual(fss.as_pathname(), os.path.realpath(test_support.TESTFN))
def test_mkalias_relative(self):
try:
os.unlink(TESTFN2)
except:
pass
test_support.unlink(TESTFN2)
# If the directory doesn't exist, then chances are this is a new
# install of Python so don't create it since the user might end up
# running ``sudo make install`` and creating the directory here won't