diff options
| author | ?ric Araujo <merwok@netwok.org> | 2011-11-15 15:03:54 +0100 |
|---|---|---|
| committer | ?ric Araujo <merwok@netwok.org> | 2011-11-15 15:03:54 +0100 |
| commit | 6eacd6a2a4aefec9563cd2c6ad689c112d9d3ecb (patch) | |
| tree | 5adf3a6ad60e504fd858025631913d305fc66d19 | |
| parent | 144074adaade12979d514a785267b9d32b927c42 (diff) | |
| download | disutils2-6eacd6a2a4aefec9563cd2c6ad689c112d9d3ecb.tar.gz | |
Add tests for tests.support (#12659), thanks to Francisco Mart?n Brugu?
| -rw-r--r-- | CHANGES.txt | 1 | ||||
| -rw-r--r-- | CONTRIBUTORS.txt | 1 | ||||
| -rw-r--r-- | distutils2/tests/test_support.py | 85 |
3 files changed, 87 insertions, 0 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index f6f6f2a..fbd06c6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -159,6 +159,7 @@ CONTRIBUTORS.txt for full names. Bug numbers refer to http://bugs.python.org/. install_dir [éric] - Remove verbose arguments for Command and Compiler classes as well as util functions, obsoleted by logging [éric] +- #12659: Add tests for tests.support [francisco] 1.0a3 - 2010-10-08 diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index a353953..bb64a73 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -17,6 +17,7 @@ Thanks to: - Anthony Baxter - Erik Bray - C. Titus Brown +- Francisco Martín Brugué - Nicolas Cadou - Godefroid Chapelle - Christophe Combelles diff --git a/distutils2/tests/test_support.py b/distutils2/tests/test_support.py new file mode 100644 index 0000000..5640fcd --- /dev/null +++ b/distutils2/tests/test_support.py @@ -0,0 +1,85 @@ +import os +import tempfile + +from distutils2.dist import Distribution +from distutils2.tests import support, unittest + + +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): + files = {} + + class Tester(support.TempdirManager, unittest.TestCase): + + def runTest(self): + # empty method required for the backport + pass + + def test_mktempfile(self2): + tmpfile = self2.mktempfile() + files['test_mktempfile'] = tmpfile.name + self.assertTrue(os.path.isfile(tmpfile.name)) + + def test_mkdtemp(self2): + tmpdir = self2.mkdtemp() + files['test_mkdtemp'] = tmpdir + self.assertTrue(os.path.isdir(tmpdir)) + + def test_write_file(self2): + tmpdir = self2.mkdtemp() + files['test_write_file'] = tmpdir + self2.write_file((tmpdir, 'file1'), 'me file 1') + file1 = os.path.join(tmpdir, 'file1') + self.assertTrue(os.path.isfile(file1)) + text = '' + f = open(file1, 'r') + try: + text = f.read() + finally: + f.close() + self.assertEqual(text, 'me file 1') + + def test_create_dist(self2): + project_dir, dist = self2.create_dist() + files['test_create_dist'] = project_dir + self.assertTrue(os.path.isdir(project_dir)) + self.assertIsInstance(dist, Distribution) + + def test_assertIsFile(self2): + fd, fn = tempfile.mkstemp() + os.close(fd) + self.addCleanup(support.unlink, fn) + self2.assertIsFile(fn) + self.assertRaises(AssertionError, self2.assertIsFile, 'foO') + + def test_assertIsNotFile(self2): + tmpdir = self2.mkdtemp() + self2.assertIsNotFile(tmpdir) + + tester = Tester() + for name in ('test_mktempfile', 'test_mkdtemp', 'test_write_file', + 'test_create_dist', 'test_assertIsFile', + 'test_assertIsNotFile'): + tester.setUp() + try: + getattr(tester, name)() + finally: + tester.tearDown() + + # check clean-up + if name in files: + self.assertFalse(os.path.exists(files[name])) + + +def test_suite(): + return unittest.makeSuite(TestingSupportTestCase) + +if __name__ == "__main__": + unittest.main(defaultTest="test_suite") |
