Skip to content

Commit 3be3ede

Browse files
Copilotcclauss
authored andcommitted
Initial plan
1 parent d28f637 commit 3be3ede

File tree

8 files changed

+542
-408
lines changed

8 files changed

+542
-408
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ jobs:
2626
python-version: ${{ matrix.python }}
2727
allow-prereleases: true
2828

29-
- name: Install uv
30-
uses: astral-sh/setup-uv@v7
29+
- uses: astral-sh/setup-uv@v7
3130
with:
32-
version: "0.9.10"
31+
version: "0.9.18"
3332

3433
- name: Run tests
35-
run: uv run --extra solrcloud -- python run-tests.py
34+
run: uv run --extra=solrcloud --with=pytest -- python run-tests.py

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ repos:
3636
- tomli
3737

3838
- repo: https://github.com/astral-sh/ruff-pre-commit
39-
rev: v0.14.7
39+
rev: v0.14.9
4040
hooks:
4141
- id: ruff-check
4242
args: [ --fix ]
@@ -53,6 +53,6 @@ repos:
5353
- id: validate-pyproject
5454

5555
- repo: https://github.com/astral-sh/uv-pre-commit
56-
rev: 0.9.14
56+
rev: 0.9.18
5757
hooks:
5858
- id: uv-lock

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ urls.Homepage = "https://github.com/django-haystack/pysolr/"
3333
dev = [
3434
"coverage",
3535
"pre-commit>=4.4",
36+
"pytest",
3637
]
3738

3839
[tool.hatch.build.targets.sdist]
@@ -100,8 +101,6 @@ lint.ignore = [
100101
"PGH004",
101102
"PLR5501",
102103
"PLW2901",
103-
"PT009",
104-
"PT027",
105104
"PTH123",
106105
"RET505",
107106
"RET506",
@@ -115,6 +114,8 @@ lint.per-file-ignores."tests/*" = [
115114
]
116115
lint.mccabe.max-complexity = 16
117116
lint.pylint.allow-magic-value-types = [
117+
"bytes",
118+
"float",
118119
"int",
119120
"str",
120121
]

run-tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import subprocess
44
import unittest
5+
from pathlib import Path
56

67

78
def main():
@@ -10,6 +11,11 @@ def main():
1011
subprocess.run(["./solr-docker-test-env.sh", "setup"], check=True)
1112

1213
print("→ Running unit test suite...")
14+
old_path = Path("tests/__init__.py")
15+
new_path = old_path.with_name("z__init__.py")
16+
old_path.rename(new_path) # rename tests/__init__.py to avoid duplicate tests
17+
subprocess.run(["pytest"], check=True) # noqa: S607
18+
new_path.rename(old_path)
1319
unittest.main(module="tests", verbosity=1)
1420

1521
finally:

tests/test_admin.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import json
33
import unittest
44

5+
import pytest
6+
57
from pysolr import SolrCoreAdmin, SolrError
68

79

@@ -49,28 +51,28 @@ def test_status(self):
4951
raw_all = self.solr_admin.status()
5052
all_data = json.loads(raw_all)
5153

52-
self.assertIn("core0", all_data["status"])
54+
assert "core0" in all_data["status"]
5355

5456
# Status of a specific core
5557
raw_single = self.solr_admin.status(core="core0")
5658
single_data = json.loads(raw_single)
5759

58-
self.assertEqual(single_data["status"]["core0"]["name"], "core0")
60+
assert single_data["status"]["core0"]["name"] == "core0"
5961

6062
def test_create(self):
6163
"""Test creating a core returns a successful response."""
6264
raw_response = self.solr_admin.create("demo_core1")
6365
data = json.loads(raw_response)
6466

65-
self.assertEqual(data["responseHeader"]["status"], 0)
66-
self.assertEqual(data["core"], "demo_core1")
67+
assert data["responseHeader"]["status"] == 0
68+
assert data["core"] == "demo_core1"
6769

6870
def test_reload(self):
6971
"""Test reloading a core returns a successful response."""
7072
raw_response = self.solr_admin.reload("core0")
7173
data = json.loads(raw_response)
7274

73-
self.assertEqual(data["responseHeader"]["status"], 0)
75+
assert data["responseHeader"]["status"] == 0
7476

7577
def test_rename(self):
7678
"""Test renaming a core succeeds and the new name appears in the status."""
@@ -82,13 +84,13 @@ def test_rename(self):
8284
raw_response = self.solr_admin.rename("demo_core1", "demo_core2")
8385
data = json.loads(raw_response)
8486

85-
self.assertEqual(data["responseHeader"]["status"], 0)
87+
assert data["responseHeader"]["status"] == 0
8688

8789
# Verify that the renamed core appears in the status response
8890
raw_response2 = self.solr_admin.status(core="demo_core2")
8991
data2 = json.loads(raw_response2)
9092

91-
self.assertEqual(data2["status"]["demo_core2"]["name"], "demo_core2")
93+
assert data2["status"]["demo_core2"]["name"] == "demo_core2"
9294

9395
def test_swap(self):
9496
"""
@@ -110,7 +112,7 @@ def test_swap(self):
110112
raw_swap = self.solr_admin.swap("demo_core1", "demo_core2")
111113
swap_data = json.loads(raw_swap)
112114

113-
self.assertEqual(swap_data["responseHeader"]["status"], 0)
115+
assert swap_data["responseHeader"]["status"] == 0
114116

115117
def test_unload(self):
116118
"""
@@ -124,18 +126,19 @@ def test_unload(self):
124126
raw_response = self.solr_admin.unload("demo_core1")
125127
data = json.loads(raw_response)
126128

127-
self.assertEqual(data["responseHeader"]["status"], 0)
129+
assert data["responseHeader"]["status"] == 0
128130

129131
def test_load(self):
130-
self.assertRaises(NotImplementedError, self.solr_admin.load, "wheatley")
132+
with pytest.raises(NotImplementedError):
133+
self.solr_admin.load("wheatley")
131134

132135
def test_status__nonexistent_core_returns_empty_response(self):
133136
"""Test that requesting status for a missing core returns an empty response."""
134137
raw_response = self.solr_admin.status(core="not_exists")
135138
data = json.loads(raw_response)
136139

137-
self.assertNotIn("name", data["status"]["not_exists"])
138-
self.assertNotIn("instanceDir", data["status"]["not_exists"])
140+
assert "name" not in data["status"]["not_exists"]
141+
assert "instanceDir" not in data["status"]["not_exists"]
139142

140143
def test_create__existing_core_raises_error(self):
141144
"""Test creating a core that already exists returns a 500 error."""
@@ -147,20 +150,18 @@ def test_create__existing_core_raises_error(self):
147150
raw_response = self.solr_admin.create("demo_core1")
148151
data = json.loads(raw_response)
149152

150-
self.assertEqual(data["responseHeader"]["status"], 500)
151-
self.assertEqual(
152-
data["error"]["msg"], "Core with name 'demo_core1' already exists."
153-
)
153+
assert data["responseHeader"]["status"] == 500
154+
assert data["error"]["msg"] == "Core with name 'demo_core1' already exists."
154155

155156
def test_reload__nonexistent_core_raises_error(self):
156157
"""Test that reloading a non-existent core returns a 400 error."""
157158
raw_response = self.solr_admin.reload("not_exists")
158159
data = json.loads(raw_response)
159160

160161
# Solr returns a 400 error for missing cores
161-
self.assertEqual(data["responseHeader"]["status"], 400)
162-
self.assertIn("No such core", data["error"]["msg"])
163-
self.assertIn("not_exists", data["error"]["msg"])
162+
assert data["responseHeader"]["status"] == 400
163+
assert "No such core" in data["error"]["msg"]
164+
assert "not_exists" in data["error"]["msg"]
164165

165166
def test_rename__nonexistent_core_no_effect(self):
166167
"""
@@ -179,8 +180,8 @@ def test_rename__nonexistent_core_no_effect(self):
179180
data = json.loads(raw_response)
180181

181182
# The target core should not exist because the rename operation was ignored
182-
self.assertNotIn("name", data["status"]["demo_core99"])
183-
self.assertNotIn("instanceDir", data["status"]["demo_core99"])
183+
assert "name" not in data["status"]["demo_core99"]
184+
assert "instanceDir" not in data["status"]["demo_core99"]
184185

185186
def test_swap__missing_source_core_returns_error(self):
186187
"""Test swapping when the source core is missing returns a 400 error."""
@@ -193,9 +194,9 @@ def test_swap__missing_source_core_returns_error(self):
193194
data = json.loads(raw_response)
194195

195196
# Solr returns a 400 error when the source core does not exist
196-
self.assertEqual(data["responseHeader"]["status"], 400)
197-
self.assertIn("No such core", data["error"]["msg"])
198-
self.assertIn("not_exists", data["error"]["msg"])
197+
assert data["responseHeader"]["status"] == 400
198+
assert "No such core" in data["error"]["msg"]
199+
assert "not_exists" in data["error"]["msg"]
199200

200201
def test_swap__missing_target_core_returns_error(self):
201202
"""Test swapping when the target core is missing returns a 400 error."""
@@ -208,9 +209,9 @@ def test_swap__missing_target_core_returns_error(self):
208209
data = json.loads(raw_response)
209210

210211
# Solr returns a 400 error when the target core does not exist
211-
self.assertEqual(data["responseHeader"]["status"], 400)
212-
self.assertIn("No such core", data["error"]["msg"])
213-
self.assertIn("not_exists", data["error"]["msg"])
212+
assert data["responseHeader"]["status"] == 400
213+
assert "No such core" in data["error"]["msg"]
214+
assert "not_exists" in data["error"]["msg"]
214215

215216
def test_unload__nonexistent_core_returns_error(self):
216217
"""Test unloading a non-existent core returns a 400 error response."""
@@ -220,6 +221,6 @@ def test_unload__nonexistent_core_returns_error(self):
220221
data = json.loads(raw_response)
221222

222223
# Solr returns a 400 error for unloading a missing core
223-
self.assertEqual(data["responseHeader"]["status"], 400)
224-
self.assertIn("Cannot unload non-existent core", data["error"]["msg"])
225-
self.assertIn("not_exists", data["error"]["msg"])
224+
assert data["responseHeader"]["status"] == 400
225+
assert "Cannot unload non-existent core" in data["error"]["msg"]
226+
assert "not_exists" in data["error"]["msg"]

0 commit comments

Comments
 (0)