def test_type_in_non_existent_directory_and_suppression_of_FileExistsError(self): """ creates a FileDict in a new directory making sure that the directory does not pre-exist, re-creates that dictionary, verifying the suppression of FileExistsError removes the directory afterwards """ path = os.getcwd() dirname = 'temptestfiledict' fulldirpath = os.path.join(path, dirname) # making sure that the directory does not pre-exist self.assertFalse(os.path.isdir(fulldirpath)) try: # this creates the directory self.assertIsInstance(FileDict('temptestfiledict'), FileDict) # asserting the directory was created self.assertTrue(os.path.isdir(fulldirpath)) # re-creating a Filedict in that directory self.assertIsInstance(FileDict('temptestfiledict'), FileDict) # asserting the directory still exists self.assertTrue(os.path.isdir(fulldirpath)) finally: if os.path.isdir(fulldirpath): os.rmdir(fulldirpath) # verifies the directory was successfully removed self.assertFalse(os.path.isdir(fulldirpath))
def setUp(self): tempfdddirname = 'tempfiledotdict' self.fdd = FileDotDict(tempfdddirname) self.tempfdddirname = FileDotDict.prefix + tempfdddirname tempdirname = 'tempdirname' self.fd = FileDict(tempdirname) self.tempdirname = FileDict.prefix + tempdirname self.data_pairs_0 = [('a', 'abstract'), ('b', 'binary'), ('c', 'collection'), ('d', 'dependency')] self.data_pairs_1 = [('a', 'absolute'), ('c', 'collection'), ('g', 'graph'), ('t', 'tree')] self.expected_0_update_1 = {'a': 'absolute', 'b': 'binary', 'c': 'collection', 'd': 'dependency', 'g': 'graph', 't': 'tree'} self.expected_1_update_0 = {'a': 'abstract', 'c': 'collection', 'g': 'graph', 't': 'tree', 'b': 'binary', 'd': 'dependency'}
def setUp(self) -> None: """ creates a self removing temporary directory where tests are conducted creates a FileDict data structure that writes into this directory :return: None """ self.tmpdirtest = tempfile.TemporaryDirectory() self.fdd = FileDict(self.tmpdirtest.name) self.tempdirname = self.prefix + self.tmpdirtest.name
def test_fd_update_fd(self): """updates a FileDict with a FileDict """ # creates a new local temp FileDict tempdirname = 'tempdict' fd = FileDict(tempdirname) tempdirname = FileDict.prefix + tempdirname self._populate(self.fd, self.data_pairs_0) self._populate(fd, self.data_pairs_1) self.fd.update(fd) self.assertEqual(self.fd, self.expected_0_update_1) shutil.rmtree(tempdirname)
def test_fd_update_fd_not_any_startswith_dot(self): """updates a FileDict with a FileDict verifies the directory contains no dotted files """ # creates a new local temp FileDict tempdirname = 'tempdict' fd = FileDict(tempdirname) tempdirname = FileDict.prefix + tempdirname self._populate(self.fd, self.data_pairs_0) self._populate(fd, self.data_pairs_1) self.fd.update(fd) self.assertTrue(not any(elt.startswith('.') for elt in os.listdir(self.tempdirname))) shutil.rmtree(tempdirname)
def test_type_in_non_existent_directory(self): """ creates a FileDict in a new directory making sure that the directory does not pre-exist, and removes it afterwards """ path = os.getcwd() dirname = 'temptestfiledict' fulldirpath = os.path.join(path, dirname) # making sure that the directory does not pre-exist self.assertFalse(os.path.isdir(fulldirpath)) try: # this creates the directory self.assertIsInstance(FileDict('temptestfiledict'), FileDict) # asserting the directory was created self.assertTrue(os.path.isdir(fulldirpath)) finally: if os.path.isdir(fulldirpath): os.rmdir(fulldirpath) # verifies the directory was successfully removed self.assertFalse(os.path.isdir(fulldirpath))