load_test
Full documentation pages are generated for docstring
reference only and may contain symbols imported from other
modules. Imported symbols are not distinguished from locally
defined symbols and will appear in any module that they are
imported into. For better information on where symbols should
be imported from, review the sourcecode on the
github.
FoSpy._dev.testing.load_test
file_prompt
file_prompt(
title="Select an input file",
filetypes=[
("FOS files", "*.fos"),
("JSON files", "*.json"),
("All files", "*.*"),
],
)
Source code in FoSpy/_dev/testing/_utils.py
| def file_prompt(title="Select an input file", filetypes=[("FOS files", "*.fos"), ("JSON files", "*.json"), ("All files", "*.*")]):
root = Tk()
root.withdraw() # hide root window
filepath = filedialog.askopenfilename(
title=title,
filetypes=filetypes
)
if not filepath:
raise Exception("No file selected.")
return filepath
|
run
run(filepath=None, open_result=False)
Source code in FoSpy/_dev/testing/load_test.py
| def run(filepath=None, open_result=False):
if filepath is None:
print("\nNo file selected. Opening Prompt...")
filepath = file_prompt()
# --- Build output directory ---
filename = os.path.splitext(os.path.basename(filepath))[0]
extension = os.path.splitext(filepath)[1]
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
outdir = os.path.join("user_files","testing", f"{filename}_{timestamp}")
outdir = os.path.abspath(outdir)
os.makedirs(outdir, exist_ok=True)
original_copy = os.path.join(outdir, f"{filename}_original{extension}")
fos_out = os.path.join(outdir, f"{filename}_saved.fos")
json_out = os.path.join(outdir, f"{filename}_saved.json")
error_log = os.path.join(outdir, "error_log.txt")
# --- Copy original file BEFORE loading ---
shutil.copy2(filepath, original_copy)
# --- Processing ---
try:
my_synthesis = Synthesis.fromFile(filepath)
my_synthesis.save(fos_out)
my_synthesis.save(json_out)
print("\nProcessing complete.")
print(f"Original copied to: {original_copy}")
print(f"Saved: {fos_out}")
print(f"Saved: {json_out}")
except Exception:
with open(error_log, "w", encoding="utf-8") as f:
f.write(traceback.format_exc())
print(f"\nAn error occurred. See log:\n {error_log}")
if open_result:
from ._utils import open_file
open_file(outdir)
return True
|