Skip to content

Commit 5f0c939

Browse files
committed
get test suite running
1 parent 888b803 commit 5f0c939

File tree

8 files changed

+54
-29
lines changed

8 files changed

+54
-29
lines changed

bindings/python/pymongoarrow/api.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def find_arrow_all(collection, query, *, schema=None, **kwargs):
8484
against which to run the ``find`` operation.
8585
- `query`: A mapping containing the query to use for the find operation.
8686
- `schema` (optional): Instance of :class:`~pymongoarrow.schema.Schema`.
87-
If the schema is not given, it will be inferred using the first
88-
document in the result set.
87+
If the schema is not given, it will be inferred using the data in the
88+
result set.
8989
9090
Additional keyword-arguments passed to this method will be passed
9191
directly to the underlying ``find`` operation.
@@ -122,8 +122,8 @@ def aggregate_arrow_all(collection, pipeline, *, schema=None, **kwargs):
122122
against which to run the ``aggregate`` operation.
123123
- `pipeline`: A list of aggregation pipeline stages.
124124
- `schema` (optional): Instance of :class:`~pymongoarrow.schema.Schema`.
125-
If the schema is not given, it will be inferred using the first
126-
document in the result set.
125+
If the schema is not given, it will be inferred using the data in the
126+
result set.
127127
128128
Additional keyword-arguments passed to this method will be passed
129129
directly to the underlying ``aggregate`` operation.
@@ -177,8 +177,8 @@ def find_pandas_all(collection, query, *, schema=None, **kwargs):
177177
against which to run the ``find`` operation.
178178
- `query`: A mapping containing the query to use for the find operation.
179179
- `schema` (optional): Instance of :class:`~pymongoarrow.schema.Schema`.
180-
If the schema is not given, it will be inferred using the first
181-
document in the result set.
180+
If the schema is not given, it will be inferred using the data in the
181+
result set.
182182
183183
Additional keyword-arguments passed to this method will be passed
184184
directly to the underlying ``find`` operation.
@@ -198,8 +198,8 @@ def aggregate_pandas_all(collection, pipeline, *, schema=None, **kwargs):
198198
against which to run the ``find`` operation.
199199
- `pipeline`: A list of aggregation pipeline stages.
200200
- `schema` (optional): Instance of :class:`~pymongoarrow.schema.Schema`.
201-
If the schema is not given, it will be inferred using the first
202-
document in the result set.
201+
If the schema is not given, it will be inferred using the data in the
202+
result set.
203203
204204
Additional keyword-arguments passed to this method will be passed
205205
directly to the underlying ``aggregate`` operation.
@@ -240,8 +240,8 @@ def find_numpy_all(collection, query, *, schema=None, **kwargs):
240240
against which to run the ``find`` operation.
241241
- `query`: A mapping containing the query to use for the find operation.
242242
- `schema` (optional): Instance of :class:`~pymongoarrow.schema.Schema`.
243-
If the schema is not given, it will be inferred using the first
244-
document in the result set.
243+
If the schema is not given, it will be inferred using the data in the
244+
result set.
245245
246246
Additional keyword-arguments passed to this method will be passed
247247
directly to the underlying ``find`` operation.
@@ -271,8 +271,8 @@ def aggregate_numpy_all(collection, pipeline, *, schema=None, **kwargs):
271271
against which to run the ``find`` operation.
272272
- `query`: A mapping containing the query to use for the find operation.
273273
- `schema` (optional): Instance of :class:`~pymongoarrow.schema.Schema`.
274-
If the schema is not given, it will be inferred using the first
275-
document in the result set.
274+
If the schema is not given, it will be inferred using the data in the
275+
result set.
276276
277277
Additional keyword-arguments passed to this method will be passed
278278
directly to the underlying ``aggregate`` operation.
@@ -338,8 +338,8 @@ def find_polars_all(collection, query, *, schema=None, **kwargs):
338338
against which to run the ``find`` operation.
339339
- `query`: A mapping containing the query to use for the find operation.
340340
- `schema` (optional): Instance of :class:`~pymongoarrow.schema.Schema`.
341-
If the schema is not given, it will be inferred using the first
342-
document in the result set.
341+
If the schema is not given, it will be inferred using the data in the
342+
result set.
343343
344344
Additional keyword-arguments passed to this method will be passed
345345
directly to the underlying ``find`` operation.
@@ -361,8 +361,8 @@ def aggregate_polars_all(collection, pipeline, *, schema=None, **kwargs):
361361
against which to run the ``find`` operation.
362362
- `pipeline`: A list of aggregation pipeline stages.
363363
- `schema` (optional): Instance of :class:`~pymongoarrow.schema.Schema`.
364-
If the schema is not given, it will be inferred using the first
365-
document in the result set.
364+
If the schema is not given, it will be inferred using the data in the
365+
result set.
366366
367367
Additional keyword-arguments passed to this method will be passed
368368
directly to the underlying ``aggregate`` operation.

bindings/python/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ archs = "x86_64 arm64"
9595
[tool.pytest.ini_options]
9696
minversion = "7"
9797
addopts = ["-ra", "--strict-config", "--strict-markers", "--durations=5", "--junitxml=xunit-results/TEST-results.xml"]
98-
testpaths = ["test", "test/pandas_types"]
98+
testpaths = ["test"]
9999
log_cli_level = "INFO"
100-
norecursedirs = ["test/*"]
101100
faulthandler_timeout = 1500
102101
xfail_strict = true
103102
filterwarnings = [

bindings/python/test/test_arrow.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def setUpClass(cls):
7474
cls.coll = cls.client.pymongoarrow_test.get_collection(
7575
"test", write_concern=WriteConcern(w="majority")
7676
)
77+
cls.addClassCleanup(cls.client.close)
7778

7879
def setUp(self):
7980
self.coll.drop()
@@ -113,6 +114,14 @@ def test_find_simple(self):
113114
self.assertEqual(find_cmd.command_name, "find")
114115
self.assertEqual(find_cmd.command["projection"], {"_id": True, "data": True})
115116

117+
def test_find_repeat_type(self):
118+
expected = Table.from_pydict(
119+
{"_id": [1, 2, 3, 4], "data": [10, 20, 30, None]},
120+
ArrowSchema([("_id", int32()), ("data", int32())]),
121+
)
122+
table = self.run_find({}, schema=Schema({"_id": int32(), "data": int32()}))
123+
self.assertEqual(table, expected)
124+
116125
def test_find_with_projection(self):
117126
expected = Table.from_pydict(
118127
{"_id": [4, 3], "data": [None, 60]},
@@ -266,18 +275,19 @@ def test_pymongo_error(self):
266275
},
267276
ArrowSchema(schema),
268277
)
269-
278+
client = MongoClient(
279+
host="somedomainthatdoesntexist.org",
280+
port=123456789,
281+
serverSelectionTimeoutMS=10,
282+
)
270283
with self.assertRaises(ArrowWriteError) as exc:
271284
write(
272-
MongoClient(
273-
host="somedomainthatdoesntexist.org",
274-
port=123456789,
275-
serverSelectionTimeoutMS=10,
276-
).pymongoarrow_test.get_collection(
285+
client.pymongoarrow_test.get_collection(
277286
"test", write_concern=WriteConcern(w="majority")
278287
),
279288
data,
280289
)
290+
client.close()
281291
self.assertEqual(
282292
exc.exception.details.keys(),
283293
{"nInserted", "writeConcernErrors", "writeErrors"},
@@ -840,6 +850,7 @@ def setUpClass(cls):
840850
cls.client = client_context.get_client(
841851
event_listeners=[cls.getmore_listener, cls.cmd_listener]
842852
)
853+
cls.addClassCleanup(cls.client.close)
843854

844855
def test_find_decimal128(self):
845856
oids = list(ObjectId() for i in range(4))

bindings/python/test/test_datetime.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def setUp(self):
4444
for doc in self.coll.find({}, sort=[("_id", ASCENDING)]):
4545
self.expected_times.append(doc["data"])
4646

47+
def tearDown(self):
48+
self.client.close()
49+
4750
def test_context_creation_fails_with_unsupported_granularity(self):
4851
unsupported_granularities = ["s", "us", "ns"]
4952
for g in unsupported_granularities:

bindings/python/test/test_numpy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def setUpClass(cls):
4242
)
4343
cls.schema = {}
4444

45+
@classmethod
46+
def tearDownClass(cls):
47+
cls.client.close()
48+
4549
def assert_numpy_equal(self, actual, expected):
4650
self.assertIsInstance(actual, dict)
4751
for field in expected:

bindings/python/test/test_pandas.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def setUpClass(cls):
4747
event_listeners=[cls.getmore_listener, cls.cmd_listener]
4848
)
4949

50+
@classmethod
51+
def tearDownClass(cls):
52+
cls.client.close()
53+
5054

5155
class TestExplicitPandasApi(PandasTestBase):
5256
@classmethod

bindings/python/test/test_polars.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def setUpClass(cls):
5050
event_listeners=[cls.getmore_listener, cls.cmd_listener],
5151
uuidRepresentation="standard",
5252
)
53+
cls.addClassCleanup(cls.client.close)
5354

5455

5556
class TestExplicitPolarsApi(PolarsTestBase):
@@ -182,11 +183,11 @@ def test_polars_types(self):
182183
"Boolean": pl.Series([True, False, None]),
183184
}
184185

185-
df_in = pl.DataFrame._from_dict(data=data, schema=pl_schema)
186+
df_in = pl.from_dict(data=data, schema=pl_schema)
186187
self.coll.drop()
187188
write(self.coll, df_in)
188189
df_out = find_polars_all(self.coll, {}, schema=Schema(pa_schema))
189-
pl.testing.assert_frame_equal(df_in, df_out.drop("_id"))
190+
pl.testing.assert_frame_equal(df_in, df_out)
190191

191192
def test_extension_types_fail(self):
192193
"""Confirm failure on ExtensionTypes for Polars.DataFrame.from_arrow"""
@@ -264,10 +265,9 @@ def test_exceptions_for_unsupported_polar_types(self):
264265
class MyObject:
265266
pass
266267

267-
with self.assertRaises(pl.PolarsPanicError) as exc:
268+
with self.assertRaises(pl.exceptions.PanicException) as exc:
268269
df_in = pl.DataFrame(data=[MyObject()] * 2)
269270
write(self.coll, df_in)
270-
self.assertTrue("not implemented" in exc.exception.args[0])
271271

272272
def test_polars_binary_type(self):
273273
"""Demonstrates that binary data is not yet supported. TODO [ARROW-214]
@@ -393,5 +393,5 @@ def test_bson_types(self):
393393
try:
394394
dfpl = pl.from_arrow(table.drop("_id"))
395395
assert dfpl["value"].dtype == data_type["ptype"]
396-
except pl.ComputeError:
396+
except pl.exceptions.ComputeError:
397397
assert isinstance(table["value"].type, pa.ExtensionType)

bindings/python/test/test_pymongoarrow.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def setUpClass(cls):
2626
raise unittest.SkipTest("cannot connect to MongoDB")
2727
cls.client = client_context.get_client()
2828

29+
@classmethod
30+
def tearDownClass(cls):
31+
cls.client.close()
32+
2933
def test_version(self):
3034
self.assertIsNotNone(__version__)
3135
self.assertIsInstance(__version__, str)

0 commit comments

Comments
 (0)