Skip to content

Commit

Permalink
Merge pull request #685 from byllyfish/cleanup
Browse files Browse the repository at this point in the history
Clean up tests and pylint/pyright warnings.
  • Loading branch information
byllyfish authored Nov 7, 2024
2 parents 8eb0170 + 671748c commit a42c5e4
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion ci/requirements-demonet.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Poetry (version 1.8.4) export at Tue Nov 5 11:42:39 MST 2024
# Poetry (version 1.8.4) export at Thu Nov 7 09:33:40 MST 2024
pygraphviz==1.14 ; python_version >= "3.10" and python_version < "4.0" \
--hash=sha256:c10df02377f4e39b00ae17c862f4ee7e5767317f1c6b2dfd04cea6acc7fc2bea
8 changes: 4 additions & 4 deletions ci/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Poetry (version 1.8.4) export at Tue Nov 5 11:42:39 MST 2024
# Poetry (version 1.8.4) export at Thu Nov 7 09:33:40 MST 2024
astroid==3.3.5 ; python_version >= "3.10" and python_version < "4.0" \
--hash=sha256:5cfc40ae9f68311075d27ef68a4841bdc5cc7f6cf86671b49f00607d30188e2d \
--hash=sha256:a9d1c946ada25098d790e079ba2a1b112157278f3fb7e718ae6a9252f5835dc8
Expand Down Expand Up @@ -311,9 +311,9 @@ pygments==2.18.0 ; python_version >= "3.10" and python_version < "4.0" \
pylint==3.3.1 ; python_version >= "3.10" and python_version < "4.0" \
--hash=sha256:2f846a466dd023513240bc140ad2dd73bfc080a5d85a710afdb728c420a5a2b9 \
--hash=sha256:9f3dcc87b1203e612b78d91a896407787e708b3f189b5fa0b307712d49ff0c6e
pyright==1.1.387 ; python_version >= "3.10" and python_version < "4.0" \
--hash=sha256:577de60224f7fe36505d5b181231e3a395d427b7873be0bbcaa962a29ea93a60 \
--hash=sha256:6a1f495a261a72e12ad17e20d1ae3df4511223c773b19407cfa006229b1b08a5
pyright==1.1.388 ; python_version >= "3.10" and python_version < "4.0" \
--hash=sha256:0166d19b716b77fd2d9055de29f71d844874dbc6b9d3472ccd22df91db3dfa34 \
--hash=sha256:c7068e9f2c23539c6ac35fc9efac6c6c1b9aa5a0ce97a9a8a6cf0090d7cbf84c
pytest-asyncio==0.24.0 ; python_version >= "3.10" and python_version < "4.0" \
--hash=sha256:a811296ed596b69bf0b6f3dc40f83bcaf341b155a269052d82efa2b25ac7037b \
--hash=sha256:d081d828e576d85f875399194281e92bf8a68d60d72d1a2faf2feddb6c46b276
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Poetry (version 1.8.4) export at Tue Nov 5 11:42:39 MST 2024
# Poetry (version 1.8.4) export at Thu Nov 7 09:33:40 MST 2024
grpcio==1.67.1 ; python_version >= "3.10" and python_version < "4.0" \
--hash=sha256:01f616a964e540638af5130469451cf580ba8c7329f45ca998ab66e0c7dcdb04 \
--hash=sha256:0489063974d1452436139501bf6b180f63d4977223ee87488fe36858c5725292 \
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def test_demo(demonet, python):
async with python(BASIC_DIR / "demo.py") as demo:
await asyncio.sleep(0.5)
await demonet.send("pingall", expect="(12/12 received)")
raise asyncio.CancelledError()
demo.cancel()


async def test_read_tables(demonet):
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/test_flowcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def test_demo(demonet, python):
await asyncio.sleep(0.5)
await demonet.send("h1 ping -c 1 -W .25 h2", expect="100% packet loss")
await demonet.send("h2 ping -c 1 -W .25 h1", expect="100% packet loss")
raise asyncio.CancelledError()
demo.cancel()


async def test_read_tables(demonet):
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/test_gnmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def test_demo2(demonet, python):
await asyncio.sleep(0.5)
await demonet.send("h1 ifconfig eth0 up")
await asyncio.sleep(0.5)
raise asyncio.CancelledError()
demo2.cancel()

assert (
result.decode()
Expand All @@ -42,7 +42,7 @@ async def test_demo3(demonet, python):

async with python(GNMI_DIR / "demo3.py") | result as demo3:
await asyncio.sleep(6.5)
raise asyncio.CancelledError()
demo3.cancel()

assert result.decode().startswith(
"initial: s1-eth1 is UP\nupdate: s1-eth1 is DOWN\nupdate: s1-eth1 is UP\nupdate: s1-eth1 is DOWN"
Expand Down
6 changes: 3 additions & 3 deletions examples/tests/test_hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def test_demo1(demonet, python):
async with python(HELLO_DIR / "demo1.py") as demo1:
await asyncio.sleep(0.25)
await demonet.send("pingall", expect="(6/6 received)")
raise asyncio.CancelledError()
demo1.cancel()


async def test_demo2(demonet, python):
Expand All @@ -50,7 +50,7 @@ async def test_demo2(demonet, python):
await asyncio.sleep(0.5)
await demonet.send("pingall")
await demonet.send("pingall", expect="(6/6 received)")
raise asyncio.CancelledError()
demo2.cancel()


async def test_read_tables(demonet):
Expand Down Expand Up @@ -90,7 +90,7 @@ async def test_demo3(demonet, python):
await asyncio.sleep(0.5)
await demonet.send("pingall")
await demonet.send("pingall", expect="(6/6 received)")
raise asyncio.CancelledError()
demo3.cancel()


@pytest.mark.skipif(not testlib.has_pygraphviz(), reason="Requires pygraphviz")
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/test_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def test_demo(demonet, python):
await asyncio.sleep(0.25)
await demonet.send("h1 echo 'abc' | socat - udp:192.168.0.48:5555")
await asyncio.sleep(1.0)
raise asyncio.CancelledError()
demo.cancel()


async def test_read_tables(demonet):
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/test_l2switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def test_demo(demonet, python):
async with python(L2SWITCH_DIR / "demo.py") as demo:
await asyncio.sleep(0.5)
await demonet.send("pingall", expect="(6/6 received)")
raise asyncio.CancelledError()
demo.cancel()


async def test_read_tables(demonet):
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/test_ngsdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def test_ngsdn_oneshot(demonet, python):
await demonet.send("h3 ping -c 1 h1a")
await demonet.send("h1a ping -c 1 h3", expect=" 0% packet loss")

raise asyncio.CancelledError()
demo.cancel()


async def test_leaf2(demonet):
Expand Down Expand Up @@ -163,7 +163,7 @@ async def test_ngsdn_actionprofile(demonet, python):
await demonet.send("h3 ping -c 2 h1a")
await demonet.send("h1a ping -c 1 h3", expect=" 0% packet loss")

raise asyncio.CancelledError()
demo.cancel()


async def test_read_tables_actionprofile(demonet, caplog):
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/test_tls_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ async def test_demo1(demonet, python):
async with python(TLSDEMO_DIR / "demo1.py") as demo1:
await asyncio.sleep(0.25)
await demonet.send("pingall", expect="(2/2 received)")
raise asyncio.CancelledError()
demo1.cancel()
6 changes: 5 additions & 1 deletion finsy/p4schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2030,10 +2030,12 @@ def data_type_spec(self) -> p4t.P4DataTypeSpec:

@property
def bitwidth(self) -> int:
"Width of serializable enum in bits."
return self.pbuf.underlying_type.bitwidth

@property
def members(self) -> dict[str, int]:
"Dictionary of enum members."
return self._members

def encode_data(self, value: Any) -> p4d.P4Data:
Expand Down Expand Up @@ -2176,10 +2178,12 @@ def __init__(

@property
def extern_type_id(self) -> int:
"ID of the extern's type."
return self._extern_type_id

@property
def extern_type_name(self) -> str:
"Name of the extern's type."
return self._extern_type_name

@property
Expand Down Expand Up @@ -2208,7 +2212,7 @@ def __getitem__(self, key: tuple[str, str] | tuple[int, int]) -> P4ExternInstanc
value = self.get(key)
if value is None:
self._key_error(key)
return value # pyright: ignore[reportReturnType]
return value

def __iter__(self) -> Iterator[P4ExternInstance]:
return iter(self._by_name.values())
Expand Down
3 changes: 3 additions & 0 deletions finsy/stringutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Don't use min() builtin in performance-critical loops.
# pylint: disable=consider-using-min-builtin


def minimum_edit_distance(str1: str, str2: str) -> int:
"""Compute the minimum edit distance between two strings.
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mypy = "^1.13.0"
pdoc = "^15.0.0"
prometheus-client = "^0.21.0"
pylint = "^3.3.1"
pyright = "^1.1.383"
pyright = "^1.1.388"
pytest = "^8.3.3"
pytest-asyncio = "^0.24.0"
pytest-cov = "^5.0.0"
Expand Down Expand Up @@ -132,14 +132,14 @@ ignored-modules = ["finsy.proto"]
good-names = ["i", "j", "k", "v", "ex", "Run", "_", "m", "s", "ee", "up", "id", "vt"]

[tool.pylint.design]
max-attributes = 15
max-attributes = 17
min-public-methods = 0
max-public-methods = 25
max-public-methods = 27
max-branches = 15
max-returns = 10

[tool.pylint.format]
max-module-lines = 2500
max-module-lines = 2700
max-line-length = 120

[tool.pylint."messages control"]
Expand Down

0 comments on commit a42c5e4

Please sign in to comment.