Skip to content

Commit

Permalink
docs: fix or ignore missing docstrings
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jhatler committed Dec 23, 2023
1 parent 8aa9f34 commit fa7d128
Show file tree
Hide file tree
Showing 29 changed files with 174 additions and 140 deletions.
2 changes: 1 addition & 1 deletion src/betamax/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BetamaxAdapter(BaseAdapter):
"""

def __init__(self, **kwargs):
def __init__(self, **kwargs): # noqa: D107
super(BetamaxAdapter, self).__init__()
self.cassette = None
self.cassette_name = None
Expand Down
1 change: 1 addition & 0 deletions src/betamax/cassette/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# noqa: D104
from .cassette import Cassette, dispatch_hooks
from .interaction import Interaction

Expand Down
25 changes: 13 additions & 12 deletions src/betamax/cassette/cassette.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# noqa: D100
# -*- coding: utf-8 -*-
import collections
from datetime import datetime
Expand All @@ -12,7 +13,7 @@
serialize_response, timestamp)


class Cassette(object):
class Cassette(object): # noqa: D101

default_cassette_options = {
'record_mode': 'once',
Expand All @@ -25,7 +26,7 @@ class Cassette(object):

hooks = collections.defaultdict(list)

def __init__(self, cassette_name, serialization_format, **kwargs):
def __init__(self, cassette_name, serialization_format, **kwargs): # noqa: D107, E501
#: Short name of the cassette
self.cassette_name = cassette_name

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

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

def clear(self):
def clear(self): # noqa: D102
# Clear out the interactions
self.interactions = []
# Serialize to the cassette file
Expand All @@ -106,7 +107,7 @@ def earliest_recorded_date(self):
return i.recorded_at
return datetime.now()

def eject(self):
def eject(self): # noqa: D102
self._save_cassette()

def find_match(self, request):
Expand Down Expand Up @@ -166,7 +167,7 @@ def is_recording(self):
}
return values.get(self.record_mode, True)

def load_interactions(self):
def load_interactions(self): # noqa: D102
if self.serialized is None:
self.serialized = self.serializer.deserialize()

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

def sanitize_interactions(self):
def sanitize_interactions(self): # noqa: D102
for i in self.interactions:
i.replace_all(self.placeholders, True)

def save_interaction(self, response, request):
def save_interaction(self, response, request): # noqa: D102
serialized_data = self.serialize_interaction(response, request)
interaction = Interaction(serialized_data, response)
dispatch_hooks('before_record', interaction, self)
if not interaction.ignored: # If a hook caused this to be ignored
self.interactions.append(interaction)
return interaction

def serialize_interaction(self, response, request):
def serialize_interaction(self, response, request): # noqa: D102
return {
'request': serialize_prepared_request(
request,
Expand Down Expand Up @@ -219,17 +220,17 @@ class Placeholder(collections.namedtuple('Placeholder',
"""Encapsulate some logic about Placeholders."""

@classmethod
def from_dict(cls, dictionary):
def from_dict(cls, dictionary): # noqa: D102
return cls(**dictionary)

def unpack(self, serializing):
def unpack(self, serializing): # noqa: D102
if serializing:
return self.replace, self.placeholder
else:
return self.placeholder, self.replace


def merge_placeholder_lists(defaults, overrides):
def merge_placeholder_lists(defaults, overrides): # noqa: D103
overrides = [Placeholder.from_dict(override) for override in overrides]
overrides_dict = dict((p.placeholder, p) for p in overrides)
placeholders = [overrides_dict.pop(p.placeholder, p)
Expand Down
12 changes: 6 additions & 6 deletions src/betamax/cassette/interaction.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# noqa: D100
from requests.cookies import extract_cookies_to_jar
from datetime import datetime

from betamax import util


class Interaction(object):

"""The Interaction object represents the entirety of a single interaction.
The interaction includes the date it was recorded, its JSON
Expand All @@ -21,7 +21,7 @@ class Interaction(object):
"""

def __init__(self, interaction, response=None):
def __init__(self, interaction, response=None): # noqa: D107
self.data = interaction
self.orig_response = response
self.recorded_response = self.deserialize()
Expand All @@ -42,7 +42,7 @@ def as_response(self):
return self.recorded_response

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

def deserialize(self):
Expand All @@ -68,7 +68,7 @@ def replace_all(self, replacements, serializing):
for placeholder in replacements:
self.replace(*placeholder.unpack(serializing))

def replace_in_headers(self, text_to_replace, placeholder):
def replace_in_headers(self, text_to_replace, placeholder): # noqa: D102
if text_to_replace == '':
return
for obj in ('request', 'response'):
Expand All @@ -80,7 +80,7 @@ def replace_in_headers(self, text_to_replace, placeholder):
else:
headers[k] = v.replace(text_to_replace, placeholder)

def replace_in_body(self, text_to_replace, placeholder):
def replace_in_body(self, text_to_replace, placeholder): # noqa: D102
if text_to_replace == '':
return
for obj in ('request', 'response'):
Expand All @@ -96,7 +96,7 @@ def replace_in_body(self, text_to_replace, placeholder):
else:
self.data[obj]['body']['string'] = body

def replace_in_uri(self, text_to_replace, placeholder):
def replace_in_uri(self, text_to_replace, placeholder): # noqa: D102
if text_to_replace == '':
return
for (obj, key) in (('request', 'uri'), ('response', 'url')):
Expand Down
7 changes: 4 additions & 3 deletions src/betamax/configure.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# noqa: D100
from collections import defaultdict

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

def __enter__(self):
def __enter__(self): # noqa: D105
return self

def __exit__(self, *args):
def __exit__(self, *args): # noqa: D105
pass

def __setattr__(self, prop, value):
def __setattr__(self, prop, value): # noqa: D105
if prop == 'preserve_exact_body_bytes':
self.default_cassette_options[prop] = True
else:
Expand Down
1 change: 1 addition & 0 deletions src/betamax/decorator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# noqa: D100
import functools
import unittest

Expand Down
26 changes: 14 additions & 12 deletions src/betamax/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
class BetamaxError(Exception):
def __init__(self, message):
# noqa: D100

class BetamaxError(Exception): # noqa: D101
def __init__(self, message): # noqa: D107
super(BetamaxError, self).__init__(message)


class MissingDirectoryError(BetamaxError):
class MissingDirectoryError(BetamaxError): # noqa: D101
pass


class ValidationError(BetamaxError):
class ValidationError(BetamaxError): # noqa: D101
pass


class InvalidOption(ValidationError):
class InvalidOption(ValidationError): # noqa: D101
pass


class BodyBytesValidationError(ValidationError):
class BodyBytesValidationError(ValidationError): # noqa: D101
pass


class MatchersValidationError(ValidationError):
class MatchersValidationError(ValidationError): # noqa: D101
pass


class RecordValidationError(ValidationError):
class RecordValidationError(ValidationError): # noqa: D101
pass


class RecordIntervalValidationError(ValidationError):
class RecordIntervalValidationError(ValidationError): # noqa: D101
pass


class PlaceholdersValidationError(ValidationError):
class PlaceholdersValidationError(ValidationError): # noqa: D101
pass


class PlaybackRepeatsValidationError(ValidationError):
class PlaybackRepeatsValidationError(ValidationError): # noqa: D101
pass


class SerializerValidationError(ValidationError):
class SerializerValidationError(ValidationError): # noqa: D101
pass


Expand Down
1 change: 1 addition & 0 deletions src/betamax/fixtures/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# noqa: D104
8 changes: 4 additions & 4 deletions src/betamax/fixtures/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@


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


Expand Down Expand Up @@ -102,7 +104,6 @@ def betamax_session(betamax_recorder):
:returns:
An instantiated requests Session wrapped by Betamax.
"""

return betamax_recorder.session


Expand Down Expand Up @@ -144,5 +145,4 @@ def betamax_parametrized_session(betamax_parametrized_recorder):
:returns:
An instantiated requests Session wrapped by Betamax.
"""

return betamax_parametrized_recorder.session
5 changes: 2 additions & 3 deletions src/betamax/fixtures/unittest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Minimal :class:`unittest.TestCase` subclass adding Betamax integration.
r"""Minimal :class:`unittest.TestCase` subclass adding Betamax integration.
.. autoclass:: betamax.fixtures.unittest.BetamaxTestCase
:members:
Expand Down Expand Up @@ -62,7 +62,6 @@ class TestMyApi(unittest.BetamaxTestCase):


class BetamaxTestCase(unittest.TestCase):

"""Betamax integration for unittest.
.. versionadded:: 0.5.0
Expand All @@ -75,7 +74,7 @@ class BetamaxTestCase(unittest.TestCase):
CASSETTE_LIBRARY_DIR = None

def generate_cassette_name(self):
"""Generates a cassette name for the current test.
"""Generate a cassette name for the current test.
The default format is "%(classname)s.%(testMethodName)s"
Expand Down
Loading

0 comments on commit fa7d128

Please sign in to comment.