Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #48 from hamishgibbs/tests
Browse files Browse the repository at this point in the history
Tests
  • Loading branch information
hamishgibbs authored Jan 11, 2021
2 parents 5dac957 + f137f78 commit 02ad0b8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pull_fb/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def download_data(download_urls: list,
# Close progress bar
bar.finish()

print('Failed to download {} files. Please try again later.'.format(len(download_failed)))
if len(download_failed) > 0:

print('Failed to download {} files. Please try again later.'.format(len(download_failed)))


def write_outfile(resp: requests.Response, out_fn: str, download_failed: list):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ def test_credentials_filled():
res = credentials.get_credentials('a', 'b')

assert type(res) is dict


def test_credentials_usenrame_none(monkeypatch):

monkeypatch.setattr('builtins.input', lambda _: "[email protected]")

# go about using input() like you normally would:
res = credentials.get_credentials(None, 'b')

assert type(res) is dict
assert res['email'] == "[email protected]"
22 changes: 22 additions & 0 deletions tests/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def __init__(self):
return Mock_Response()


@pytest.fixture(scope="session")
def tmp_path(tmpdir_factory):

path = tmpdir_factory.mktemp("tmp")

return path


def test_format_out_fn():

res = driver.format_out_fn('a', 'b', datetime(2000, 1, 1, 0))
Expand Down Expand Up @@ -69,3 +77,17 @@ def test_write_outfile(mock_csv_response):
assert type(res) is list

os.remove('test.csv')


# test download_data
def test_download_data_tmp_dir(tmp_path):

download_urls = [{"url": "https://github.com/hamishgibbs/uk_tier_data/raw/master/output/uk_tier_data_parliament_2020_10_25_1606.csv",
"date": datetime(2020, 3, 1, 0)}]

driver.download_data(download_urls,
"Britain",
str(tmp_path),
[])

assert os.path.exists(str(tmp_path) + '/Britain_2020_03_01_0000.csv')
2 changes: 0 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ deps = pytest
pandas
commands =
pytest

temp_dir = 'tmp'

0 comments on commit 02ad0b8

Please sign in to comment.