Skip to content

Commit

Permalink
Create tests_data_sources for unnittests
Browse files Browse the repository at this point in the history
  • Loading branch information
esloch committed Dec 5, 2023
1 parent 9382b9a commit ce39546
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ jobs:
run: |
make run-jupyter-pysus
- name: Test unnittest
run: |
pytest -vv pysus/tests/test_init.py
- name: Test with pytest
run: |
make conda-install-geo
Expand Down
9 changes: 4 additions & 5 deletions pysus/online_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ def list_data_sources() -> str:
"""

databases_directory = (
Path(__file__).resolve(strict=True).parent.parent
/ "ftp"
/ "databasess"
Path(__file__).resolve(strict=True).parent.parent / "ftp" / "databases"
)

if databases_directory.exists():
Expand All @@ -162,7 +160,7 @@ def list_data_sources() -> str:
for file in databases_directory.glob("*.py")
if file.name != "__init__.py"
]

# breakpoint()
return f"""Currently, the supported databases are: {
', '.join(supported_databases)}"""
else:
Expand All @@ -176,7 +174,8 @@ def list_data_sources() -> str:
"CNES",
"CIHA",
]
return f"""No support for the databases of DATASUS was found."
# breakpoint()
return f"""No support for the databases was found."
"Expected databases for implementation are: {
', '.join(expected_databases)}"""

Expand Down
38 changes: 33 additions & 5 deletions pysus/tests/test_init.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import unittest
import pytest
from unittest.mock import patch

import numpy as np
import pandas as pd
from numpy import dtype
from pysus.online_data import FTP_Inspect
import pytest
from pysus import online_data


class TestInitFunctions(unittest.TestCase):
Expand All @@ -20,12 +21,39 @@ def test_last_update(self):
"CNES",
"CIHA",
]:
df = FTP_Inspect(db).last_update_df()
df = online_data.FTP_Inspect(db).last_update_df()
self.assertIsInstance(df, pd.DataFrame)
self.assertGreater(df.size, 0)
self.assertIn("folder", df.columns)
self.assertIsInstance(df["date"][0], pd.Timestamp)
self.assertEqual(df.file_size.dtype, dtype("int64"))
self.assertEqual(df.file_size.dtype, np.dtype("int64"))


class TestListDataSources(unittest.TestCase):
@patch("pysus.online_data.Path.exists")
def test_list_data_sources_exists(self, mock_exists):
dbs = "SIM, SIA, SINAN, SINASC, SIH, CNES"
mock_exists.return_value = True
expected_output = f"""Currently, the supported databases are: {dbs}"""
self.assertEqual(online_data.list_data_sources(), expected_output)

@patch("pysus.online_data.Path.exists")
def test_list_data_sources_not_exists(self, mock_exists):
mock_exists.return_value = False
expected_databases = [
"SINAN",
"SIM",
"SINASC",
"SIH",
"SIA",
"PNI",
"CNES",
"CIHA",
]
expected_output = f"""No support for the databases was found."
"Expected databases for implementation are: {
', '.join(expected_databases)}"""
self.assertEqual(online_data.list_data_sources(), expected_output)


if __name__ == "__main__":
Expand Down

0 comments on commit ce39546

Please sign in to comment.