Skip to content
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ repos:
- id: prettier
name: Ensuring files are prettier
language: system
types: [text]
types: [yaml, json, markdown]
entry: npm run prettier
pass_filenames: false
- id: pylint
Expand Down
22 changes: 11 additions & 11 deletions src/pyipp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Info:

name: str
printer_name: str
printer_uri_supported: list
printer_uri_supported: list[Uri]
uptime: int
command_set: str | None = None
location: str | None = None
Expand All @@ -31,7 +31,7 @@ class Info:
more_info: str | None = None

@staticmethod
def from_dict(data: dict[str, Any]):
def from_dict(data: dict[str, Any]) -> Info:
"""Return Info object from IPP response."""
cmd = None
name = "IPP Printer"
Expand Down Expand Up @@ -108,8 +108,8 @@ class Uri:
"""Object holding URI info from IPP."""

uri: str
authentication: str
security: str
authentication: str | None
security: str | None


@dataclass(frozen=True)
Expand All @@ -121,7 +121,7 @@ class State:
message: str | None

@staticmethod
def from_dict(data):
def from_dict(data: dict[str, Any]) -> State:
"""Return State object from IPP response."""
state = data.get("printer-state", 0)

Expand All @@ -145,7 +145,7 @@ class Printer:
uris: list[Uri]

@staticmethod
def from_dict(data):
def from_dict(data: dict[str, Any]) -> Printer:
"""Return Printer object from IPP response."""
return Printer(
info=Info.from_dict(data),
Expand All @@ -155,7 +155,7 @@ def from_dict(data):
)

@staticmethod
def merge_marker_data(data):
def merge_marker_data(data: dict[str, Any]) -> list[Marker]: # noqa: PLR0912
"""Return Marker data from IPP response."""
markers = []
mlen = 0
Expand Down Expand Up @@ -221,14 +221,14 @@ def merge_marker_data(data):
return markers

@staticmethod
def merge_uri_data(data):
def merge_uri_data(data: dict[str, Any]) -> list[Uri]:
"""Return URI data from IPP response."""
uris = []
ulen = 0

_uris = []
auth = []
security = []
_uris: list[str] = []
auth: list[str | None] = []
security: list[str | None] = []

if isinstance(data.get("printer-uri-supported"), list):
_uris = data["printer-uri-supported"]
Expand Down
51 changes: 31 additions & 20 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Tests for IPP."""
from __future__ import annotations

import os
from typing import Any

DEFAULT_PRINTER_HOST = "epson761251.local"
DEFAULT_PRINTER_PORT = 631
Expand All @@ -9,7 +12,7 @@
)

# COMMON (NOT DOCUMENTED)
COMMON_PRINTER_ATTRS = {
COMMON_PRINTER_ATTRS: dict[str, Any] = {
"marker-colors": "",
"marker-high-levels": "",
"marker-levels": "",
Expand All @@ -19,7 +22,7 @@
}

# RFC 2911 - IPP 1.1
RFC2911_PRINTER_ATTRS = {
RFC2911_PRINTER_ATTRS: dict[str, Any] = {
"attributes-charset": "",
"attributes-natural-language": "",
"charset-configured": "",
Expand Down Expand Up @@ -76,7 +79,7 @@
}

# RFC 3995 - Notifications
RFC3995_PRINTER_ATTRS = {
RFC3995_PRINTER_ATTRS: dict[str, Any] = {
"notify-events-default": "",
"notify-events-supported": "",
"notify-lease-duration-default": "",
Expand All @@ -88,19 +91,19 @@
}

# PWG 5100.1 - Finishings
PWG51001_PRINTER_ATTRS = {
PWG51001_PRINTER_ATTRS: dict[str, Any] = {
"finishings-col-default": "",
"finishings-col-ready": "",
}

# PWG 5100.2 - Output Bins
PWG51002_PRINTER_ATTRS = {
PWG51002_PRINTER_ATTRS: dict[str, Any] = {
"output-bin-default": "",
"output-bin-supported": "",
}

# PWG 5100.3
PWG51003_PRINTER_ATTRS = {
PWG51003_PRINTER_ATTRS: dict[str, Any] = {
"job-account-id-default": "",
"job-account-id-supported": "",
"job-accounting-user-id-default": "",
Expand All @@ -112,31 +115,31 @@
}

# PWG 5100.4
PWG51004_PRINTER_ATTRS = {
PWG51004_PRINTER_ATTRS: dict[str, Any] = {
"pwg-raster-document-resolution-supported": "",
"pwg-raster-document-sheet-back": "",
"pwg-raster-document-type-supported": "",
}

# PWG 5100.6 - Page Overrides
PWG51006_PRINTER_ATTRS = {
PWG51006_PRINTER_ATTRS: dict[str, Any] = {
"overrides-supported": "",
}

# PWG 5100.7
PWG51007_PRINTER_ATTRS = {
PWG51007_PRINTER_ATTRS: dict[str, Any] = {
"print-content-optimize-default": "",
"print-content-optimize-supported": "",
}

# PWG 5100.9 - Alerts
PWG51009_PRINTER_ATTRS = {
PWG51009_PRINTER_ATTRS: dict[str, Any] = {
"printer-alert": "",
"printer-alert-description": "",
}

# PWG 5100.11 - Extended Options Set 2
PWG510011_PRINTER_ATTRS = {
PWG510011_PRINTER_ATTRS: dict[str, Any] = {
"feed-orientation-default": "",
"feed-orientation-supported": "",
"job-creation-attributes-supported": "",
Expand All @@ -148,7 +151,7 @@
}

# PWG 5100.13 - Extended Options Sst 3
PWG510013_PRINTER_ATTRS = {
PWG510013_PRINTER_ATTRS: dict[str, Any] = {
"document-password-supported": "",
"identify-actions-default": "",
"identify-actions-supported": "",
Expand Down Expand Up @@ -187,7 +190,7 @@
}

# PWG 5100.14 - IPP Everywhere v1
IPPE10_PRINTER_ATTRS = {
IPPE10_PRINTER_ATTRS: dict[str, Any] = {
**RFC2911_PRINTER_ATTRS, # required
**RFC3995_PRINTER_ATTRS,
**PWG51002_PRINTER_ATTRS,
Expand All @@ -202,7 +205,7 @@
}

# PWG 5100.12 - IPP 2.0
IPP20_PRINTER_ATTRS = {
IPP20_PRINTER_ATTRS: dict[str, Any] = {
**RFC2911_PRINTER_ATTRS, # required
**RFC3995_PRINTER_ATTRS, # optional
**PWG51001_PRINTER_ATTRS, # required
Expand All @@ -217,15 +220,23 @@
}


def load_fixture(filename):
def load_fixture(filename: str) -> str:
"""Load a fixture."""
path = os.path.join(os.path.dirname(__file__), "fixtures", filename)
with open(path, encoding="utf-8") as fptr:
path = os.path.join( # noqa: PTH118
os.path.dirname(__file__), # noqa: PTH120
"fixtures",
filename,
)
with open(path, encoding="utf-8") as fptr: # noqa: PTH123
return fptr.read()


def load_fixture_binary(filename):
def load_fixture_binary(filename: str) -> bytes:
"""Load a binary fixture."""
path = os.path.join(os.path.dirname(__file__), "fixtures", filename)
with open(path, "rb") as fptr:
path = os.path.join( # noqa: PTH118
os.path.dirname(__file__), # noqa: PTH120
"fixtures",
filename,
)
with open(path, "rb") as fptr: # noqa: PTH123
return fptr.read()
24 changes: 21 additions & 3 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# pylint: disable=R0912,R0915
from __future__ import annotations

from typing import Any

import pytest

from pyipp import models, parser
Expand All @@ -10,7 +12,7 @@


@pytest.mark.asyncio
async def test_info():
async def test_info() -> None: # noqa: PLR0915
"""Test Info model."""
parsed = parser.parse(load_fixture_binary("get-printer-attributes-epsonxp6000.bin"))
data = parsed["printers"][0]
Expand Down Expand Up @@ -82,7 +84,23 @@ async def test_info():


@pytest.mark.asyncio
async def test_printer():
async def test_state() -> None:
"""Test State model."""
data: dict[str, Any] = {
"printer-state": 4,
"printer-state-reasons": "none",
}

state = models.State.from_dict(data)

assert state
assert state.printer_state == "printing"
assert state.reasons is None
assert state.message is None


@pytest.mark.asyncio
async def test_printer() -> None: # noqa: PLR0915
"""Test Printer model."""
parsed = parser.parse(load_fixture_binary("get-printer-attributes-epsonxp6000.bin"))
printer = models.Printer.from_dict(parsed["printers"][0])
Expand Down Expand Up @@ -177,7 +195,7 @@ async def test_printer():


@pytest.mark.asyncio
async def test_printer_with_marker_data():
async def test_printer_with_marker_data() -> None: # noqa: PLR0915, assignment
"""Test Printer model."""
data = IPPE10_PRINTER_ATTRS.copy()
data["marker-names"] = []
Expand Down