Skip to content

Commit

Permalink
Fix black module error when 19.10b0 is installed (#1855)
Browse files Browse the repository at this point in the history
* Fix black module error

* Add unittest pattern

* skip unsupported unittest

* skip unsupported unittest
  • Loading branch information
koxudaxi authored Feb 13, 2024
1 parent ab4a39c commit a4a3a42
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ jobs:
black-version: default
python-version: 3.8
pydantic-version: 1.8.2
- os: ubuntu-latest
isort-version: 5.6.4
black-version: 19.10b0
python-version: 3.9
pydantic-version: 1.8.2
- os: ubuntu-latest
isort-version: 5.6.4
black-version: 24.1.0
Expand All @@ -31,6 +36,7 @@ jobs:
black-version: 23.12.1
python-version: 3.12
pydantic-version: 2.4.2

exclude:
- os: windows-latest
black-version: 22.1.0
Expand Down
6 changes: 5 additions & 1 deletion datamodel_code_generator/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
from warnings import warn

import black
import black.mode
import isort

from datamodel_code_generator.util import cached_property, load_toml

try:
import black.mode
except ImportError: # pragma: no cover
black.mode = None


class PythonVersion(Enum):
PY_36 = '3.6'
Expand Down
92 changes: 92 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,10 @@ def test_main_no_file(capsys: CaptureFixture) -> None:
),
],
)
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_extra_template_data_config(
capsys: CaptureFixture, output_model, expected_output
) -> None:
Expand Down Expand Up @@ -964,6 +968,10 @@ def test_main_without_field_constraints(output_model, expected_output):
],
)
@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_with_aliases(output_model, expected_output):
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand Down Expand Up @@ -1135,6 +1143,10 @@ def test_enable_version_header():
],
)
@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_allow_population_by_field_name(output_model, expected_output):
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand Down Expand Up @@ -1170,6 +1182,10 @@ def test_allow_population_by_field_name(output_model, expected_output):
],
)
@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_allow_extra_fields(output_model, expected_output):
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand Down Expand Up @@ -1205,6 +1221,10 @@ def test_allow_extra_fields(output_model, expected_output):
],
)
@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_enable_faux_immutability(output_model, expected_output):
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand Down Expand Up @@ -2823,6 +2843,10 @@ def test_main_openapi_nullable_strict_nullable():
],
)
@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_openapi_pattern(output_model, expected_output):
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand Down Expand Up @@ -4121,6 +4145,10 @@ def test_long_description():


@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_long_description_wrap_string_literal():
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand Down Expand Up @@ -4311,6 +4339,10 @@ def test_jsonschema_without_titles_use_title_as_name():
),
],
)
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_use_annotated_with_field_constraints(output_model, expected_output):
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand Down Expand Up @@ -5182,6 +5214,10 @@ def test_main_jsonschema_pattern_properties_by_reference():
],
)
@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_openapi_default_object(output_model, expected_output):
with TemporaryDirectory() as output_dir:
output_path: Path = Path(output_dir)
Expand Down Expand Up @@ -5277,6 +5313,10 @@ def test_main_dataclass_field():


@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_jsonschema_enum_root_literal():
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand Down Expand Up @@ -5968,6 +6008,10 @@ def test_main_jsonschema_discriminator_literals():


@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_openapi_all_of_with_relative_ref():
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand Down Expand Up @@ -6023,6 +6067,10 @@ def test_main_msgspec_struct():


@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_msgspec_use_annotated_with_field_constraints():
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand Down Expand Up @@ -6092,6 +6140,10 @@ def test_main_duplicate_field_constraints():
],
)
@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_duplicate_field_constraints_msgspec(
collapse_root_models, python_version, expected_output
):
Expand Down Expand Up @@ -6190,6 +6242,10 @@ def test_main_all_of_ref_self():


@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_array_field_constraints():
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand Down Expand Up @@ -6252,6 +6308,10 @@ def test_all_of_use_default():
],
)
@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_graphql_simple_star_wars(output_model, expected_output):
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand All @@ -6275,6 +6335,10 @@ def test_main_graphql_simple_star_wars(output_model, expected_output):


@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_graphql_different_types_of_fields():
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand All @@ -6300,6 +6364,10 @@ def test_main_graphql_different_types_of_fields():


@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_graphql_custom_scalar_types():
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand All @@ -6325,6 +6393,10 @@ def test_main_graphql_custom_scalar_types():


@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_graphql_field_aliases():
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand All @@ -6350,6 +6422,10 @@ def test_main_graphql_field_aliases():


@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_graphql_enums():
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand All @@ -6371,6 +6447,10 @@ def test_main_graphql_enums():


@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_graphql_union():
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand Down Expand Up @@ -6429,6 +6509,10 @@ def test_main_graphql_additional_imports_isort_4():
reason='See https://github.com/PyCQA/isort/issues/1600 for example',
)
@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_graphql_additional_imports_isort_5():
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand Down Expand Up @@ -6458,6 +6542,10 @@ def test_main_graphql_additional_imports_isort_5():


@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_graphql_custom_formatters():
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand All @@ -6483,6 +6571,10 @@ def test_main_graphql_custom_formatters():


@freeze_time('2019-07-26')
@pytest.mark.skipif(
black.__version__.split('.')[0] == '19',
reason="Installed black doesn't support the old style",
)
def test_main_openapi_discriminator_enum():
with TemporaryDirectory() as output_dir:
output_file: Path = Path(output_dir) / 'output.py'
Expand Down

0 comments on commit a4a3a42

Please sign in to comment.