Skip to content

Commit

Permalink
Merge pull request #16 from bug-or-feature/pr_tests
Browse files Browse the repository at this point in the history
better env check for creds
  • Loading branch information
bug-or-feature authored May 2, 2024
2 parents b28bdcc + 435a9a3 commit b3a5c7c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
14 changes: 12 additions & 2 deletions bcutils/tests/test_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def test_bad_credentials(self, download_dir):
)

def test_hourly(self, bc_config, download_dir):
print(bc_config.keys())
if len(bc_config) == 0:
pytest.skip("Skipping test, no Barchart credentials found in env")
else:
Expand All @@ -81,7 +82,7 @@ def test_hourly(self, bc_config, download_dir):
assert not csv.is_dir()

def test_daily(self, bc_config, download_dir):
if len(bc_config) == 0:
if not self._have_creds(bc_config):
pytest.skip("Skipping test, no Barchart credentials found in env")
else:
get_barchart_downloads(
Expand All @@ -100,7 +101,7 @@ def test_daily(self, bc_config, download_dir):
assert not csv.is_dir()

def test_insufficient(self, bc_config, download_dir):
if len(bc_config) == 0:
if not self._have_creds(bc_config):
pytest.skip("Skipping test, no Barchart credentials found in env")
else:
contract_key = "UPU14"
Expand All @@ -119,3 +120,12 @@ def test_insufficient(self, bc_config, download_dir):
)

assert result == HistoricalDataResult.INSUFFICIENT

@staticmethod
def _have_creds(config: dict):
return (
"barchart_username" in config
and config["barchart_username"]
and "barchart_password" in config
and config["barchart_password"]
)
13 changes: 7 additions & 6 deletions sample/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
_env,
)
from bcutils.migrate import migrate_to_multi_freq
from bcutils.config import CONTRACT_MAP

logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -122,14 +123,14 @@ def update_hourly_file():
)


def update_daily_file():
# update the daily AUD Mar 2024 price file in the current working directory
contract_map = {"AUD": {"code": "A6", "cycle": "HMUZ", "exchange": "CME"}}
def update_daily_file(contract_key, config=None):
if config is None:
config = CONTRACT_MAP
update_barchart_contract_file(
create_bc_session(config_obj=_env()),
_build_inverse_map(contract_map),
config,
os.getcwd(),
"A6H24",
contract_key,
Resolution.Day,
)

Expand All @@ -153,5 +154,5 @@ def rename_files_with_new_format():
# save_hourly("CHFJPY", "UPU14")
# update_downloads()
# update_hourly_file()
# update_daily_file()
# update_daily_file("EPM24")
# rename_files_with_new_format()

0 comments on commit b3a5c7c

Please sign in to comment.