Skip to content

Commit

Permalink
Replace flake8 with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerysong committed Oct 30, 2024
1 parent e46abe6 commit a0d310d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@ jobs:
git diff
git status --porcelain | grep -q '^ M' && exit 1 || exit 0
flake8:
ruff:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Install flake8
run: sudo pip install flake8
run: sudo pip install ruff

- name: Lint Python code
run: flake8 --max-line-length=160
run: ruff check

- name: Lint Python code formatting
run: |
ruff format
git diff
git status --porcelain | grep -q '^ M' && exit 1 || exit 0
check:
runs-on: ubuntu-latest
Expand Down
8 changes: 8 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
line-length = 160

[lint]
select = ["F", "E", "W", "B", "RUF"]
ignore = ["B007"]

[format]
quote-style = "single"
15 changes: 10 additions & 5 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def private_key(scope='session'):
binargs = [
'openssl',
'genrsa',
'-out', keypath,
'-out',
keypath,
'2048',
]
subprocess.run(binargs)
Expand All @@ -23,7 +24,8 @@ def private_key(scope='session'):
binargs = [
'openssl',
'rsa',
'-in', keypath,
'-in',
keypath,
'-pubout',
]
res = subprocess.run(binargs, capture_output=True, text=True)
Expand All @@ -48,6 +50,7 @@ def _tool_path(tool):
binpath = os.path.dirname(os.path.realpath(__file__))
binpath = os.path.join(binpath, '..', tool)
return os.path.realpath(binpath)

return _tool_path


Expand All @@ -60,7 +63,7 @@ def milter_config(request, tmp_path, private_key):
'sock': tmp_path.joinpath('milter.sock'),
}
for candidate in [
request.fspath.basename, # test file
request.fspath.basename, # test file
request.function.__name__, # test function
]:
fname = os.path.join(base_path, '.'.join([candidate, 'conf']))
Expand All @@ -77,8 +80,10 @@ def milter_cmdline(tmp_path, tool_path, milter_config):
tool_path('openarc/openarc'),
'-f',
'-v',
'-c', milter_config['file'],
'-p', milter_config['sock'],
'-c',
milter_config['file'],
'-p',
milter_config['sock'],
]


Expand Down
8 changes: 4 additions & 4 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@

def test_config(milter_config, milter_cmdline):
"""A basic config should parse without error"""
res = subprocess.run(milter_cmdline + ['-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4)
res = subprocess.run([*milter_cmdline, '-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4)
assert res.returncode == 0


def test_config_fail(milter_config, milter_cmdline):
"""An invalid config should fail and return an error"""
res = subprocess.run(milter_cmdline + ['-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4)
res = subprocess.run([*milter_cmdline, '-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4)
assert res.returncode != 0
assert 'parameter "KeyFile" required when signing' in res.stderr


def test_config_requiresafekeys(milter_config, milter_cmdline):
"""World-readable keys should be rejected"""
res = subprocess.run(milter_cmdline + ['-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4)
res = subprocess.run([*milter_cmdline, '-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4)
assert res.returncode != 0
assert 'can be read or written by other users' in res.stderr


def test_config_requiresafekeys_false(milter_config, milter_cmdline):
"""World-readable keys are okay if the user said they're okay."""
res = subprocess.run(milter_cmdline + ['-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4)
res = subprocess.run([*milter_cmdline, '-n'], cwd=milter_config['cwd'], capture_output=True, text=True, timeout=4)
assert res.returncode == 0

0 comments on commit a0d310d

Please sign in to comment.