Skip to content

Commit

Permalink
add empty list test + reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
lazargugleta committed Jun 27, 2024
1 parent 892053a commit d8fd09e
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions bindings/python/test/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.
from datetime import datetime
from unittest import TestCase
import pytest

import pytest
from bson import Binary, Code, Decimal128, Int64, ObjectId
from pyarrow import Table, field, float64, int64, list_, struct, timestamp
from pyarrow import schema as ArrowSchema
Expand Down Expand Up @@ -98,20 +98,19 @@ def test_list_of_list_projection(self):

def test_py_list_projection(self):
schema = Schema(
{
"_id": ObjectId,
"list": [(struct([field("a", int64()), field("b", float64())]))]
}
{"_id": ObjectId, "list": [(struct([field("a", int64()), field("b", float64())]))]}
)

self.assertEqual(schema._get_projection(), {"_id": True, "list": {"a": True, "b": True}})

def test_py_list_with_multiple_fields_raises(self):

with pytest.raises(ValueError, match="list field in schema must contain exactly one element, not 2"):
_ = Schema(
{
"_id": ObjectId,
"list": [([field("a", int64()), field("b", float64())])]
}
)
with pytest.raises(
ValueError, match="list field in schema must contain exactly one element, not 2"
):
_ = Schema({"_id": ObjectId, "list": [([field("a", int64()), field("b", float64())])]})

def test_py_empty_list_raises(self):
with pytest.raises(
ValueError, match="list field in schema must contain exactly one element, not 0"
):
_ = Schema({"_id": ObjectId, "list": []})

0 comments on commit d8fd09e

Please sign in to comment.