Python os.remove() Examples
The following are 30
code examples of os.remove().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.

Example #1
Source File: test_party.py From indras_net with GNU General Public License v3.0 | 10 votes |
def test_props_write(self): announce('test_props_write') report = True self.env.pwrite(self.env.model_nm + ".props") with open(self.env.model_nm + ".props", "r") as f: props_written = json.load(f) if len(props_written) != len(self.env.props.props): report = False if report: for key in props_written: if key not in self.env.props.props: report = False break else: if props_written[key]["val"] != self.env.props.props[key].val: report = False break f.close() os.remove(self.env.model_nm + ".props") self.assertEqual(report, True)
Example #2
Source File: test_forestfire.py From indras_net with GNU General Public License v3.0 | 8 votes |
def test_props_write(self): announce('test_props_write') report = True self.env.pwrite(self.env.model_nm + ".props") with open(self.env.model_nm + ".props", "r") as f: props_written = json.load(f) if len(props_written) != len(self.env.props.props): report = False if report: for key in props_written: if key not in self.env.props.props: report = False break else: if props_written[key]["val"] != self.env.props.props[key].val: report = False break f.close() os.remove(self.env.model_nm + ".props") self.assertEqual(report, True)
Example #3
Source File: test_basic.py From indras_net with GNU General Public License v3.0 | 7 votes |
def test_props_write(self): announce('test_props_write') report = True self.env.pwrite(self.env.model_nm + ".props") with open(self.env.model_nm + ".props", "r") as f: props_written = json.load(f) if len(props_written) != len(self.env.props.props): report = False if report: for key in props_written: if key not in self.env.props.props: report = False break else: if props_written[key]["val"] != self.env.props.props[key].val: report = False break f.close() os.remove(self.env.model_nm + ".props") self.assertEqual(report, True)
Example #4
Source File: test_basic.py From indras_net with GNU General Public License v3.0 | 7 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #5
Source File: test_coop.py From indras_net with GNU General Public License v3.0 | 7 votes |
def test_props_write(self): announce('test_props_write') report = True self.env.pwrite(self.env.model_nm + ".props") with open(self.env.model_nm + ".props", "r") as f: props_written = json.load(f) if len(props_written) != len(self.env.props.props): report = False if report: for key in props_written: if key not in self.env.props.props: report = False break else: if props_written[key]["val"] != self.env.props.props[key].val: report = False break f.close() os.remove(self.env.model_nm + ".props") self.assertEqual(report, True)
Example #6
Source File: test_hiv.py From indras_net with GNU General Public License v3.0 | 7 votes |
def test_props_write(self): announce('test_props_write') report = True self.env.pwrite(self.env.model_nm + '.props') with open(self.env.model_nm + '.props', 'r') as f: props_written = json.load(f) if len(props_written) != len(self.env.props.props): report = False if report: for key in props_written: if key not in self.env.props.props: report = False break elif (props_written[key]["val"] != self.env.props.props[key].val): report = False break f.close() os.remove(self.env.model_nm + ".props") self.assertEqual(report, True)
Example #7
Source File: test_hiv.py From indras_net with GNU General Public License v3.0 | 7 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #8
Source File: test_fmarket.py From indras_net with GNU General Public License v3.0 | 7 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #9
Source File: test_gridang.py From indras_net with GNU General Public License v3.0 | 7 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #10
Source File: views_main.py From everyclass-server with Mozilla Public License 2.0 | 7 votes |
def exit_maintenance(): config = get_config() auth = request.authorization if auth \ and auth.username in config.MAINTENANCE_CREDENTIALS \ and config.MAINTENANCE_CREDENTIALS[auth.username] == auth.password: try: os.remove(config.MAINTENANCE_FILE) # remove maintenance file except OSError: return 'Not in maintenance mode. Ignore command.' open(os.path.join(os.getcwd(), 'reload'), "w+").close() # uwsgi reload return 'success' else: return Response( 'Could not verify your access level for that URL.\n' 'You have to login with proper credentials', 401, {'WWW-Authenticate': 'Basic realm="Login Required"'})
Example #11
Source File: test_party.py From indras_net with GNU General Public License v3.0 | 6 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #12
Source File: test_forestfire.py From indras_net with GNU General Public License v3.0 | 6 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #13
Source File: test_wolfsheep.py From indras_net with GNU General Public License v3.0 | 6 votes |
def test_props_write(self): announce('test_props_write') report = True self.env.pwrite(self.env.model_nm + ".props") with open(self.env.model_nm + ".props", "r") as f: props_written = json.load(f) if len(props_written) != len(self.env.props.props): report = False if report: for key in props_written: if key not in self.env.props.props: report = False break else: if props_written[key]["val"] != self.env.props.props[key].val: report = False break f.close() os.remove(self.env.model_nm + ".props") self.assertEqual(report, True)
Example #14
Source File: test_wolfsheep.py From indras_net with GNU General Public License v3.0 | 6 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #15
Source File: test_grid.py From indras_net with GNU General Public License v3.0 | 6 votes |
def test_props_write(self): announce('test_props_write') report = True self.env.pwrite(self.env.model_nm + ".props") with open(self.env.model_nm + ".props", "r") as f: props_written = json.load(f) if len(props_written) != len(self.env.props.props): report = False if report: for key in props_written: if key not in self.env.props.props: report = False break else: if props_written[key]["val"] != self.env.props.props[key].val: report = False break f.close() os.remove(self.env.model_nm + ".props") self.assertEqual(report, True)
Example #16
Source File: test_gridang.py From indras_net with GNU General Public License v3.0 | 6 votes |
def test_props_write(self): announce('test_props_write') report = True self.env.pwrite(self.env.model_nm + ".props") with open(self.env.model_nm + ".props", "r") as f: props_written = json.load(f) if len(props_written) != len(self.env.props.props): report = False if report: for key in props_written: if key not in self.env.props.props: report = False break else: if props_written[key]["val"] != self.env.props.props[key].val: report = False break f.close() os.remove(self.env.model_nm + ".props") self.assertEqual(report, True)
Example #17
Source File: test_fashion.py From indras_net with GNU General Public License v3.0 | 6 votes |
def test_list_agents(self): announce('test_list_agents') report = True orig_out = sys.stdout sys.stdout = open("checkfile.txt", "w") self.env.list_agents() sys.stdout.close() sys.stdout = orig_out f = open("checkfile.txt", "r") line1 = f.readline() for agent in self.env.agents: line = f.readline() line_list = line.split(" with a goal of ") line_list[1] = line_list[1].strip() if agent.name != line_list[0] or agent.goal != line_list[1]: report = False break f.close() os.remove("checkfile.txt") self.assertEqual(report, True)
Example #18
Source File: __init__.py From ALF with Apache License 2.0 | 6 votes |
def do_iteration(self, mutation_fn, aggression): """ This method is called with an output mutation filename and a real aggression (see :ref:`aggression`) indicating the amount of aggression the fuzzing algorithm should use. *mutation_fn* is unique for every invokation of :meth:`do_iteration`. It is an error for this method not to write the mutated template to *mutation_fn* before returning a result. If a result is not found, the mutation filename may be written to if needed, but it is not required. If a notable result is found, it should be returned as a :class:`FuzzResult` instance. This will be stored and reported to the ALF central server at the next check-in interval. A return of None indicates a result was not found. The filenames of any temporary files or folders created during execution can be safely removed using :func:`alf.delete`. This is safer than using :func:`os.remove` or :func:`shutil.rmtree` directly. *mutation_fn* does not need to be deleted, it is cleaned up automatically. """ raise NotImplementedError()
Example #19
Source File: util.py From wechat-alfred-workflow with MIT License | 6 votes |
def atomic_writer(fpath, mode): """Atomic file writer. .. versionadded:: 1.12 Context manager that ensures the file is only written if the write succeeds. The data is first written to a temporary file. :param fpath: path of file to write to. :type fpath: ``unicode`` :param mode: sames as for :func:`open` :type mode: string """ suffix = '.{}.tmp'.format(os.getpid()) temppath = fpath + suffix with open(temppath, mode) as fp: try: yield fp os.rename(temppath, fpath) finally: try: os.remove(temppath) except (OSError, IOError): pass
Example #20
Source File: download_glue.py From BERT-Classification-Tutorial with Apache License 2.0 | 5 votes |
def download_and_extract(task, data_dir): print("Downloading and extracting %s..." % task) data_file = "%s.zip" % task urllib.request.urlretrieve(TASK2PATH[task], data_file) with zipfile.ZipFile(data_file) as zip_ref: zip_ref.extractall(data_dir) os.remove(data_file) print("\tCompleted!")
Example #21
Source File: test_agent_pop.py From indras_net with GNU General Public License v3.0 | 5 votes |
def test_remove(self): report = True self.agentpop.add_variety("dummy var") dummy_node = node.Node("dummy node") dummy_node.ntype = "dummy var" self.agentpop.append(dummy_node) self.agentpop.remove(dummy_node) if dummy_node in self.agentpop.vars['dummy var'][AGENTS]: report = False self.assertEqual(report, True)
Example #22
Source File: test_basic.py From indras_net with GNU General Public License v3.0 | 5 votes |
def test_examine_log(self): announce('test_examine_log') report = True logfile_name = self.env.props.props["model"].val + ".log" list_for_reference = deque(maxlen=16) with open(logfile_name, 'rt') as log: for line in log: list_for_reference.append(line) orig_out = sys.stdout sys.stdout = open("checklog.txt", "w") self.env.disp_log() sys.stdout.close() sys.stdout = orig_out f = open("checklog.txt", "r") first_line = f.readline().strip() first_line = first_line.split(" ") if logfile_name != first_line[-1]: report = False if report: for i, line in enumerate(f): if list_for_reference[i] != line: report = False break f.close() os.remove("checklog.txt") self.assertEqual(report, True)
Example #23
Source File: test_basic.py From indras_net with GNU General Public License v3.0 | 5 votes |
def test_save_session(self): announce('test_save_session') report = True rand_sess_id = random.randint(1, 10) try: base_dir = self.env.props["base_dir"] except: base_dir = "" self.env.save_session(rand_sess_id) path = base_dir + "json/" + self.env.model_nm + str(rand_sess_id) + ".json" with open(path, "r") as f: json_input = f.readline() json_input_dic = json.loads(json_input) if json_input_dic["period"] != self.env.period: report = False if json_input_dic["model_nm"] != self.env.model_nm: report = False if json_input_dic["preact"] != self.env.preact: report = False if json_input_dic["postact"] != self.env.postact: report = False if json_input_dic["props"] != self.env.props.to_json(): report = False #Here is why test_save_session fail before. #The env will generate a new prop_arg 2 type proparg when restoring #session(check env.from_json function), but # we were using old prop_arg in this test file. if json_input_dic["user"] != self.env.user.to_json(): report = False agents = [] for agent in self.env.agents: agents.append(agent.to_json()) if json_input_dic["agents"] != agents: report = False f.close() os.remove(path) self.assertEqual(report, True)
Example #24
Source File: test_coop.py From indras_net with GNU General Public License v3.0 | 5 votes |
def test_display_props(self): announce('test_display_props') report = True orig_out = sys.stdout sys.stdout = open("checkprops.txt", "w") self.env.disp_props() sys.stdout.close() sys.stdout = orig_out f = open("checkprops.txt", "r") title = f.readline() title_list = title.split(" for ") if self.env.model_nm != title_list[1].strip(): report = False dic_for_check = {} if report is True: for line in f: if line != "\n": line_list = line.split(": ") line_list[0] = line_list[0].strip() line_list[1] = line_list[1].strip() dic_for_check[line_list[0]] = line_list[1] for key in self.env.props.props: if str(self.env.props.props[key]) != dic_for_check[key]: report = False f.close() os.remove("checkprops.txt") self.assertEqual(report, True)
Example #25
Source File: test_coop.py From indras_net with GNU General Public License v3.0 | 5 votes |
def test_examine_log(self): announce('test_examine_log') report = True logfile_name = self.env.props.props["log_fname"].val list_for_reference = deque(maxlen=16) with open(logfile_name, 'rt') as log: for line in log: list_for_reference.append(line) orig_out = sys.stdout sys.stdout = open("checklog.txt", "w") self.env.disp_log() sys.stdout.close() sys.stdout = orig_out f = open("checklog.txt", "r") first_line = f.readline().strip() first_line = first_line.split(" ") if logfile_name != first_line[-1]: report = False if report: for i, line in enumerate(f): if list_for_reference[i] != line: report = False break f.close() os.remove("checklog.txt") self.assertEqual(report, True)
Example #26
Source File: test_hiv.py From indras_net with GNU General Public License v3.0 | 5 votes |
def test_display_props(self): announce('test_display_props') report = True orig_out = sys.stdout sys.stdout = open("checkprops.txt", "w") self.env.disp_props() sys.stdout.close() sys.stdout = orig_out f = open("checkprops.txt", "r") title = f.readline() title_list = title.split(" for ") if self.env.model_nm != title_list[1].strip(): report = False dic_for_check = {} if report is True: for line in f: if line != "\n": line_list = line.split(": ") line_list[0] = line_list[0].strip() line_list[1] = line_list[1].strip() dic_for_check[line_list[0]] = line_list[1] for key in self.env.props.props: if str(self.env.props.props[key]) != dic_for_check[key]: report = False f.close() os.remove("checkprops.txt") self.assertEqual(report, True)
Example #27
Source File: test_hiv.py From indras_net with GNU General Public License v3.0 | 5 votes |
def test_examine_log(self): announce('test_examine_log') report = True logfile_name = self.env.props.props["log_fname"].val list_for_reference = deque(maxlen=16) with open(logfile_name, 'rt') as log: for line in log: list_for_reference.append(line) orig_out = sys.stdout sys.stdout = open("checklog.txt", "w") self.env.disp_log() sys.stdout.close() sys.stdout = orig_out f = open("checklog.txt", "r") first_line = f.readline().strip() first_line = first_line.split(" ") if logfile_name != first_line[-1]: report = False if report: for i, line in enumerate(f): if list_for_reference[i] != line: report = False break f.close() os.remove("checklog.txt") self.assertEqual(report, True)
Example #28
Source File: test_hiv.py From indras_net with GNU General Public License v3.0 | 5 votes |
def test_save_session(self): announce('test_save_session') report = True rand_sess_id = random.randint(1, 10) try: base_dir = self.env.props["base_dir"] except: base_dir = "" self.env.save_session(rand_sess_id) path = (base_dir + "json/" + self.env.model_nm + str(rand_sess_id) + ".json") with open(path, "r") as f: json_input = f.readline() json_input_dic = json.loads(json_input) if json_input_dic["period"] != self.env.period: report = False if json_input_dic["model_nm"] != self.env.model_nm: report = False if json_input_dic["preact"] != self.env.preact: report = False if json_input_dic["postact"] != self.env.postact: report = False if json_input_dic["props"] != self.env.props.to_json(): report = False if json_input_dic["user"] != self.env.user.to_json(): report = False agents = [] for agent in self.env.agents: agents.append(agent.to_json()) f.close() os.remove(path) self.assertEqual(report, True)
Example #29
Source File: test_hiv.py From indras_net with GNU General Public License v3.0 | 5 votes |
def test_restore_session(self): announce('test_restore_session') report = True rand_sess_id = random.randint(1, 10) try: base_dir = self.env.props["base_dir"] except: base_dir = "" self.env.save_session(rand_sess_id) self.env.n_steps(random.randint(1, 10)) self.env.restore_session(rand_sess_id) path = (base_dir + "json/" + self.env.model_nm + str(rand_sess_id) + ".json") with open(path, "r") as f: json_input = f.readline() json_input_dic = json.loads(json_input) if json_input_dic["period"] != self.env.period: report = False if json_input_dic["model_nm"] != self.env.model_nm: report = False if json_input_dic["preact"] != self.env.preact: report = False if json_input_dic["postact"] != self.env.postact: report = False if json_input_dic["props"] != self.env.props.to_json(): report = False if json_input_dic["user"] != self.env.user.to_json(): report = False agents = [] for agent in self.env.agents: agents.append(agent.to_json()) os.remove(path) f.close() self.assertEqual(report, True)
Example #30
Source File: test_fmarket.py From indras_net with GNU General Public License v3.0 | 5 votes |
def test_display_props(self): announce('test_display_props') report = True orig_out = sys.stdout sys.stdout = open("checkprops.txt", "w") self.env.disp_props() sys.stdout.close() sys.stdout = orig_out f = open("checkprops.txt", "r") title = f.readline() title_list = title.split(" for ") if self.env.model_nm != title_list[1].strip(): report = False dic_for_check = {} if report is True: for line in f: if line != "\n": line_list = line.split(": ") line_list[0] = line_list[0].strip() line_list[1] = line_list[1].strip() dic_for_check[line_list[0]] = line_list[1] for key in self.env.props.props: if str(self.env.props.props[key]) != dic_for_check[key]: report = False f.close() os.remove("checkprops.txt") self.assertEqual(report, True)