Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update dependencies
Browse files Browse the repository at this point in the history
PhotonQuantum committed Jun 4, 2024

Verified

This commit was signed with the committer’s verified signature.
nonrational Alan Norton
1 parent 45c3c06 commit 0aea9e3
Showing 6 changed files with 818 additions and 862 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pysjtu.yml
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
python: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
python: [ "3.9", "3.10", "3.11", "3.12" ]

runs-on: ${{ matrix.os }}

1,608 changes: 780 additions & 828 deletions pdm.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -8,11 +8,10 @@ authors = [
dependencies = [
"marshmallow>=3.19.0",
"lxml>=4.9.2",
"httpx>=0.23.3",
"importlib-resources>=5.10.2; python_version < \"3.9\"",
"httpx>=0.27.0",
"marshmallow-dataclass>=8.5.11",
]
requires-python = ">=3.8"
requires-python = ">=3.9"
readme = "README.md"
license = { text = "GPL-3.0-or-later" }
classifiers = [
@@ -42,9 +41,9 @@ tests = [
"respx>=0.20.1",
]
ocr = [
"onnxruntime>=1.13.1",
"numpy>=1.24.1",
"Pillow>=9.4.0",
"onnxruntime>=1.18.0",
"numpy>=1.26.4",
"Pillow>=10.3.0",
]

[tool.pdm]
2 changes: 1 addition & 1 deletion pysjtu/ocr/__init__.py
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ def _tensor_to_captcha(tensors):

captcha = ""
for tensor in tensors:
asc = int(np.argmax(tensor, 1))
asc = np.argmax(tensor, 1)[0]
if asc < 26:
captcha += chr(ord("a") + asc)
return captcha
53 changes: 29 additions & 24 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -18,13 +18,18 @@

# noinspection PyPep8Naming
def Session(*args, **kwargs):
return _Session(*args, **kwargs, proxies={"all://": None})
return _Session(*args, **kwargs, mounts={"all://": None})


@pytest.fixture
def logged_session(mocker):
def transport():
return httpx.WSGITransport(app=app)


@pytest.fixture
def logged_session(mocker, transport):
mocker.patch.object(JCSSRecognizer, "recognize", return_value="ipsum")
sess = Session(app=app, retry=[0], timeout=1)
sess = Session(transport=transport, retry=[0], timeout=1)
sess.login("FeiLin", "WHISPERS")
return sess

@@ -66,32 +71,32 @@ def test_secure_req(self):
with pytest.raises(httpx.NetworkError):
sess._secure_req(partial(httpx.get, "https://fail.page.edu.cn"))

def test_context(self, mocker):
def test_context(self, mocker, transport):
tmpfile = NamedTemporaryFile()
pickle.dump({"username": "FeiLin", "password": "WHISPERS"}, tmpfile)
tmpfile.seek(0)

mocker.patch.object(JCSSRecognizer, "recognize", return_value="ipsum")
with Session(app=app, session_file=tmpfile.file):
with Session(transport=transport, session_file=tmpfile.file):
pass
tmpfile.seek(0)

assert pickle.load(tmpfile)["cookies"]

def test_init(self, mocker, check_login):
def test_init(self, mocker, transport, check_login):
tmpfile = NamedTemporaryFile()
mocker.patch.object(JCSSRecognizer, "recognize", return_value="ipsum")
sess = Session(app=app, username="FeiLin", password="WHISPERS")
sess = Session(transport=transport, username="FeiLin", password="WHISPERS")
assert check_login(sess)
cookie = sess.cookies
sess.dump(tmpfile.file)
tmpfile.seek(0)

with pytest.warns(LoadWarning):
sess = Session(app=app, cookies=cookie)
sess = Session(transport=transport, cookies=cookie)
assert check_login(sess)

sess = Session(app=app, session_file=tmpfile.file)
sess = Session(transport=transport, session_file=tmpfile.file)
assert check_login(sess)

def test_req(self, logged_session, check_login):
@@ -144,11 +149,11 @@ def test_logout(self, logged_session, check_login):
with pytest.raises(SessionException):
logged_session.get("https://i.sjtu.edu.cn/xtgl/index_initMenu.html")

def test_loads_dumps(self, logged_session, check_login):
def test_loads_dumps(self, transport, logged_session, check_login):
cookie = logged_session.cookies
dumps = logged_session.dumps()

sess = Session(app=app)
sess = Session(transport=transport)
sess.loads({"username": "FeiLin", "password": "WHISPERS"})
assert check_login(sess)

@@ -158,7 +163,7 @@ def test_loads_dumps(self, logged_session, check_login):
assert not sess._username
assert not sess._password

sess = Session(app=app)
sess = Session(transport=transport)
with pytest.raises(TypeError):
sess.loads({"cookies": "Cookie☆"})
with pytest.warns(LoadWarning):
@@ -168,36 +173,36 @@ def test_loads_dumps(self, logged_session, check_login):
with pytest.warns(DumpWarning):
sess.dumps()

sess = Session(app=app)
sess = Session(transport=transport)
sess.loads(dumps)
assert check_login(sess)

# test auto renew mechanism
logged_session.logout()
sess = Session(app=app)
sess = Session(transport=transport)
sess.loads(dumps)
assert check_login(sess)

def test_load_dump(self, logged_session, check_login, tmp_path):
def test_load_dump(self, transport, logged_session, check_login, tmp_path):
tmp_file = NamedTemporaryFile()
logged_session.dump(tmp_file.file)
tmp_file.seek(0)
sess = Session(app=app)
sess = Session(transport=transport)
sess.load(tmp_file.file)
assert check_login(sess)

tmp_file = tmp_path / "tmpfile_1"
# noinspection PyTypeChecker
open(tmp_file, mode="a").close()
logged_session.dump(tmp_file)
sess = Session(app=app)
sess = Session(transport=transport)
sess.load(tmp_file)
assert check_login(sess)

tmp_file = str(tmp_path / "tmpfile_2")
open(tmp_file, mode="a").close()
logged_session.dump(tmp_file)
sess = Session(app=app)
sess = Session(transport=transport)
sess.load(tmp_file)
assert check_login(sess)

@@ -209,21 +214,21 @@ def test_load_dump(self, logged_session, check_login, tmp_path):
sess.dump(0)

empty_file = NamedTemporaryFile()
sess = Session(app=app)
sess = Session(transport=transport)
with pytest.warns(LoadWarning):
sess.load(empty_file.file)

empty_file = tmp_path / "empty_file"
# noinspection PyTypeChecker
open(empty_file, mode="a").close()
sess = Session(app=app)
sess = Session(transport=transport)
with pytest.warns(LoadWarning):
sess.load(empty_file)

def test_properties(self, logged_session):
def test_properties(self, transport, logged_session):
cookie = logged_session.cookies

sess = Session(app=app)
sess = Session(transport=transport)

assert isinstance(sess.timeout, httpx.Timeout)
sess.timeout = httpx.Timeout(1.0)
@@ -259,14 +264,14 @@ def get(self): ...
def post(self): ...

# noinspection PyTypeChecker
def test_init(self, logged_session):
def test_init(self, transport, logged_session):
Client(logged_session)
Client(self.DummySession())
with pytest.raises(TypeError):
Client(0)
with pytest.raises(TypeError):
Client(self.DummySession2())
client = create_client("FeiLin", "WHISPERS", app=app, proxies={"all://": None})
client = create_client("FeiLin", "WHISPERS", transport=transport, mounts={"all://": None})
assert client.student_id == 519027910001

def test_student_id(self, logged_client):
4 changes: 2 additions & 2 deletions tests/test_ocr.py
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ def f_expected(f):
]


@pytest.mark.skipif(sys.version_info > (3, 10), reason="Python 3.11 doesn't have ONNXRuntime, yet.")
# @pytest.mark.skipif(sys.version_info > (3, 10), reason="Python 3.11 doesn't have ONNXRuntime, yet.")
@pytest.mark.parametrize("captcha", captcha_files())
def test_recognizer(captcha, recognizer):
expected, file = captcha
@@ -42,5 +42,5 @@ def test_recognizer(captcha, recognizer):
def test_jcss_recognizer():
respx.post("https://jcss.lightquantum.me").respond(
content='{"status":"success","data":{"prediction":"gbmke","elapsed_time":2}}')
predictor = JCSSRecognizer(proxies={"all://": None})
predictor = JCSSRecognizer(mounts={"all://": None})
assert predictor.recognize(b'fbkfbkfbk') == "gbmke"

0 comments on commit 0aea9e3

Please sign in to comment.