Skip to content

Commit e12251d

Browse files
authored
docs: fix or ignore missing docstrings (#4)
This updates the docstrings, where trivial, to pass the flake8 docstring checks. In the cases where adding docstrings was non-trivial, the docstring check was ignored. Refs: betamaxpy#204 Signed-off-by: Jaremy Hatler <hatler.jaremy@gmail.com>
1 parent a10f631 commit e12251d

29 files changed

+174
-140
lines changed

src/betamax/adapter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class BetamaxAdapter(BaseAdapter):
2222
2323
"""
2424

25-
def __init__(self, **kwargs):
25+
def __init__(self, **kwargs): # noqa: D107
2626
super(BetamaxAdapter, self).__init__()
2727
self.cassette = None
2828
self.cassette_name = None

src/betamax/cassette/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# noqa: D104
12
from .cassette import Cassette, dispatch_hooks
23
from .interaction import Interaction
34

src/betamax/cassette/cassette.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# noqa: D100
12
# -*- coding: utf-8 -*-
23
import collections
34
from datetime import datetime
@@ -12,7 +13,7 @@
1213
serialize_response, timestamp)
1314

1415

15-
class Cassette(object):
16+
class Cassette(object): # noqa: D101
1617

1718
default_cassette_options = {
1819
'record_mode': 'once',
@@ -25,7 +26,7 @@ class Cassette(object):
2526

2627
hooks = collections.defaultdict(list)
2728

28-
def __init__(self, cassette_name, serialization_format, **kwargs):
29+
def __init__(self, cassette_name, serialization_format, **kwargs): # noqa: D107, E501
2930
#: Short name of the cassette
3031
self.cassette_name = cassette_name
3132

@@ -68,7 +69,7 @@ def __init__(self, cassette_name, serialization_format, **kwargs):
6869
self.serializer.allow_serialization = self.is_recording()
6970

7071
@staticmethod
71-
def can_be_loaded(cassette_library_dir, cassette_name, serialize_with,
72+
def can_be_loaded(cassette_library_dir, cassette_name, serialize_with, # noqa: D102, E501
7273
record_mode):
7374
# If we want to record a cassette we don't care if the file exists
7475
# yet
@@ -92,7 +93,7 @@ def can_be_loaded(cassette_library_dir, cassette_name, serialize_with,
9293
# have the cassette the user expects us to load and raise.
9394
return os.path.exists(cassette_path) or recording
9495

95-
def clear(self):
96+
def clear(self): # noqa: D102
9697
# Clear out the interactions
9798
self.interactions = []
9899
# Serialize to the cassette file
@@ -106,7 +107,7 @@ def earliest_recorded_date(self):
106107
return i.recorded_at
107108
return datetime.now()
108109

109-
def eject(self):
110+
def eject(self): # noqa: D102
110111
self._save_cassette()
111112

112113
def find_match(self, request):
@@ -166,7 +167,7 @@ def is_recording(self):
166167
}
167168
return values.get(self.record_mode, True)
168169

169-
def load_interactions(self):
170+
def load_interactions(self): # noqa: D102
170171
if self.serialized is None:
171172
self.serialized = self.serializer.deserialize()
172173

@@ -177,19 +178,19 @@ def load_interactions(self):
177178
dispatch_hooks('before_playback', i, self)
178179
i.replace_all(self.placeholders, False)
179180

180-
def sanitize_interactions(self):
181+
def sanitize_interactions(self): # noqa: D102
181182
for i in self.interactions:
182183
i.replace_all(self.placeholders, True)
183184

184-
def save_interaction(self, response, request):
185+
def save_interaction(self, response, request): # noqa: D102
185186
serialized_data = self.serialize_interaction(response, request)
186187
interaction = Interaction(serialized_data, response)
187188
dispatch_hooks('before_record', interaction, self)
188189
if not interaction.ignored: # If a hook caused this to be ignored
189190
self.interactions.append(interaction)
190191
return interaction
191192

192-
def serialize_interaction(self, response, request):
193+
def serialize_interaction(self, response, request): # noqa: D102
193194
return {
194195
'request': serialize_prepared_request(
195196
request,
@@ -219,17 +220,17 @@ class Placeholder(collections.namedtuple('Placeholder',
219220
"""Encapsulate some logic about Placeholders."""
220221

221222
@classmethod
222-
def from_dict(cls, dictionary):
223+
def from_dict(cls, dictionary): # noqa: D102
223224
return cls(**dictionary)
224225

225-
def unpack(self, serializing):
226+
def unpack(self, serializing): # noqa: D102
226227
if serializing:
227228
return self.replace, self.placeholder
228229
else:
229230
return self.placeholder, self.replace
230231

231232

232-
def merge_placeholder_lists(defaults, overrides):
233+
def merge_placeholder_lists(defaults, overrides): # noqa: D103
233234
overrides = [Placeholder.from_dict(override) for override in overrides]
234235
overrides_dict = dict((p.placeholder, p) for p in overrides)
235236
placeholders = [overrides_dict.pop(p.placeholder, p)

src/betamax/cassette/interaction.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
# noqa: D100
12
from requests.cookies import extract_cookies_to_jar
23
from datetime import datetime
34

45
from betamax import util
56

67

78
class Interaction(object):
8-
99
"""The Interaction object represents the entirety of a single interaction.
1010
1111
The interaction includes the date it was recorded, its JSON
@@ -21,7 +21,7 @@ class Interaction(object):
2121
2222
"""
2323

24-
def __init__(self, interaction, response=None):
24+
def __init__(self, interaction, response=None): # noqa: D107
2525
self.data = interaction
2626
self.orig_response = response
2727
self.recorded_response = self.deserialize()
@@ -42,7 +42,7 @@ def as_response(self):
4242
return self.recorded_response
4343

4444
@property
45-
def recorded_at(self):
45+
def recorded_at(self): # noqa: D102
4646
return datetime.strptime(self.data['recorded_at'], '%Y-%m-%dT%H:%M:%S')
4747

4848
def deserialize(self):
@@ -68,7 +68,7 @@ def replace_all(self, replacements, serializing):
6868
for placeholder in replacements:
6969
self.replace(*placeholder.unpack(serializing))
7070

71-
def replace_in_headers(self, text_to_replace, placeholder):
71+
def replace_in_headers(self, text_to_replace, placeholder): # noqa: D102
7272
if text_to_replace == '':
7373
return
7474
for obj in ('request', 'response'):
@@ -80,7 +80,7 @@ def replace_in_headers(self, text_to_replace, placeholder):
8080
else:
8181
headers[k] = v.replace(text_to_replace, placeholder)
8282

83-
def replace_in_body(self, text_to_replace, placeholder):
83+
def replace_in_body(self, text_to_replace, placeholder): # noqa: D102
8484
if text_to_replace == '':
8585
return
8686
for obj in ('request', 'response'):
@@ -96,7 +96,7 @@ def replace_in_body(self, text_to_replace, placeholder):
9696
else:
9797
self.data[obj]['body']['string'] = body
9898

99-
def replace_in_uri(self, text_to_replace, placeholder):
99+
def replace_in_uri(self, text_to_replace, placeholder): # noqa: D102
100100
if text_to_replace == '':
101101
return
102102
for (obj, key) in (('request', 'uri'), ('response', 'url')):

src/betamax/configure.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# noqa: D100
12
from collections import defaultdict
23

34
from .cassette import Cassette
@@ -23,13 +24,13 @@ class Configuration(object):
2324
CASSETTE_LIBRARY_DIR = 'vcr/cassettes'
2425
recording_hooks = defaultdict(list)
2526

26-
def __enter__(self):
27+
def __enter__(self): # noqa: D105
2728
return self
2829

29-
def __exit__(self, *args):
30+
def __exit__(self, *args): # noqa: D105
3031
pass
3132

32-
def __setattr__(self, prop, value):
33+
def __setattr__(self, prop, value): # noqa: D105
3334
if prop == 'preserve_exact_body_bytes':
3435
self.default_cassette_options[prop] = True
3536
else:

src/betamax/decorator.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# noqa: D100
12
import functools
23
import unittest
34

src/betamax/exceptions.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
1-
class BetamaxError(Exception):
2-
def __init__(self, message):
1+
# noqa: D100
2+
3+
class BetamaxError(Exception): # noqa: D101
4+
def __init__(self, message): # noqa: D107
35
super(BetamaxError, self).__init__(message)
46

57

6-
class MissingDirectoryError(BetamaxError):
8+
class MissingDirectoryError(BetamaxError): # noqa: D101
79
pass
810

911

10-
class ValidationError(BetamaxError):
12+
class ValidationError(BetamaxError): # noqa: D101
1113
pass
1214

1315

14-
class InvalidOption(ValidationError):
16+
class InvalidOption(ValidationError): # noqa: D101
1517
pass
1618

1719

18-
class BodyBytesValidationError(ValidationError):
20+
class BodyBytesValidationError(ValidationError): # noqa: D101
1921
pass
2022

2123

22-
class MatchersValidationError(ValidationError):
24+
class MatchersValidationError(ValidationError): # noqa: D101
2325
pass
2426

2527

26-
class RecordValidationError(ValidationError):
28+
class RecordValidationError(ValidationError): # noqa: D101
2729
pass
2830

2931

30-
class RecordIntervalValidationError(ValidationError):
32+
class RecordIntervalValidationError(ValidationError): # noqa: D101
3133
pass
3234

3335

34-
class PlaceholdersValidationError(ValidationError):
36+
class PlaceholdersValidationError(ValidationError): # noqa: D101
3537
pass
3638

3739

38-
class PlaybackRepeatsValidationError(ValidationError):
40+
class PlaybackRepeatsValidationError(ValidationError): # noqa: D101
3941
pass
4042

4143

42-
class SerializerValidationError(ValidationError):
44+
class SerializerValidationError(ValidationError): # noqa: D101
4345
pass
4446

4547

src/betamax/fixtures/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# noqa: D104

src/betamax/fixtures/pytest.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818

1919
def _sanitize(name):
20+
"""Replace problematic characters.
21+
22+
Replaces characters which might be problematic when contained in
23+
strings which will be used as file names with '-'s.
2024
"""
21-
Replace certain characters (which might be problematic when contained in
22-
strings which will be used as file names) by '-'s. """
2325
return re.sub(r'[\s/<>:\\"|?*]', '-', name)
2426

2527

@@ -102,7 +104,6 @@ def betamax_session(betamax_recorder):
102104
:returns:
103105
An instantiated requests Session wrapped by Betamax.
104106
"""
105-
106107
return betamax_recorder.session
107108

108109

@@ -144,5 +145,4 @@ def betamax_parametrized_session(betamax_parametrized_recorder):
144145
:returns:
145146
An instantiated requests Session wrapped by Betamax.
146147
"""
147-
148148
return betamax_parametrized_recorder.session

src/betamax/fixtures/unittest.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Minimal :class:`unittest.TestCase` subclass adding Betamax integration.
1+
r"""Minimal :class:`unittest.TestCase` subclass adding Betamax integration.
22
33
.. autoclass:: betamax.fixtures.unittest.BetamaxTestCase
44
:members:
@@ -62,7 +62,6 @@ class TestMyApi(unittest.BetamaxTestCase):
6262

6363

6464
class BetamaxTestCase(unittest.TestCase):
65-
6665
"""Betamax integration for unittest.
6766
6867
.. versionadded:: 0.5.0
@@ -75,7 +74,7 @@ class BetamaxTestCase(unittest.TestCase):
7574
CASSETTE_LIBRARY_DIR = None
7675

7776
def generate_cassette_name(self):
78-
"""Generates a cassette name for the current test.
77+
"""Generate a cassette name for the current test.
7978
8079
The default format is "%(classname)s.%(testMethodName)s"
8180

0 commit comments

Comments
 (0)