improve type annotations in tests

This commit is contained in:
Jan Petykiewicz 2024-07-29 18:00:32 -07:00
parent f87dc7d771
commit 5011750637
15 changed files with 28 additions and 28 deletions

View File

@ -2,7 +2,8 @@
Build files equivalent to the test cases used by KLayout. Build files equivalent to the test cases used by KLayout.
""" """
from typing import Callable, IO from typing import IO
from collections.abc import Callable
from . import ( from . import (

View File

@ -1,4 +1,4 @@
# type: ignore # mypy: disable-error-code="union-attr"
from typing import IO from typing import IO
from io import BytesIO from io import BytesIO

View File

@ -1,4 +1,4 @@
# type: ignore # mypy: disable-error-code="union-attr"
from typing import IO from typing import IO
from io import BytesIO from io import BytesIO

View File

@ -1,4 +1,4 @@
# type: ignore # mypy: disable-error-code="union-attr"
from typing import IO from typing import IO
from io import BytesIO from io import BytesIO

View File

@ -1,4 +1,4 @@
# type: ignore # mypy: disable-error-code="union-attr"
from typing import IO from typing import IO
from io import BytesIO from io import BytesIO

View File

@ -1,4 +1,3 @@
# type: ignore
from typing import IO from typing import IO
from io import BytesIO from io import BytesIO
import struct import struct

View File

@ -1,5 +1,5 @@
# type: ignore from typing import IO
from typing import Sequence, IO from collections.abc import Sequence
from io import BytesIO from io import BytesIO
@ -27,7 +27,7 @@ def base_tests(layout: OasisLayout) -> None:
assert not layout.cellnames assert not layout.cellnames
assert len(layout.cells) == 1 assert len(layout.cells) == 1
assert layout.cells[0].name.string == 'A' assert layout.cells[0].name.string == 'A' # type: ignore
assert not layout.cells[0].properties assert not layout.cells[0].properties

View File

@ -1,4 +1,4 @@
# type: ignore # mypy: disable-error-code="union-attr"
from typing import IO from typing import IO
from io import BytesIO from io import BytesIO

View File

@ -1,4 +1,4 @@
# type: ignore # mypy: disable-error-code="union-attr"
from typing import IO from typing import IO
from io import BytesIO from io import BytesIO
@ -182,7 +182,7 @@ def test_file_1() -> None:
else: else:
assert gg.half_width == 12, msg assert gg.half_width == 12, msg
assert len(gg.point_list) == 3, msg assert len(gg.point_list) == 3, msg # type: ignore
assert_equal(gg.point_list, [[150, 0], [0, 50], [-50, 0]], err_msg=msg) assert_equal(gg.point_list, [[150, 0], [0, 50], [-50, 0]], err_msg=msg)
if ii >= 4: if ii >= 4:

View File

@ -1,5 +1,5 @@
# type: ignore # mypy: disable-error-code="union-attr"
from typing import Tuple, IO, cast, List from typing import IO, cast
from io import BytesIO from io import BytesIO
from numpy.testing import assert_equal from numpy.testing import assert_equal
@ -22,7 +22,7 @@ def base_tests(layout: OasisLayout) -> None:
assert not layout.layers assert not layout.layers
def write_rectangle(buf: IO[bytes], pos: Tuple[int, int] = (300, -400)) -> None: def write_rectangle(buf: IO[bytes], pos: tuple[int, int] = (300, -400)) -> None:
write_uint(buf, 20) # RECTANGLE record write_uint(buf, 20) # RECTANGLE record
write_byte(buf, 0b0111_1011) # SWHX_YRDL write_byte(buf, 0b0111_1011) # SWHX_YRDL
write_uint(buf, 1) # layer write_uint(buf, 1) # layer
@ -174,7 +174,7 @@ def test_file_1() -> None:
assert not layout.cells[1].properties assert not layout.cells[1].properties
assert not layout.cells[1].geometry assert not layout.cells[1].geometry
geometry = cast(List[Rectangle], layout.cells[0].geometry) geometry = cast(list[Rectangle], layout.cells[0].geometry)
assert len(geometry) == 1 assert len(geometry) == 1
assert geometry[0].layer == 1 assert geometry[0].layer == 1
assert geometry[0].datatype == 2 assert geometry[0].datatype == 2
@ -843,7 +843,7 @@ def test_file_8() -> None:
assert not layout.cells[2].properties assert not layout.cells[2].properties
assert not layout.cells[2].placements assert not layout.cells[2].placements
geometry = cast(List[Rectangle], layout.cells[2].geometry) geometry = cast(list[Rectangle], layout.cells[2].geometry)
assert len(geometry) == 1 assert len(geometry) == 1
assert geometry[0].layer == 1 assert geometry[0].layer == 1
assert geometry[0].datatype == 2 assert geometry[0].datatype == 2

View File

@ -1,4 +1,4 @@
# type: ignore # mypy: disable-error-code="union-attr, arg-type"
from typing import IO from typing import IO
from io import BytesIO from io import BytesIO
@ -445,7 +445,7 @@ def test_file_3() -> None:
for ii, gg in enumerate(geometry): for ii, gg in enumerate(geometry):
msg = f'Fail on polygon {ii}' msg = f'Fail on polygon {ii}'
assert len(gg.properties) == 1, msg assert len(gg.properties) == 1, msg
assert gg.properties[0].name == 0, msg assert gg.properties[0].name == 0, msg # type: ignore
assert len(gg.properties[0].values) == 1, msg assert len(gg.properties[0].values) == 1, msg
assert gg.properties[0].values[0] * 5 == 1, msg assert gg.properties[0].values[0] * 5 == 1, msg # type: ignore

View File

@ -1,4 +1,4 @@
# type: ignore # mypy: disable-error-code="union-attr, index, arg-type"
from typing import IO from typing import IO
from io import BytesIO from io import BytesIO
@ -28,7 +28,7 @@ def write_file_common(buf: IO[bytes], variant: int) -> IO[bytes]:
""" """
include_repetitions = variant in (2, 5) include_repetitions = variant in (2, 5)
def var_byte(buf, byte): def var_byte(buf: IO[bytes], byte: int) -> None:
if include_repetitions: if include_repetitions:
byte |= 0b0100 byte |= 0b0100
write_byte(buf, byte) write_byte(buf, byte)

View File

@ -1,4 +1,4 @@
# type: ignore # mypy: disable-error-code="union-attr"
from typing import IO from typing import IO
from io import BytesIO from io import BytesIO
@ -267,7 +267,7 @@ def test_file_2() -> None:
prop = gg.properties[0] prop = gg.properties[0]
assert prop.name == 0, msg assert prop.name == 0, msg
assert len(prop.values) == 1, msg assert len(prop.values) == 1, msg # type: ignore
assert prop.values[0].numerator == 1, msg assert prop.values[0].numerator == 1, msg # type: ignore
assert prop.values[0].denominator == 5, msg assert prop.values[0].denominator == 5, msg # type: ignore

View File

@ -1,4 +1,4 @@
# type: ignore # mypy: disable-error-code="union-attr, index"
from typing import IO from typing import IO
from io import BytesIO from io import BytesIO

View File

@ -1,4 +1,4 @@
# type: ignore # mypy: disable-error-code="union-attr"
from typing import IO from typing import IO
from io import BytesIO from io import BytesIO