Skip to content

Commit ee456c6

Browse files
committed
InterposedTestCase allows Interposer subclassing
1 parent b065c3e commit ee456c6

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.6.1] - 2019-09-04
11+
12+
### Changed
13+
14+
- `InterposedTestCase` now allows Interposer to be subclassed.
15+
16+
## [0.6.0] - 2019-09-04
17+
18+
### Added
19+
20+
- `InterposedTestCase` was added to make testing even easier.
21+
22+
### Changed
23+
24+
- Updated the README.
25+
- Provided an example.
26+
27+
## [0.5.0] - 2019-09-01
28+
29+
Initial Release.

interposer/testcase.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,35 @@ class will record what they do, depending on what is patched in as a
2222
wrapper.
2323
"""
2424

25-
def setUp(self, *args, **kwargs) -> None:
25+
def setUp(self, recordings: Path, cls: Interposer = Interposer) -> None:
2626
"""
2727
Prepare for recording or playback based on the test name.
2828
2929
Arguments:
30+
cls (Interposer): allows subclassing Interposer
3031
recordings (Path): the location of the recordings
3132
"""
32-
tapedir = kwargs.pop("recordings", None)
33-
super().setUp(*args, **kwargs)
33+
super().setUp()
3434

35-
assert tapedir, "recordings location must be specified"
36-
assert isinstance(tapedir, Path), "recordings location must be a pathlib.Path"
35+
assert recordings, "recordings location must be specified"
36+
assert isinstance(
37+
recordings, Path
38+
), "recordings location must be a pathlib.Path"
3739

3840
self.mode = Mode.Recording if os.environ.get("RECORDING") else Mode.Playback
39-
self.tape = tapedir / f"{self.id()}.db"
41+
self.tape = recordings / f"{self.id()}.db"
4042
if self.mode == Mode.Playback:
4143
# decompress the recording
4244
with gzip.open(str(self.tape) + ".gz", "rb") as fin:
4345
with self.tape.open("wb") as fout:
4446
fout.write(fin.read())
4547
else:
46-
tapedir.mkdir(parents=True, exist_ok=True)
48+
recordings.mkdir(parents=True, exist_ok=True)
4749

48-
self.interposer = Interposer(self.tape, self.mode)
50+
self.interposer = cls(self.tape, self.mode)
4951
self.interposer.open()
5052

51-
def tearDown(self, *args, **kwargs) -> None:
53+
def tearDown(self) -> None:
5254
"""
5355
Finalize recording or playback based on the test name.
5456
"""
@@ -62,4 +64,4 @@ def tearDown(self, *args, **kwargs) -> None:
6264
# self.tape is the uncompressed file - do not leave it around
6365
self.tape.unlink()
6466

65-
super().tearDown(*args, **kwargs)
67+
super().tearDown()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
description = "A code intercept wrapper with recording and playback options."
1515
major = 0
1616
minor = 6
17-
patch = 0
17+
patch = 1
1818

1919
# Everything below should be cookie-cutter
2020

0 commit comments

Comments
 (0)