def test_remove_files(self): """Remove files functions as expected """ # create list of temp file paths test_filepaths = [ get_tmp_filename(prefix="remove_files_test") for i in range(5) ] # try to remove them with remove_files and verify that an IOError is # raises self.assertRaises(OSError, remove_files, test_filepaths) # now get no error when error_on_missing=False remove_files(test_filepaths, error_on_missing=False) # touch one of the filepaths so it exists open(test_filepaths[2], "w").close() # check that an error is raised on trying to remove the files... self.assertRaises(OSError, remove_files, test_filepaths) # ... but that the existing file was still removed self.assertFalse(exists(test_filepaths[2])) # touch one of the filepaths so it exists open(test_filepaths[2], "w").close() # no error is raised on trying to remove the files # (although 4 don't exist)... remove_files(test_filepaths, error_on_missing=False) # ... and the existing file was removed self.assertFalse(exists(test_filepaths[2]))
def test_tree_collection_read_write_file(self): """should correctly read / write a collection from a file""" def eval_klass(coll): coll.write("sample.trees") read = make_trees("sample.trees") self.assertTrue(type(read) == type(coll)) eval_klass(LogLikelihoodScoredTreeCollection(self.scored_trees)) # convert lnL into p eval_klass(WeightedTreeCollection([(exp(s), t) for s, t in self.scored_trees])) remove_files(["sample.trees"], error_on_missing=False)