-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
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.