@@ -22,33 +22,35 @@ class will record what they do, depending on what is patched in as a
22
22
wrapper.
23
23
"""
24
24
25
- def setUp (self , * args , ** kwargs ) -> None :
25
+ def setUp (self , recordings : Path , cls : Interposer = Interposer ) -> None :
26
26
"""
27
27
Prepare for recording or playback based on the test name.
28
28
29
29
Arguments:
30
+ cls (Interposer): allows subclassing Interposer
30
31
recordings (Path): the location of the recordings
31
32
"""
32
- tapedir = kwargs .pop ("recordings" , None )
33
- super ().setUp (* args , ** kwargs )
33
+ super ().setUp ()
34
34
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"
37
39
38
40
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"
40
42
if self .mode == Mode .Playback :
41
43
# decompress the recording
42
44
with gzip .open (str (self .tape ) + ".gz" , "rb" ) as fin :
43
45
with self .tape .open ("wb" ) as fout :
44
46
fout .write (fin .read ())
45
47
else :
46
- tapedir .mkdir (parents = True , exist_ok = True )
48
+ recordings .mkdir (parents = True , exist_ok = True )
47
49
48
- self .interposer = Interposer (self .tape , self .mode )
50
+ self .interposer = cls (self .tape , self .mode )
49
51
self .interposer .open ()
50
52
51
- def tearDown (self , * args , ** kwargs ) -> None :
53
+ def tearDown (self ) -> None :
52
54
"""
53
55
Finalize recording or playback based on the test name.
54
56
"""
@@ -62,4 +64,4 @@ def tearDown(self, *args, **kwargs) -> None:
62
64
# self.tape is the uncompressed file - do not leave it around
63
65
self .tape .unlink ()
64
66
65
- super ().tearDown (* args , ** kwargs )
67
+ super ().tearDown ()
0 commit comments