Skip to content

Commit

Permalink
Refactor csv_test.py to use mocker for CsvExtractor and clean up exce…
Browse files Browse the repository at this point in the history
…l_test.py by removing commented-out code
  • Loading branch information
ggurjar333 committed Dec 3, 2024
1 parent 474902f commit e71dcaa
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 237 deletions.
10 changes: 4 additions & 6 deletions test/unit/extract/csv_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Pytest for pudl.extract.csv module."""

from unittest.mock import MagicMock

import pandas as pd
import pytest

Expand All @@ -16,16 +14,16 @@


class FakeExtractor(CsvExtractor):
def __init__(self):
def __init__(self, ds):
# TODO: Make these tests independent of the eia176 implementation
self.METADATA = GenericMetadata("eia176")
super().__init__(ds=MagicMock())
super().__init__(ds=ds)


@pytest.fixture
def extractor():
def extractor(mocker):
# Create an instance of the CsvExtractor class
return FakeExtractor()
return FakeExtractor(mocker.MagicMock())


def test_source_filename_valid_partition(extractor):
Expand Down
22 changes: 0 additions & 22 deletions test/unit/extract/excel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,3 @@ def test_extract(self, extractor):
"size": {0: 10, 1: 99},
}
assert expected_boxes == res["boxes"].to_dict()

# @patch('pudl.extract.excel.pd.read_excel', _fake_data_frames)
# def test_resulting_dataframes(self):
# """Checks that pages across years are merged and columns are translated."""
# dfs = FakeExtractor().extract([2010, 2011], testing=True)
# assert set(['books', 'boxes']) == set(dfs.keys())
# pd.testing.assert_frame_equal(
# pd.DataFrame(data={
# 'author': ['Laozi', 'Benjamin Hoff'],
# 'pages': [0, 158],
# 'title': ['Tao Te Ching', 'The Tao of Pooh'],
# }),
# dfs['books'])
# pd.testing.assert_frame_equal(
# pd.DataFrame(data={
# 'material': ['cardboard', 'metal'],
# 'size': [10, 99],
# }),
# dfs['boxes'])

# TODO: need to figure out how to test process_$x methods.
# TODO: we should test that empty columns are properly added.
Loading

0 comments on commit e71dcaa

Please sign in to comment.