Error handling for custom files when folder not present. (#1534)

* Error handling for custom files when folder not present.`

* Test the new load

Co-authored-by: didierlopes.eth <dro.lopes@campus.fct.unl.pt>
This commit is contained in:
jmaslek
2022-03-23 09:26:34 -04:00
committed by GitHub
parent 5d184bd1be
commit d5eb7ed436
6 changed files with 27 additions and 5 deletions

Binary file not shown.

View File

@@ -422,11 +422,6 @@ class StockBaseController(BaseController, metaclass=ABCMeta):
"--file",
default=None,
help="Path to load custom file.",
choices=[
x
for x in os.listdir(os.path.join("custom_imports", "stocks"))
if x.endswith(".csv")
],
dest="filepath",
type=str,
)
@@ -478,6 +473,21 @@ class StockBaseController(BaseController, metaclass=ABCMeta):
monthly=ns_parser.monthly,
)
else:
# This seems to block the .exe since the folder needs to be manually created
# This block basically makes sure that we only look for the file if the -f flag is used
# If we add files in the argparse choices, it will fail for the .exe even if no -f is used
try:
if ns_parser.filepath not in os.listdir(
os.path.join("custom_imports", "stocks")
):
console.print(
f"[red]{ns_parser.filepath} not found in custom_imports/stocks/ folder[/red].\n"
)
return
except Exception as e:
console.print(e)
return
df_stock_candidate = stocks_helper.load_custom(
os.path.join(
os.path.join("custom_imports", "stocks"), ns_parser.filepath

View File

@@ -102,6 +102,16 @@ def test_load_custom_output(path):
stocks_helper.load_custom(path)
@pytest.mark.vcr
@pytest.mark.record_stdout
@pytest.mark.parametrize(
"path",
[os.path.join(os.path.join("random_folder", "test69.csv"))],
)
def test_load_custom_output_wrong_path(path):
stocks_helper.load_custom(path)
@pytest.mark.vcr
@pytest.mark.parametrize(
"path",

View File

@@ -0,0 +1,2 @@
[red]File path does not exist.[/red]