Skip to content

Commit

Permalink
Auto-format all Python files with black
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed Feb 20, 2024
1 parent 6c9cf53 commit 33b7ef2
Show file tree
Hide file tree
Showing 33 changed files with 1,170 additions and 1,062 deletions.
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"recommendations": [
"EditorConfig.EditorConfig",
"ms-python.black-formatter",
"ms-python.flake8"
]
}
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"python.analysis.extraPaths": [".virtualenv"],
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
},
"black-formatter.importStrategy": "fromEnvironment",
"isort.args": [
"--profile", "black"
]
}
20 changes: 15 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
alfred-workflow-packager==3.0.0
attrs==21.4.0
biplist==1.0.3
black==24.2.0
click==8.1.7
coverage==6.5.0
flake8==4.0.1
isort==5.10.1
flake8==7.0.0
flake8-black==0.3.6
flake8-isort==6.1.1
isort==5.13.2
jsonschema==4.4.0
mccabe==0.6.1
mccabe==0.7.0
mypy-extensions==1.0.0
nose2==0.11.0
pycodestyle==2.8.0
pyflakes==2.4.0
packaging==23.2
pathspec==0.12.1
platformdirs==4.2.0
pycodestyle==2.11.1
pyflakes==3.2.0
pyrsistent==0.18.1
six==1.16.0
tomli==2.0.1
typing_extensions==4.9.0
11 changes: 5 additions & 6 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
import os.path
import shutil
import tempfile

from unittest.mock import patch

import yvs.core as core
import yvs.cache as cache
import yvs.core as core

temp_dir = tempfile.gettempdir()
local_data_dir_patcher = patch(
'yvs.core.LOCAL_DATA_DIR_PATH',
os.path.join(temp_dir, 'yvs-data'))
"yvs.core.LOCAL_DATA_DIR_PATH", os.path.join(temp_dir, "yvs-data")
)
local_cache_dir_patcher = patch(
'yvs.cache.LOCAL_CACHE_DIR_PATH',
os.path.join(temp_dir, 'yvs-cache'))
"yvs.cache.LOCAL_CACHE_DIR_PATH", os.path.join(temp_dir, "yvs-cache")
)


def set_up():
Expand Down
8 changes: 6 additions & 2 deletions tests/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import sys
from functools import wraps
from io import StringIO

from unittest.mock import patch


def redirect_stdout(func):
"""temporarily redirect stdout to new output stream"""

@wraps(func)
def wrapper(*args, **kwargs):
original_stdout = sys.stdout
Expand All @@ -19,15 +19,19 @@ def wrapper(*args, **kwargs):
return func(out, *args, **kwargs)
finally:
sys.stdout = original_stdout

return wrapper


def use_user_prefs(user_prefs):
"""temporarily use the given values for user preferences"""

def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
with patch('yvs.core.get_user_prefs', return_value=user_prefs):
with patch("yvs.core.get_user_prefs", return_value=user_prefs):
return func(*args, **kwargs)

return wrapper

return decorator
46 changes: 21 additions & 25 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,24 @@
@redirect_stdout
def test_cache_purge_oldest(out):
"""should purge oldest entry when cache grows too large"""
entry_key = 'a'
entry_key = "a"
num_entries = cache.MAX_NUM_CACHE_ENTRIES + 2
purged_entry_checksum = hashlib.sha1(
('a' * 1).encode('utf-8')).hexdigest()
last_entry_checksum = hashlib.sha1(
('a' * num_entries).encode('utf-8')).hexdigest()
purged_entry_checksum = hashlib.sha1(("a" * 1).encode("utf-8")).hexdigest()
last_entry_checksum = hashlib.sha1(("a" * num_entries).encode("utf-8")).hexdigest()
case.assertFalse(
os.path.exists(cache.get_cache_entry_dir_path()),
'local cache entry directory exists')
"local cache entry directory exists",
)
for i in range(num_entries):
cache.add_cache_entry(entry_key, 'blah blah')
entry_key += 'a'
cache.add_cache_entry(entry_key, "blah blah")
entry_key += "a"
entry_checksums = os.listdir(cache.get_cache_entry_dir_path())
case.assertEqual(len(entry_checksums), cache.MAX_NUM_CACHE_ENTRIES)
case.assertNotIn(purged_entry_checksum, entry_checksums)
case.assertIn(last_entry_checksum, entry_checksums)
with open(cache.get_cache_manifest_path(), 'r') as manifest_file:
with open(cache.get_cache_manifest_path(), "r") as manifest_file:
entry_checksums = manifest_file.read().splitlines()
case.assertEqual(
len(entry_checksums), cache.MAX_NUM_CACHE_ENTRIES)
case.assertEqual(len(entry_checksums), cache.MAX_NUM_CACHE_ENTRIES)
case.assertNotIn(purged_entry_checksum, entry_checksums)
case.assertIn(last_entry_checksum, entry_checksums)

Expand All @@ -55,30 +53,28 @@ def test_cache_truncate(out):
should truncate cache if max entries count changes
between workflow versions
"""
entry_key = 'a'
entry_key = "a"
new_max_count = cache.MAX_NUM_CACHE_ENTRIES // 2
num_entries = cache.MAX_NUM_CACHE_ENTRIES + 2
purged_entry_checksum = hashlib.sha1(
('a' * 1).encode('utf-8')).hexdigest()
last_entry_checksum = hashlib.sha1(
('a' * num_entries).encode('utf-8')).hexdigest()
purged_entry_checksum = hashlib.sha1(("a" * 1).encode("utf-8")).hexdigest()
last_entry_checksum = hashlib.sha1(("a" * num_entries).encode("utf-8")).hexdigest()
case.assertFalse(
os.path.exists(cache.get_cache_entry_dir_path()),
'local cache entry directory exists')
"local cache entry directory exists",
)
for i in range(num_entries // 2):
cache.add_cache_entry(entry_key, 'blah blah')
entry_key += 'a'
with patch('yvs.cache.MAX_NUM_CACHE_ENTRIES', new_max_count):
cache.add_cache_entry(entry_key, "blah blah")
entry_key += "a"
with patch("yvs.cache.MAX_NUM_CACHE_ENTRIES", new_max_count):
for i in range(num_entries // 2):
cache.add_cache_entry(entry_key, 'blah blah')
entry_key += 'a'
cache.add_cache_entry(entry_key, "blah blah")
entry_key += "a"
entry_checksums = os.listdir(cache.get_cache_entry_dir_path())
case.assertEqual(len(entry_checksums), new_max_count)
case.assertNotIn(purged_entry_checksum, entry_checksums)
case.assertIn(last_entry_checksum, entry_checksums)
with open(cache.get_cache_manifest_path(), 'r') as manifest_file:
with open(cache.get_cache_manifest_path(), "r") as manifest_file:
entry_checksums = manifest_file.read().splitlines()
case.assertEqual(
len(entry_checksums), new_max_count)
case.assertEqual(len(entry_checksums), new_max_count)
case.assertNotIn(purged_entry_checksum, entry_checksums)
case.assertIn(last_entry_checksum, entry_checksums)
9 changes: 4 additions & 5 deletions tests/test_clear_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import yvs.clear_cache as yvs
from tests import set_up, tear_down


case = unittest.TestCase()


Expand All @@ -21,8 +20,8 @@ def test_clear_cache():
"""should remove cache directory when cache is cleared"""
yvs.main()
case.assertFalse(
os.path.exists(yvs.cache.LOCAL_CACHE_DIR_PATH),
'local cache directory exists')
os.path.exists(yvs.cache.LOCAL_CACHE_DIR_PATH), "local cache directory exists"
)


@with_setup(set_up)
Expand All @@ -32,5 +31,5 @@ def test_clear_cache_silent_fail():
shutil.rmtree(yvs.cache.LOCAL_CACHE_DIR_PATH)
yvs.main()
case.assertFalse(
os.path.exists(yvs.cache.LOCAL_CACHE_DIR_PATH),
'local cache directory exists')
os.path.exists(yvs.cache.LOCAL_CACHE_DIR_PATH), "local cache directory exists"
)

0 comments on commit 33b7ef2

Please sign in to comment.