| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5e01a65 commit b396663
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3638,6 +3638,24 @@ def test_os_all(self): | |||
| 3638 | 3638 | self.assertIn('walk', os.__all__) | |
| 3639 | 3639 | ||
| 3640 | 3640 | ||
| 3641 | + class TestDirEntry(unittest.TestCase): | ||
| 3642 | + def setUp(self): | ||
| 3643 | + self.path = os.path.realpath(support.TESTFN) | ||
| 3644 | + self.addCleanup(support.rmtree, self.path) | ||
| 3645 | + os.mkdir(self.path) | ||
| 3646 | + | ||
| 3647 | + def test_uninstantiable(self): | ||
| 3648 | + self.assertRaises(TypeError, os.DirEntry) | ||
| 3649 | + | ||
| 3650 | + def test_unpickable(self): | ||
| 3651 | + filename = create_file(os.path.join(self.path, "file.txt"), b'python') | ||
| 3652 | + entry = [entry for entry in os.scandir(self.path)].pop() | ||
| 3653 | + self.assertIsInstance(entry, os.DirEntry) | ||
| 3654 | + self.assertEqual(entry.name, "file.txt") | ||
| 3655 | + import pickle | ||
| 3656 | + self.assertRaises(TypeError, pickle.dumps, entry, filename) | ||
| 3657 | + | ||
| 3658 | + | ||
| 3641 | 3659 | class TestScandir(unittest.TestCase): | |
| 3642 | 3660 | check_no_resource_warning = support.check_no_resource_warning | |
| 3643 | 3661 | ||
@@ -3672,6 +3690,18 @@ def assert_stat_equal(self, stat1, stat2, skip_fields): | |||
| 3672 | 3690 | else: | |
| 3673 | 3691 | self.assertEqual(stat1, stat2) | |
| 3674 | 3692 | ||
| 3693 | + def test_uninstantiable(self): | ||
| 3694 | + scandir_iter = os.scandir(self.path) | ||
| 3695 | + self.assertRaises(TypeError, type(scandir_iter)) | ||
| 3696 | + scandir_iter.close() | ||
| 3697 | + | ||
| 3698 | + def test_unpickable(self): | ||
| 3699 | + filename = self.create_file("file.txt") | ||
| 3700 | + scandir_iter = os.scandir(self.path) | ||
| 3701 | + import pickle | ||
| 3702 | + self.assertRaises(TypeError, pickle.dumps, scandir_iter, filename) | ||
| 3703 | + scandir_iter.close() | ||
| 3704 | + | ||
| 3675 | 3705 | def check_entry(self, entry, name, is_dir, is_file, is_symlink): | |
| 3676 | 3706 | self.assertIsInstance(entry, os.DirEntry) | |
| 3677 | 3707 | self.assertEqual(entry.name, name) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Convert posixmodule.c statically allocated types ``DirEntryType`` and | ||
| 2 | + ``ScandirIteratorType`` to heap-allocated types. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments