-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testing passing for sources POPTCU and projpop
- Loading branch information
Showing
4 changed files
with
120 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import unittest | ||
from unittest.mock import MagicMock, patch | ||
from pysus.ftp.databases import ibge_datasus | ||
|
||
class IBGEDATASUSTests(unittest.TestCase): | ||
|
||
@patch('pysus.ftp.databases.ibge_datasus.File') | ||
def test_describe_zip_file(self, mock_file): | ||
mock_file.extension.upper.return_value = ".ZIP" | ||
mock_file.name = "POPBR12.zip" | ||
mock_file.info = {"size": 100, "modify": "2022-01-01"} | ||
|
||
ibge = ibge_datasus.IBGEDATASUS() | ||
result = ibge.describe(mock_file) | ||
|
||
self.assertEqual(result, { | ||
"name": "POPBR12", | ||
"year": "2012", | ||
"size": 100, | ||
"last_update": "2022-01-01" | ||
}) | ||
|
||
# @patch('pysus.ftp.databases.ibge_datasus.File') | ||
# def describe_dbf_file(self, mock_file): | ||
# mock_file.extension.upper.return_value = ".DBF" | ||
# mock_file.name = "file20.dbf" | ||
# mock_file.info = {"size": 100, "modify": "2022-01-01"} | ||
# | ||
# ibge = ibge_datasus.IBGEDATASUS() | ||
# result = ibge.describe(mock_file) | ||
# | ||
# self.assertEqual(result, { | ||
# "name": "file20", | ||
# "year": "2020", | ||
# "size": 100, | ||
# "last_update": "2022-01-01" | ||
# }) | ||
|
||
# @patch('pysus.ftp.databases.ibge_datasus.File') | ||
# def describe_other_file(self, mock_file): | ||
# mock_file.extension.upper.return_value = ".TXT" | ||
# mock_file.name = "file20.txt" | ||
# | ||
# ibge = ibge_datasus.IBGEDATASUS() | ||
# result = ibge.describe(mock_file) | ||
# | ||
# self.assertEqual(result, {}) | ||
|
||
@patch('pysus.ftp.databases.ibge_datasus.File') | ||
def format_file(self, mock_file): | ||
mock_file.name = "file20.zip" | ||
|
||
ibge = ibge_datasus.IBGEDATASUS() | ||
result = ibge.format(mock_file) | ||
|
||
self.assertEqual(result, "20.zip") | ||
|
||
@patch('pysus.ftp.databases.ibge_datasus.File') | ||
@patch('pysus.ftp.databases.ibge_datasus.to_list') | ||
def test_get_files_with_year(self, mock_to_list, mock_file): | ||
mock_file.extension.upper.return_value = ".ZIP" | ||
mock_file.name = "POPBR12.zip" | ||
mock_to_list.return_value = ["2012"] | ||
|
||
ibge = ibge_datasus.IBGEDATASUS() | ||
ibge.__content__ = {"POPBR12.zip": mock_file} | ||
result = ibge.get_files(year="2012") | ||
|
||
self.assertEqual(result, [mock_file]) | ||
|
||
@patch('pysus.ftp.databases.ibge_datasus.File') | ||
def get_files_without_year(self, mock_file): | ||
mock_file.extension.upper.return_value = ".ZIP" | ||
mock_file.name = "file20.zip" | ||
|
||
ibge = ibge_datasus.IBGEDATASUS() | ||
ibge.files = [mock_file] | ||
result = ibge.get_files() | ||
|
||
self.assertEqual(result, [mock_file]) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters