ยปCore Development>Code coverage>Lib/test/test_tools/test_md5sum.py

Python code coverage for Lib/test/test_tools/test_md5sum.py

#countcontent
1n/a"""Tests for the md5sum script in the Tools directory."""
2n/a
3n/aimport os
4n/aimport unittest
5n/afrom test import support
6n/afrom test.support.script_helper import assert_python_ok, assert_python_failure
7n/a
8n/afrom test.test_tools import scriptsdir, skip_if_missing
9n/a
10n/askip_if_missing()
11n/a
12n/aclass MD5SumTests(unittest.TestCase):
13n/a @classmethod
14n/a def setUpClass(cls):
15n/a cls.script = os.path.join(scriptsdir, 'md5sum.py')
16n/a os.mkdir(support.TESTFN)
17n/a cls.fodder = os.path.join(support.TESTFN, 'md5sum.fodder')
18n/a with open(cls.fodder, 'wb') as f:
19n/a f.write(b'md5sum\r\ntest file\r\n')
20n/a cls.fodder_md5 = b'd38dae2eb1ab346a292ef6850f9e1a0d'
21n/a cls.fodder_textmode_md5 = b'a8b07894e2ca3f2a4c3094065fa6e0a5'
22n/a
23n/a @classmethod
24n/a def tearDownClass(cls):
25n/a support.rmtree(support.TESTFN)
26n/a
27n/a def test_noargs(self):
28n/a rc, out, err = assert_python_ok(self.script)
29n/a self.assertEqual(rc, 0)
30n/a self.assertTrue(
31n/a out.startswith(b'd41d8cd98f00b204e9800998ecf8427e <stdin>'))
32n/a self.assertFalse(err)
33n/a
34n/a def test_checksum_fodder(self):
35n/a rc, out, err = assert_python_ok(self.script, self.fodder)
36n/a self.assertEqual(rc, 0)
37n/a self.assertTrue(out.startswith(self.fodder_md5))
38n/a for part in self.fodder.split(os.path.sep):
39n/a self.assertIn(part.encode(), out)
40n/a self.assertFalse(err)
41n/a
42n/a def test_dash_l(self):
43n/a rc, out, err = assert_python_ok(self.script, '-l', self.fodder)
44n/a self.assertEqual(rc, 0)
45n/a self.assertIn(self.fodder_md5, out)
46n/a parts = self.fodder.split(os.path.sep)
47n/a self.assertIn(parts[-1].encode(), out)
48n/a self.assertNotIn(parts[-2].encode(), out)
49n/a
50n/a def test_dash_t(self):
51n/a rc, out, err = assert_python_ok(self.script, '-t', self.fodder)
52n/a self.assertEqual(rc, 0)
53n/a self.assertTrue(out.startswith(self.fodder_textmode_md5))
54n/a self.assertNotIn(self.fodder_md5, out)
55n/a
56n/a def test_dash_s(self):
57n/a rc, out, err = assert_python_ok(self.script, '-s', '512', self.fodder)
58n/a self.assertEqual(rc, 0)
59n/a self.assertIn(self.fodder_md5, out)
60n/a
61n/a def test_multiple_files(self):
62n/a rc, out, err = assert_python_ok(self.script, self.fodder, self.fodder)
63n/a self.assertEqual(rc, 0)
64n/a lines = out.splitlines()
65n/a self.assertEqual(len(lines), 2)
66n/a self.assertEqual(*lines)
67n/a
68n/a def test_usage(self):
69n/a rc, out, err = assert_python_failure(self.script, '-h')
70n/a self.assertEqual(rc, 2)
71n/a self.assertEqual(out, b'')
72n/a self.assertGreater(err, b'')
73n/a
74n/a
75n/aif __name__ == '__main__':
76n/a unittest.main()