From 41ee931bc6fe156b115903cd4c91c1a5a643ba22 Mon Sep 17 00:00:00 2001 From: di1ara Date: Mon, 17 Jul 2023 20:02:52 -0400 Subject: [PATCH 1/4] add tests for brokers.toml file --- piker/config.py | 2 +- tests/conftest.py | 5 +++-- tests/test_configs.py | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 tests/test_configs.py diff --git a/piker/config.py b/piker/config.py index e2c63ea4..ab8e0dd7 100644 --- a/piker/config.py +++ b/piker/config.py @@ -427,7 +427,7 @@ def load_accounts( ) -> bidict[str, str | None]: - conf, path = load() + conf, path = load(touch_if_dne=True) accounts = bidict() for provider_name, section in conf.items(): accounts_section = section.get('accounts') diff --git a/tests/conftest.py b/tests/conftest.py index 366d5d95..10be9ef6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -174,13 +174,14 @@ def tmpconfdir( ) assert path.is_file(), 'WTH.. `brokers.toml` not created!?' - return tmpconfdir + yield tmpconfdir # NOTE: the `tmp_dir` fixture will wipe any files older then 3 test # sessions by default: # https://docs.pytest.org/en/6.2.x/tmpdir.html#the-default-base-temporary-directory # BUT, if we wanted to always wipe conf dir and all contained files, - # rmtree(str(tmp_path)) + from shutil import rmtree + rmtree(str(tmp_path)) @pytest.fixture diff --git a/tests/test_configs.py b/tests/test_configs.py new file mode 100644 index 00000000..38d48fe8 --- /dev/null +++ b/tests/test_configs.py @@ -0,0 +1,19 @@ +from pathlib import Path + +from piker import config + + +def test_root_conf_networking_section( + +): + # load account names from ``brokers.toml`` + accounts_def = config.load_accounts( + providers=['binans'], + ) + # import pdbp; pdbp.set_trace() + + + + + + \ No newline at end of file From 390faeef46f27695e1ed3c0d41a654e5653a1040 Mon Sep 17 00:00:00 2001 From: di1ara Date: Wed, 19 Jul 2023 15:09:32 -0400 Subject: [PATCH 2/4] deleted the comment and white spaces --- tests/test_configs.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/tests/test_configs.py b/tests/test_configs.py index 38d48fe8..231e3471 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -3,17 +3,8 @@ from pathlib import Path from piker import config -def test_root_conf_networking_section( - -): +def test_root_conf_networking_section(): # load account names from ``brokers.toml`` accounts_def = config.load_accounts( - providers=['binans'], - ) - # import pdbp; pdbp.set_trace() - - - - - - \ No newline at end of file + providers=['binance'], + ) \ No newline at end of file From 5fd0e5020f0ecad0753883938b3cf8b5b56c63fc Mon Sep 17 00:00:00 2001 From: di1ara Date: Thu, 20 Jul 2023 13:38:33 -0400 Subject: [PATCH 3/4] changed the function name and added a doc string explaining --- tests/conftest.py | 4 ++-- tests/test_configs.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 10be9ef6..6f170615 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -180,8 +180,8 @@ def tmpconfdir( # sessions by default: # https://docs.pytest.org/en/6.2.x/tmpdir.html#the-default-base-temporary-directory # BUT, if we wanted to always wipe conf dir and all contained files, - from shutil import rmtree - rmtree(str(tmp_path)) + # from shutil import rmtree + # rmtree(str(tmp_path)) @pytest.fixture diff --git a/tests/test_configs.py b/tests/test_configs.py index 231e3471..530c282b 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -1,9 +1,14 @@ +''' + testing the creation of brokers.toml if it doesn't exist, + issue was found when trying to run piker chart on windows. + +''' from pathlib import Path from piker import config -def test_root_conf_networking_section(): +def test_brokers_created_from_template_on_load_accounts(): # load account names from ``brokers.toml`` accounts_def = config.load_accounts( providers=['binance'], From 9c470846a6a93bc5bbece9cac2df9bbdcc408e46 Mon Sep 17 00:00:00 2001 From: di1ara Date: Thu, 20 Jul 2023 13:45:50 -0400 Subject: [PATCH 4/4] added the error name --- tests/test_configs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_configs.py b/tests/test_configs.py index 530c282b..a1fee2cd 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -1,6 +1,6 @@ ''' testing the creation of brokers.toml if it doesn't exist, - issue was found when trying to run piker chart on windows. + FileNotFoundError was found when trying to run piker chart on windows. ''' from pathlib import Path