Skip to content

Commit

Permalink
Merge pull request #187 from boxine/update-req
Browse files Browse the repository at this point in the history
Add flake8-bugbear and fix code style to pass
  • Loading branch information
phihag authored Jan 16, 2024
2 parents ab1f7e0 + 05c1b08 commit 711dc7b
Show file tree
Hide file tree
Showing 12 changed files with 682 additions and 588 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ max_line_length = 119
indent_style = tab
insert_final_newline = false

[*.yml]
[{*.yaml,*.yml}]
indent_size = 2
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.11", "3.10", "3.9"]
env:
PYTHONUNBUFFERED: 1
PYTHONWARNINGS: always
steps:
- name: Checkout
run: |
echo $GITHUB_REF $GITHUB_SHA
git clone --depth 1 https://github.com/$GITHUB_REPOSITORY.git .
git clone https://github.com/$GITHUB_REPOSITORY.git .
git fetch origin $GITHUB_SHA:temporary-ci-branch
git checkout $GITHUB_SHA || (git fetch && git checkout $GITHUB_SHA)
Expand All @@ -45,6 +42,9 @@ jobs:
make install
- name: 'Run tests with Python v${{ matrix.python-version }}'
env:
PYTHONUNBUFFERED: 1
PYTHONWARNINGS: always
run: |
make coverage
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
*.egg-info
__pycache__
/dist/
/build/
/coverage.*
*.orig

!.github
!.editorconfig
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Doc-Write, see: https://github.com/boxine/bx_py_utils/blob/master/bx_py_utils/do

A simple mock for Boto3's S3 modules.

* [`PseudoS3Client()`](https://github.com/boxine/bx_py_utils/blob/master/bx_py_utils/test_utils/mocks3.py#L60-L245) - Simulates a boto3 S3 client object in tests
* [`PseudoS3Client()`](https://github.com/boxine/bx_py_utils/blob/master/bx_py_utils/test_utils/mocks3.py#L60-L246) - Simulates a boto3 S3 client object in tests

#### bx_py_utils.test_utils.redirect

Expand Down
2 changes: 1 addition & 1 deletion bx_py_utils/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ def __enter__(self):
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type:
raise
os.environ = self._origin_env
os.environ = self._origin_env # noqa:B003
2 changes: 1 addition & 1 deletion bx_py_utils/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def print_exc_plus(exc=None, stop_on_file_path=None, max_chars=None):

try:
print(value, file=sys.stderr)
except BaseException:
except BaseException: # noqa:B036
print('<ERROR WHILE PRINTING VALUE>', file=sys.stderr)

print(file=sys.stderr)
Expand Down
2 changes: 1 addition & 1 deletion bx_py_utils/humanize/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def human_timedelta(t):
if abs(t) < 60:
return f'{round(t, 1):.1f}\xa0seconds'

for seconds, time_string in TIMESINCE_CHUNKS:
for seconds, time_string in TIMESINCE_CHUNKS: # noqa: B007
count = t / seconds
if abs(count) >= 1:
count = round(count, 1)
Expand Down
7 changes: 4 additions & 3 deletions bx_py_utils/test_utils/mocks3.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ class PseudoS3Client:

exceptions = PseudoS3Exceptions

def __init__(self, *, origin_client=None, init_buckets=[]):
def __init__(self, *, origin_client=None, init_buckets=None):
self.origin_client = origin_client

self.buckets = {}
for bucket_name in init_buckets:
self.buckets[bucket_name] = {}
if init_buckets:
for bucket_name in init_buckets:
self.buckets[bucket_name] = {}

# non-standard variable names for Boto3 compatibility
def download_file(self, Bucket, Key, Filename, *, ExtraArgs=None, Callback=None, Config=None):
Expand Down
6 changes: 3 additions & 3 deletions bx_py_utils/test_utils/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def assert_text_snapshot(
)
try:
expected = snapshot_file.read_bytes().decode('utf-8')
except (FileNotFoundError, OSError):
except OSError:
snapshot_file.write_bytes(got.encode('utf-8'))
if not raise_snapshot_errors():
return
Expand Down Expand Up @@ -226,7 +226,7 @@ def assert_snapshot(
try:
with snapshot_file.open('r') as snapshot_handle:
expected = json.load(snapshot_handle)
except (ValueError, OSError, FileNotFoundError):
except (ValueError, OSError):
_write_json(got, snapshot_file)
if not raise_snapshot_errors():
return
Expand Down Expand Up @@ -385,7 +385,7 @@ def assert_binary_snapshot(
)
try:
expected = snapshot_file.read_bytes()
except (FileNotFoundError, OSError):
except OSError:
snapshot_file.write_bytes(got)
if not raise_snapshot_errors():
return
Expand Down
4 changes: 2 additions & 2 deletions bx_py_utils_tests/tests/test_error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_print_exc_plus(self):
with RedirectOut() as buffer:
try:
raise AssertionError(test_message)
except BaseException:
except BaseException: # noqa: B036
print_exc_plus()

self.assertEqual(buffer.stdout, '')
Expand All @@ -25,7 +25,7 @@ def test_print_exc_plus_max_chars(self):
try:
x = '12345678901234567890'
raise AssertionError(x)
except BaseException:
except BaseException: # noqa: B036
print_exc_plus(max_chars=15)

self.assertEqual(buffer.stdout, '')
Expand Down
Loading

0 comments on commit 711dc7b

Please sign in to comment.