Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jun 8, 2022
1 parent ee41766 commit dc0fbf7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 1 addition & 3 deletions nbformat/json_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ def _validator_for_name(validator_name):
return validator_cls
# we always return something.
raise ValueError(
"Missing validator for {validator_name}".format(
validator_name=repr(validator_name)
)
f"Missing validator for {repr(validator_name)}"
)


Expand Down
7 changes: 3 additions & 4 deletions nbformat/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Distributed under the terms of the Modified BSD License.



import json
import os
import pprint
Expand All @@ -16,8 +15,7 @@
from .corpus.words import generate_corpus_id
from .json_compat import ValidationError, _validator_for_name, get_current_validator
from .reader import get_version
from .warnings import MissingIDFieldWarning, DuplicateCellId

from .warnings import DuplicateCellId, MissingIDFieldWarning

validators = {}

Expand Down Expand Up @@ -282,6 +280,7 @@ def normalize(nbdict, version, version_minor):
nbdict = deepcopy(nbdict)
return _normalize(nbdict)


def _normalize(nbdict, version, version_minor, repair_duplicate_cell_ids):
changes = 0

Expand Down Expand Up @@ -326,6 +325,7 @@ def _normalize(nbdict, version, version_minor, repair_duplicate_cell_ids):
seen_ids.add(cell_id)
return changes, nbdict


def validate(
nbdict=None,
ref=None,
Expand Down Expand Up @@ -368,7 +368,6 @@ def validate(
if version is None:
version, version_minor = 1, 0


if ref is None:
_normalize(nbdict, version, version_minor, repair_duplicate_cell_ids)

Expand Down
10 changes: 5 additions & 5 deletions tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import os
import re
from copy import deepcopy

import pytest
from jsonschema import ValidationError
Expand All @@ -14,11 +15,10 @@
from nbformat import read
from nbformat.json_compat import VALIDATORS
from nbformat.validator import isvalid, iter_validate, validate

from nbformat.warnings import DuplicateCellId, MissingIDFieldWarning

from .base import TestsBase
from copy import deepcopy
from nbformat.warnings import MissingIDFieldWarning, DuplicateCellId

nb4 = ("test4.ipynb", "test4.5.ipynb")


Expand All @@ -40,7 +40,7 @@ def set_validator(validator_name):
def test_should_warn(validator_name):
"""Test that a v4 notebook witout id emit a warning"""
set_validator(validator_name)
with TestsBase.fopen(u"test4.5.ipynb", u"r") as f:
with TestsBase.fopen("test4.5.ipynb", "r") as f:
nb = read(f, as_version=4)

del nb.cells[3]["id"]
Expand All @@ -62,7 +62,7 @@ def test_should_not_mutate(validator_name):
Probably should be 2 test. To enable in the future.
"""
set_validator(validator_name)
with TestsBase.fopen(u"test4.5.ipynb", u"r") as f:
with TestsBase.fopen("test4.5.ipynb", "r") as f:
nb = read(f, as_version=4)

del nb.cells[3]["id"]
Expand Down

0 comments on commit dc0fbf7

Please sign in to comment.