diff -r 8f1187288fac Lib/packaging/tests/test_support.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/packaging/tests/test_support.py Thu Sep 08 00:06:54 2011 +0200 @@ -0,0 +1,86 @@ +"""Tests for packaging.tests.support""" + +import os +import unittest + +from packaging.dist import Distribution +from packaging.tests import support + +class TestingSupportTestCase(unittest.TestCase): + + def test_fake_dec(self): + @support.fake_dec(1, 2, k=3) + def func(arg0, *args, **kargs): + return arg0, args, kargs + self.assertEqual(func(-1, -2, k=-3), (-1, (-2,), {'k':-3})) + + def test_TempdirManager(self): + self.longMessage = True + + files = {} + dirs = {} + + class Mixin(support.TempdirManager, unittest.TestCase): + + def test_mktempfile(self2): + tmpFile = self2.mktempfile() + files['from_test_mktempfile'] = tmpFile.name + self2.assertTrue(os.path.exists(tmpFile.name)) + self2.assertTrue(os.path.isfile(tmpFile.name)) + + def test_mkdtemp(self2): + tmpdir = self2.mkdtemp() + dirs['from_test_mkdtemp'] = tmpdir + self2.assertTrue(os.path.exists(tmpdir)) + self2.assertTrue(os.path.isdir(tmpdir)) + + def test_write_file(self2): + tmpdir = self2.mkdtemp() + dirs['from_test_write_file'] = tmpdir + self2.write_file((tmpdir, 'file1'), 'me file 1') + file1 = os.path.join(tmpdir, 'file1') + self2.assertTrue(os.path.exists(file1)) + self2.assertTrue(os.path.isfile(file1)) + text = '' + with open(file1, 'r') as f: + text = f.read() + self2.assertEqual(text, 'me file 1') + + def test_create_dist(self2): + project_dir, dist = self2.create_dist() + dirs['from_test_create_dist'] = project_dir + self2.assertTrue(os.path.exists(project_dir)) + self2.assertTrue(os.path.isdir(project_dir)) + self2.assertTrue(hasattr(dist, 'get_fullname')) + + def test_assertIsFile(self2): + self2.assertIsFile(__file__) + self2.assertRaises(AssertionError, self2.assertIsFile, 'foo') + + def test_assertIsNotFile(self2): + self2.assertIsNotFile(os.path.dirname(__file__)) + + result = unittest.TestResult() + suite = unittest.TestLoader().loadTestsFromTestCase(Mixin) + suite.run(result) + + tracebacks = '\n' + for error in result.errors: + tracebacks += error[1] + for failure in result.failures: + tracebacks += failure[1] + + self.assertEqual(result.testsRun, 6) + self.assertTrue(result.wasSuccessful(), tracebacks) + self.assertFalse(os.path.exists(files['from_test_mktempfile'])) + self.assertFalse(os.path.exists(dirs['from_test_mkdtemp'])) + self.assertFalse(os.path.exists(dirs['from_test_write_file'])) + self.assertFalse(os.path.exists(dirs['from_test_create_dist'])) + + +def test_suite(): + return unittest.makeSuite(TestingSupportTestCase) + +if __name__ == "__main__": + unittest.main(defaultTest="test_suite") +