diff --git a/pysus/ftp/__init__.py b/pysus/ftp/__init__.py index 134960b..b118e41 100644 --- a/pysus/ftp/__init__.py +++ b/pysus/ftp/__init__.py @@ -64,7 +64,12 @@ def __init__(self, path: str, name: str, info: dict) -> None: if path.endswith("/") else path + "/" + self.basename ) - self.parent_path = self.path.replace(self.basename, "") + ppath = self.path.replace(self.basename, "") + self.parent_path = ( + ppath[:-1] + if ppath.endswith("/") + else ppath + ) self.__info__ = info def __str__(self) -> str: diff --git a/pysus/tests/test_ftp/test_File.py b/pysus/tests/test_ftp/test_File.py index 5752e41..83b2240 100644 --- a/pysus/tests/test_ftp/test_File.py +++ b/pysus/tests/test_ftp/test_File.py @@ -6,5 +6,58 @@ """ import unittest import datetime +from pathlib import Path -from pysus.ftp import File +import pandas as pd + +from pysus.ftp import File, CACHEPATH +from pysus.data.local import ParquetSet + + +class TestFile(unittest.TestCase): + + def setUp(self): + path = "/dissemin/publicos/SIM/CID10/DORES/" + name = "DOAC1996.dbc" + info = { + "size": 76107, + "type": "file", + "modify": datetime.datetime(2020, 1, 31, 14, 48) + } + + self.file = File(path, name, info) + + def test_file_initialization(self): + file = self.file + + expected_path = "/dissemin/publicos/SIM/CID10/DORES/DOAC1996.dbc" + self.assertEqual(file.path, expected_path) + + self.assertEqual(file.name, "DOAC1996") + + self.assertEqual(file.extension, ".dbc") + + self.assertEqual(file.basename, "DOAC1996.dbc") + + expected_info = { + 'size': '76.1 kB', + 'type': 'DBC file', + 'modify': '2020-01-31 02:48PM' + } + self.assertEqual(file.info, expected_info) + + def test_file_download(self): + parquet = self.file.download() + + self.assertIsInstance(parquet, ParquetSet) + + self.assertTrue("size" in parquet.info) + + local_cache = Path(CACHEPATH) + expected_local_path = local_cache / "DOAC1996.parquet" + self.assertTrue(expected_local_path.exists()) + self.assertEqual(Path(str(parquet)), expected_local_path) + + df = parquet.to_dataframe() + self.assertIsInstance(df, pd.DataFrame) + self.assertFalse(df.empty) diff --git a/pysus/tests/test_ibge.py b/pysus/tests/test_ibge.py index 3c725b4..3948dd7 100644 --- a/pysus/tests/test_ibge.py +++ b/pysus/tests/test_ibge.py @@ -12,7 +12,7 @@ def test_get_aggregates(self): self.assertIsInstance(df, pd.DataFrame) self.assertGreater(df.size, 0) - @pytest.mark.timeout(120) + @pytest.mark.skip(reason="This test takes too long") def test_localidades_por_agregado(self): df = IBGE.localidades_por_agregado(475, nivel='N3') self.assertIsInstance(df, pd.DataFrame) @@ -31,7 +31,7 @@ def test_get_sidra_table(self): self.assertIsInstance(df, pd.DataFrame) self.assertGreater(df.size, 0) - @pytest.mark.timeout(120) + @pytest.mark.skip(reason="This test takes too long") def test_metadata(self): md = IBGE.metadados(475) self.assertIsInstance(md, dict)