mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 05:21:48 +00:00
* modify export function to user data function * change to exports * change i18n * be able to change user data folder * black * add exports to paths_helper * black * minor fixes * fix * small change to exports * fix * exports changes * fix export * fix reports export * black * minor changes * fix test * fix dcf export * type ignore * black * pylint * fix tests Co-authored-by: Chavithra <chavithra@gmail.com>
100 lines
2.6 KiB
Python
100 lines
2.6 KiB
Python
# IMPORTATION STANDARD
|
|
from pathlib import Path
|
|
|
|
# IMPORTATION THIRDPARTY
|
|
import pandas as pd
|
|
import pytest
|
|
|
|
# IMPORTATION INTERNAL
|
|
from openbb_terminal.helper_funcs import export_data
|
|
|
|
# pylint: disable=E1101
|
|
# pylint: disable=W0603
|
|
# pylint: disable=E1111
|
|
# pylint: disable=W0621
|
|
# pylint: disable=W0613
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_compose_export_path(monkeypatch, tmp_path):
|
|
# files in tmp_dir will remain (in separate folders) for 3 sequential runs of pytest
|
|
def mock_return(func_name, *args, **kwargs):
|
|
return tmp_path / f"20220829_235959_{func_name}"
|
|
|
|
monkeypatch.setattr("openbb_terminal.helper_funcs.compose_export_path", mock_return)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"export_type, dir_path, func_name, df",
|
|
[
|
|
(
|
|
"csv",
|
|
"C:/openbb_terminal/common/behavioural_analysis",
|
|
"queries",
|
|
pd.DataFrame(),
|
|
),
|
|
(
|
|
"json",
|
|
"C:/openbb_terminal/common/behavioural_analysis",
|
|
"queries",
|
|
pd.DataFrame(),
|
|
),
|
|
(
|
|
"xlsx",
|
|
"C:/openbb_terminal/common/behavioural_analysis",
|
|
"queries",
|
|
pd.DataFrame(),
|
|
),
|
|
(
|
|
"png",
|
|
"C:/openbb_terminal/common/behavioural_analysis",
|
|
"queries",
|
|
pd.DataFrame(),
|
|
),
|
|
(
|
|
"jpg",
|
|
"C:/openbb_terminal/common/behavioural_analysis",
|
|
"queries",
|
|
pd.DataFrame(),
|
|
),
|
|
(
|
|
"pdf",
|
|
"C:/openbb_terminal/common/behavioural_analysis",
|
|
"queries",
|
|
pd.DataFrame(),
|
|
),
|
|
(
|
|
"svg",
|
|
"C:/openbb_terminal/common/behavioural_analysis",
|
|
"queries",
|
|
pd.DataFrame(),
|
|
),
|
|
],
|
|
)
|
|
def test_export_data_filetypes(
|
|
mock_compose_export_path, export_type, dir_path, func_name, df, tmp_path
|
|
):
|
|
export_data(export_type, dir_path, func_name, df)
|
|
|
|
assert Path(tmp_path / f"20220829_235959_{func_name}.{export_type}").exists()
|
|
# TODO add assertions to check the validity of the files?
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"export_type, dir_path, func_name, data",
|
|
[
|
|
(
|
|
# Dict instead of DataFrame
|
|
"csv",
|
|
"C:/openbb_terminal/common/behavioural_analysis",
|
|
"queries",
|
|
dict({"test": "dict"}),
|
|
),
|
|
],
|
|
)
|
|
def test_export_data_invalid_data(
|
|
mock_compose_export_path, export_type, dir_path, func_name, data
|
|
):
|
|
with pytest.raises(AttributeError):
|
|
assert export_data(export_type, dir_path, func_name, data)
|