mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-13 04:41:24 +00:00
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:
BIN
.coverage.Colins-Air.indiana.edu.21211.834887
vendored
BIN
.coverage.Colins-Air.indiana.edu.21211.834887
vendored
Binary file not shown.
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
[red]File path does not exist.[/red]
|
||||
|
||||
Reference in New Issue
Block a user