-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
abstractmethod
for BaseWrangler
to explicitly enforce
implementation of all required methods before wrangler instantiation. Add `concretize_abstract_wrangler` helper function for testing classes which do not implement all abstract methods.
- Loading branch information
1 parent
fbb404b
commit 326a501
Showing
11 changed files
with
114 additions
and
24 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""This module contains testing utility. | ||
""" | ||
|
||
from typing import Type | ||
|
||
|
||
def concretize_abstract_wrangler(wrangler_class: Type) -> Type: | ||
"""Makes abstract wrangler classes instantiable for testing purposes by | ||
implementing abstract methods of `BaseWrangler`. | ||
Parameters | ||
---------- | ||
wrangler_class: Type | ||
Class object to inherit from while overriding abstract methods. | ||
Returns | ||
------- | ||
concrete_class: Type | ||
Concrete class usable for testing. | ||
""" | ||
|
||
class ConcreteWrangler(wrangler_class): | ||
|
||
@property | ||
def preserves_sample_size(self): | ||
return super().preserves_sample_size | ||
|
||
@property | ||
def computation_engine(self): | ||
return super().computation_engine | ||
|
||
def fit(self, *args, **kwargs): | ||
return super().fit(*args, **kwargs) | ||
|
||
def fit_transform(self, *args, **kwargs): | ||
return super().fit_transform(*args, **kwargs) | ||
|
||
def transform(self, *args, **kwargs): | ||
return super().transform(*args, **kwargs) | ||
|
||
return ConcreteWrangler |
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
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
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,24 @@ | ||
"""This module contains tests for testing utilities. | ||
""" | ||
|
||
import pytest | ||
|
||
from pywrangler.base import BaseWrangler | ||
from pywrangler.util.testing import concretize_abstract_wrangler | ||
|
||
|
||
def test_concretize_abstract_wrangler(): | ||
|
||
class Dummy(BaseWrangler): | ||
@property | ||
def computation_engine(self) -> str: | ||
return "engine" | ||
|
||
concrete_class = concretize_abstract_wrangler(Dummy) | ||
instance = concrete_class() | ||
|
||
assert instance.computation_engine == "engine" | ||
|
||
with pytest.raises(NotImplementedError): | ||
instance.preserves_sample_size |