-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish unittest -> pytest conversion (#4014)
* Refactor CsvExtractor unit tests for better test independence * Refactor unit tests for better test independence * Refactor unit tests for better test independence * Refactor unit tests for better test independence * Refactor unit tests for better test independence * Remove unnecessary IDE configuration files * [pre-commit.ci] auto fixes from pre-commit.com hooks For more information, see https://pre-commit.ci * Refactor excel_test.py for better test independence * Refactor excel_test.py for better test independence * [pre-commit.ci] auto fixes from pre-commit.com hooks For more information, see https://pre-commit.ci * Refactor excel_test.py for better test independence * Refactor excel_test.py for better test independance * [pre-commit.ci] auto fixes from pre-commit.com hooks For more information, see https://pre-commit.ci * Refactor classes_test.py for improved test organization * Refactor mocks in classes_test.py for improved readability * Convert unittest assertions to pytest style in resource_cache_test.py * Convert unittest assertions to pytest style in resource_cache_test.py * Convert unittest assertions to pytest style in resource_cache_test.py * chore: revert to old setup structure for ferc1 output test The main improvement I see to the test setup is to make the graph definitions more atomic. Currently we have the graph definitions split between node creation in setup and edge definition in the tests themselves. * [pre-commit.ci] auto fixes from pre-commit.com hooks For more information, see https://pre-commit.ci --------- Co-authored-by: Gaurav Gurjar <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Zane Selvans <[email protected]>
- Loading branch information
1 parent
d6bef30
commit 454ca96
Showing
6 changed files
with
277 additions
and
326 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,42 @@ | ||
"""Unit tests for pudl.extract.excel module.""" | ||
|
||
import unittest | ||
from unittest import mock as mock | ||
|
||
import pandas as pd | ||
import pytest | ||
|
||
from pudl.extract import excel | ||
|
||
|
||
class TestMetadata(unittest.TestCase): | ||
class TestMetadata: | ||
"""Tests basic operation of the excel.Metadata object.""" | ||
|
||
@pytest.fixture(autouse=True) | ||
def setUp(self): | ||
"""Cosntructs test metadata instance for testing.""" | ||
"""Constructs test metadata instance for testing.""" | ||
self._metadata = excel.ExcelMetadata("test") | ||
|
||
def test_basics(self): | ||
"""Test that basic API method return expected results.""" | ||
self.assertEqual("test", self._metadata.get_dataset_name()) | ||
self.assertListEqual( | ||
["books", "boxes", "shoes"], self._metadata.get_all_pages() | ||
) | ||
self.assertListEqual( | ||
["author", "pages", "title"], self._metadata.get_all_columns("books") | ||
) | ||
self.assertDictEqual( | ||
{"book_title": "title", "name": "author", "pages": "pages"}, | ||
self._metadata.get_column_map("books", year=2010), | ||
) | ||
self.assertEqual(10, self._metadata.get_skiprows("boxes", year=2011)) | ||
self.assertEqual(1, self._metadata.get_sheet_name("boxes", year=2011)) | ||
assert self._metadata.get_dataset_name() == "test" | ||
assert self._metadata.get_all_pages() == ["books", "boxes", "shoes"] | ||
assert self._metadata.get_all_columns("books") == ["author", "pages", "title"] | ||
assert self._metadata.get_column_map("books", year=2010) == { | ||
"book_title": "title", | ||
"name": "author", | ||
"pages": "pages", | ||
} | ||
assert self._metadata.get_skiprows("boxes", year=2011) == 10 | ||
assert self._metadata.get_sheet_name("boxes", year=2011) == 1 | ||
|
||
def test_metadata_methods(self): | ||
"""Test various metadata methods.""" | ||
assert self._metadata.get_all_columns("books") == ["author", "pages", "title"] | ||
assert self._metadata.get_column_map("books", year=2010) == { | ||
"book_title": "title", | ||
"name": "author", | ||
"pages": "pages", | ||
} | ||
assert self._metadata.get_skiprows("boxes", year=2011) == 10 | ||
assert self._metadata.get_sheet_name("boxes", year=2011) == 1 | ||
|
||
|
||
class FakeExtractor(excel.ExcelExtractor): | ||
|
@@ -77,11 +84,10 @@ def _fake_data_frames(page_name, **kwargs): | |
return fake_data[page_name] | ||
|
||
|
||
class TestExtractor(unittest.TestCase): | ||
class TestExtractor: | ||
"""Test operation of the excel.Extractor class.""" | ||
|
||
@staticmethod | ||
def test_extract(): | ||
def test_extract(self): | ||
extractor = FakeExtractor() | ||
res = extractor.extract(year=[2010, 2011]) | ||
expected_books = { | ||
|
@@ -103,7 +109,7 @@ def test_extract(): | |
# def test_resulting_dataframes(self): | ||
# """Checks that pages across years are merged and columns are translated.""" | ||
# dfs = FakeExtractor().extract([2010, 2011], testing=True) | ||
# self.assertEqual(set(['books', 'boxes']), set(dfs.keys())) | ||
# assert set(['books', 'boxes']) == set(dfs.keys()) | ||
# pd.testing.assert_frame_equal( | ||
# pd.DataFrame(data={ | ||
# 'author': ['Laozi', 'Benjamin Hoff'], | ||
|
@@ -118,5 +124,5 @@ def test_extract(): | |
# }), | ||
# dfs['boxes']) | ||
|
||
# TODO([email protected]): need to figure out how to test process_$x methods. | ||
# TODO([email protected]): we should test that empty columns are properly added. | ||
# TODO: need to figure out how to test process_$x methods. | ||
# TODO: we should test that empty columns are properly added. |
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
Oops, something went wrong.