Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt ruff and address lint #123

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version: 2
updates:
# Set update schedule for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "weekly"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
12 changes: 8 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,17 @@ jobs:
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- uses: jupyterlab/maintainer-tools/.github/actions/check-links@v1

pre_commit:
test_lint:
name: Test Lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- uses: jupyterlab/maintainer-tools/.github/actions/pre-commit@v1
- name: Run Linters
run: |
hatch run typing:test
hatch run lint:style
pipx run 'validate-pyproject[all]' pyproject.toml

check_release:
runs-on: ubuntu-latest
Expand All @@ -137,7 +141,7 @@ jobs:
if: always()
needs:
- test
- pre_commit
- test_lint
- check_release
- test_minimum_versions
- test_prereleases
Expand Down
54 changes: 15 additions & 39 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
ci:
autoupdate_schedule: monthly

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand All @@ -15,52 +18,25 @@ repos:
- id: check-builtin-literals
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
args: ["--line-length", "100"]

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
files: \.py$
args: [--profile=black]

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.10.1
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.19.2
hooks:
- id: validate-pyproject
stages: [manual]
- id: check-github-workflows

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
hooks:
- id: mdformat
additional_dependencies:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.0
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/PyCQA/doc8
rev: v1.0.0
hooks:
- id: doc8
args: [--max-line-length=200]

- repo: https://github.com/john-hen/Flake8-pyproject
rev: 1.2.2
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: Flake8-pyproject
alias: flake8
additional_dependencies:
["flake8-bugbear==22.6.22", "flake8-implicit-str-concat==0.2.0"]
stages: [manual]
- id: black

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.19.2
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.165
hooks:
- id: check-github-workflows
- id: ruff
args: ["--fix"]
58 changes: 32 additions & 26 deletions jupyter_kernel_test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from queue import Empty
from unittest import SkipTest, TestCase

from jupyter_client.manager import start_new_kernel
from jupyter_client.blocking.client import BlockingKernelClient
from jupyter_client.manager import KernelManager, start_new_kernel
from jupyter_client.utils import run_sync

from .msgspec_v5 import validate_message
Expand All @@ -25,6 +26,8 @@ def ensure_sync(func):

class KernelTests(TestCase):
kernel_name = "python3"
kc: BlockingKernelClient
km: KernelManager

@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -97,7 +100,7 @@ def execute_helper(

def test_execute_stdout(self):
if not self.code_hello_world:
raise SkipTest
raise SkipTest("No code hello world")

self.flush_channels()
reply, output_msgs = self.execute_helper(code=self.code_hello_world)
Expand All @@ -118,7 +121,7 @@ def test_execute_stdout(self):

def test_execute_stderr(self):
if not self.code_stderr:
raise SkipTest
raise SkipTest("No code stderr")

self.flush_channels()
reply, output_msgs = self.execute_helper(code=self.code_stderr)
Expand All @@ -135,7 +138,7 @@ def test_execute_stderr(self):
False, "Expected one output message of type 'stream' and 'content.name'='stderr'"
)

completion_samples = []
completion_samples: list = []

def get_non_kernel_info_reply(self, timeout=None):
while True:
Expand All @@ -145,7 +148,7 @@ def get_non_kernel_info_reply(self, timeout=None):

def test_completion(self):
if not self.completion_samples:
raise SkipTest
raise SkipTest("No completion samples")

for sample in self.completion_samples:
with self.subTest(text=sample["text"]):
Expand All @@ -155,9 +158,9 @@ def test_completion(self):
if "matches" in sample:
self.assertEqual(set(reply["content"]["matches"]), set(sample["matches"]))

complete_code_samples = []
incomplete_code_samples = []
invalid_code_samples = []
complete_code_samples: list = []
incomplete_code_samples: list = []
invalid_code_samples: list = []

def check_is_complete(self, sample, status):
msg_id = self.kc.is_complete(sample)
Expand All @@ -171,7 +174,7 @@ def test_is_complete(self):
if not (
self.complete_code_samples or self.incomplete_code_samples or self.invalid_code_samples
):
raise SkipTest
raise SkipTest("Not testing is_complete")

self.flush_channels()

Expand All @@ -191,7 +194,7 @@ def test_is_complete(self):

def test_pager(self):
if not self.code_page_something:
raise SkipTest
raise SkipTest("No code page something")

self.flush_channels()

Expand All @@ -207,7 +210,7 @@ def test_pager(self):

def test_error(self):
if not self.code_generate_error:
raise SkipTest
raise SkipTest("No code generate error")

self.flush_channels()

Expand All @@ -216,11 +219,11 @@ def test_error(self):
self.assertEqual(len(output_msgs), 1)
self.assertEqual(output_msgs[0]["msg_type"], "error")

code_execute_result = []
code_execute_result: list = []

def test_execute_result(self):
if not self.code_execute_result:
raise SkipTest
raise SkipTest("No code execute result")

for sample in self.code_execute_result:
with self.subTest(code=sample["code"]):
Expand All @@ -242,13 +245,14 @@ def test_execute_result(self):
self.assertIn(mime, msg["content"]["data"])
if "result" in sample:
self.assertEqual(msg["content"]["data"][mime], sample["result"])
assert found, "execute_result message not found"
if not found:
raise AssertionError("execute_result message not found")

code_display_data = []
code_display_data: list = []

def test_display_data(self):
if not self.code_display_data:
raise SkipTest
raise SkipTest("No code display data")

for sample in self.code_display_data:
with self.subTest(code=sample["code"]):
Expand All @@ -265,7 +269,8 @@ def test_display_data(self):
else:
continue
self.assertIn(sample["mime"], msg["content"]["data"])
assert found, "display_data message not found"
if not found:
raise AssertionError("display_data message not found")

# this should match one of the values in code_execute_result
code_history_pattern = ""
Expand All @@ -287,7 +292,7 @@ def history_helper(self, execute_first, timeout=TIMEOUT, **histargs):

def test_history(self):
if not self.code_execute_result:
raise SkipTest
raise SkipTest("No code execute result")

codes = [s["code"] for s in self.code_execute_result]
_ = [s.get("result", "") for s in self.code_execute_result]
Expand All @@ -297,7 +302,7 @@ def test_history(self):

with self.subTest(hist_access_type="tail"):
if "tail" not in self.supported_history_operations:
raise SkipTest
raise SkipTest("History tail not suported")
reply = self.history_helper(codes, output=False, raw=True, hist_access_type="tail", n=n)
self.assertEqual(len(reply["content"]["history"]), n)
self.assertEqual(len(reply["content"]["history"][0]), 3)
Expand All @@ -312,9 +317,9 @@ def test_history(self):

with self.subTest(hist_access_type="range"):
if "range" not in self.supported_history_operations:
raise SkipTest
raise SkipTest("History range not supported")
if session is None:
raise SkipTest
raise SkipTest("No session")
reply = self.history_helper(
codes,
output=False,
Expand All @@ -330,9 +335,9 @@ def test_history(self):

with self.subTest(hist_access_type="search"):
if not self.code_history_pattern:
raise SkipTest
raise SkipTest("No code history pattern")
if "search" not in self.supported_history_operations:
raise SkipTest
raise SkipTest("History search not supported")

with self.subTest(subsearch="normal"):
reply = self.history_helper(
Expand Down Expand Up @@ -368,7 +373,7 @@ def test_history(self):

def test_inspect(self):
if not self.code_inspect_sample:
raise SkipTest
raise SkipTest("No code inspect sample")

self.flush_channels()
msg_id = self.kc.inspect(self.code_inspect_sample)
Expand All @@ -383,7 +388,7 @@ def test_inspect(self):

def test_clear_output(self):
if not self.code_clear_output:
raise SkipTest
raise SkipTest("No code clear output")

self.flush_channels()
reply, output_msgs = self.execute_helper(code=self.code_clear_output)
Expand All @@ -396,4 +401,5 @@ def test_clear_output(self):
found = True
else:
continue
assert found, "clear_output message not found"
if not found:
raise AssertionError("clear_output message not found")
6 changes: 3 additions & 3 deletions jupyter_kernel_test/msgspec_v5.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# These fragments will be wrapped in the boilerplate for a valid JSON schema.
# We also add a default 'required' containing all keys.
schema_fragments = {}
schema_fragments: dict = {}


def get_msg_content_validator(msg_type, version_minor):
Expand Down Expand Up @@ -110,7 +110,7 @@ def get_abort_reply_validator(version_minor):
}


def validate_message(msg, msg_type=None, parent_id=None):
def validate_message(msg, msg_type=None, parent_id=None): # noqa
msg_structure_validator.validate(msg)

msg_version_s = msg["header"]["version"]
Expand Down Expand Up @@ -146,7 +146,7 @@ def validate_message(msg, msg_type=None, parent_id=None):
try:
status = msg["content"]["status"]
except KeyError as e:
raise ValidationError(str(e))
raise ValidationError(str(e)) from None
if status == "error":
content_vdor = get_error_reply_validator(version_minor)
elif status == "abort":
Expand Down
Loading