예제 #1
0
파일: test_dbm.py 프로젝트: za/cpython
 def test_whichdb(self):
     self.addCleanup(setattr, dbm, '_defaultmod', dbm._defaultmod)
     _bytes_fname = os.fsencode(_fname)
     fnames = [
         _fname,
         os_helper.FakePath(_fname), _bytes_fname,
         os_helper.FakePath(_bytes_fname)
     ]
     for module in dbm_iterator():
         # Check whether whichdb correctly guesses module name
         # for databases opened with "module" module.
         name = module.__name__
         setup_test_dir()
         dbm._defaultmod = module
         # Try with empty files first
         with module.open(_fname, 'c'):
             pass
         for path in fnames:
             self.assertEqual(name, self.dbm.whichdb(path))
         # Now add a key
         with module.open(_fname, 'w') as f:
             f[b"1"] = b"1"
             # and test that we can find it
             self.assertIn(b"1", f)
             # and read it
             self.assertEqual(f[b"1"], b"1")
         for path in fnames:
             self.assertEqual(name, self.dbm.whichdb(path))
예제 #2
0
 async def execute():
     p = await subprocess.create_subprocess_exec(
         os_helper.FakePath(sys.executable), '-c', 'pass')
     await p.wait()
     p = await subprocess.create_subprocess_exec(
         sys.executable, '-c', 'pass', os_helper.FakePath('.'))
     await p.wait()
예제 #3
0
 def test_whichdb_ndbm(self):
     # Issue 17198: check that ndbm which is referenced in whichdb is defined
     db_file = '{}_ndbm.db'.format(_fname)
     with open(db_file, 'w'):
         self.addCleanup(os_helper.unlink, db_file)
     db_file_bytes = os.fsencode(db_file)
     self.assertIsNone(self.dbm.whichdb(db_file[:-3]))
     self.assertIsNone(self.dbm.whichdb(os_helper.FakePath(db_file[:-3])))
     self.assertIsNone(self.dbm.whichdb(db_file_bytes[:-3]))
     self.assertIsNone(self.dbm.whichdb(os_helper.FakePath(db_file_bytes[:-3])))
예제 #4
0
파일: test_dbm.py 프로젝트: za/cpython
 def test_whichdb_ndbm(self):
     # Issue 17198: check that ndbm which is referenced in whichdb is defined
     with open(_fname + '.db', 'wb'):
         pass
     _bytes_fname = os.fsencode(_fname)
     fnames = [
         _fname,
         os_helper.FakePath(_fname), _bytes_fname,
         os_helper.FakePath(_bytes_fname)
     ]
     for path in fnames:
         self.assertIsNone(self.dbm.whichdb(path))
예제 #5
0
            async def execute():
                asyncio.set_child_watcher(watcher)

                with self.assertRaises(RuntimeError):
                    await subprocess.create_subprocess_exec(
                        os_helper.FakePath(sys.executable), '-c', 'pass')

                watcher.add_child_handler.assert_not_called()
예제 #6
0
        async def execute():
            watcher = mock.create_authspec(asyncio.AbstractChildWatcher)
            watcher.is_active.return_value = False
            asyncio.set_child_watcher(watcher)

            with self.assertRaises(RuntimeError):
                await subprocess.create_subprocess_exec(
                    os_helper.FakePath(sys.executable), '-c', 'pass')

            watcher.add_child_handler.assert_not_called()
예제 #7
0
 def test_whichdb(self):
     _bytes_fname = os.fsencode(_fname)
     for path in [_fname, os_helper.FakePath(_fname),
                  _bytes_fname, os_helper.FakePath(_bytes_fname)]:
         for module in dbm_iterator():
             # Check whether whichdb correctly guesses module name
             # for databases opened with "module" module.
             # Try with empty files first
             name = module.__name__
             if name == 'dbm.dumb':
                 continue   # whichdb can't support dbm.dumb
             delete_files()
             f = module.open(path, 'c')
             f.close()
             self.assertEqual(name, self.dbm.whichdb(path))
             # Now add a key
             f = module.open(path, 'w')
             f[b"1"] = b"1"
             # and test that we can find it
             self.assertIn(b"1", f)
             # and read it
             self.assertEqual(f[b"1"], b"1")
             f.close()
             self.assertEqual(name, self.dbm.whichdb(path))
예제 #8
0
 def test_pathlib_bytes_path_file_shelf(self):
     self.test_open_template(
         filename=os_helper.FakePath(os.fsencode(self.fn)))
예제 #9
0
 def test_pathlib_path_file_shelf(self):
     self.test_open_template(filename=os_helper.FakePath(self.fn))
예제 #10
0
파일: test_dbm.py 프로젝트: za/cpython
 def test_open_with_pathlib_path_bytes(self):
     dbm.open(os_helper.FakePath(os.fsencode(_fname)), "c").close()
예제 #11
0
파일: test_dbm.py 프로젝트: za/cpython
 def test_open_with_pathlib_path(self):
     dbm.open(os_helper.FakePath(_fname), "c").close()
예제 #12
0
 def test_open_with_pathlib_bytes_path(self):
     dbm.ndbm.open(os_helper.FakePath(os.fsencode(self.filename)),
                   "c").close()