Skip to content

Commit

Permalink
Consumer iterators on <=Py38
Browse files Browse the repository at this point in the history
  • Loading branch information
TimPansino committed Jul 26, 2023
1 parent ef06df5 commit b9a91e5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions tests/datastore_firestore/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def existing_document(collection, reset_firestore):


def _exercise_client(client, collection, existing_document):
assert len(list(client.collections())) == 1
doc = list(client.get_all([existing_document]))[0]
assert len([_ for _ in client.collections()]) == 1
doc = [_ for _ in client.get_all([existing_document])][0]
assert doc.to_dict()["x"] == 1


Expand Down
6 changes: 3 additions & 3 deletions tests/datastore_firestore/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def _exercise_collections(collection):

documents_get = collection.get()
assert len(documents_get) == 2
documents_stream = list(collection.stream())
documents_stream = [_ for _ in collection.stream()]
assert len(documents_stream) == 2
documents_list = list(collection.list_documents())
documents_list = [_ for _ in collection.list_documents()]
assert len(documents_list) == 2


Expand Down Expand Up @@ -67,7 +67,7 @@ def _test():
def test_firestore_collections_generators(collection, assert_trace_for_generator):
collection.add({})
collection.add({})
assert len(list(collection.list_documents())) == 2
assert len([_ for _ in collection.list_documents()]) == 2

assert_trace_for_generator(collection.stream)
assert_trace_for_generator(collection.list_documents)
Expand Down
4 changes: 2 additions & 2 deletions tests/datastore_firestore/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _exercise_documents(collection):
italy_doc.get()
italian_cities = italy_doc.collection("cities")
italian_cities.add({"capital": "Rome"})
retrieved_coll = list(italy_doc.collections())
retrieved_coll = [_ for _ in italy_doc.collections()]
assert len(retrieved_coll) == 1

usa_doc = collection.document("USA")
Expand Down Expand Up @@ -78,7 +78,7 @@ def test_firestore_documents_generators(collection, assert_trace_for_generator):
subcollection_doc.set({})
subcollection_doc.collection("collection1").add({})
subcollection_doc.collection("collection2").add({})
assert len(list(subcollection_doc.collections())) == 2
assert len([_ for _ in subcollection_doc.collections()]) == 2

assert_trace_for_generator(subcollection_doc.collections)

Expand Down
4 changes: 2 additions & 2 deletions tests/datastore_firestore/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def sample_data(collection, reset_firestore):
def _exercise_query(collection):
query = collection.select("x").limit(10).order_by("x").where(field_path="x", op_string="<=", value=3)
assert len(query.get()) == 3
assert len(list(query.stream())) == 3
assert len([_ for _ in query.stream()]) == 3


def test_firestore_query(collection):
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_firestore_query_db_duration(collection):
def _exercise_aggregation_query(collection):
aggregation_query = collection.select("x").where(field_path="x", op_string="<=", value=3).count()
assert aggregation_query.get()[0][0].value == 3
assert list(aggregation_query.stream())[0][0].value == 3
assert [_ for _ in aggregation_query.stream()][0][0].value == 3


def test_firestore_aggregation_query(collection):
Expand Down
10 changes: 5 additions & 5 deletions tests/datastore_firestore/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ def _exercise_transaction_commit(client, collection):
@transactional
def _exercise(transaction):
# get a DocumentReference
list(transaction.get(collection.document("doc1")))
[_ for _ in transaction.get(collection.document("doc1"))]

# get a Query
query = collection.select("x").where(field_path="x", op_string=">", value=2)
assert len(list(transaction.get(query))) == 1
assert len([_ for _ in transaction.get(query)]) == 1

# get_all on a list of DocumentReferences
all_docs = transaction.get_all([collection.document("doc%d" % x) for x in range(1, 4)])
assert len(list(all_docs)) == 3
assert len([_ for _ in all_docs]) == 3

# set and delete methods
transaction.set(collection.document("doc2"), {"x": 0})
transaction.delete(collection.document("doc3"))

_exercise(client.transaction())
assert len(list(collection.list_documents())) == 2
assert len([_ for _ in collection.list_documents()]) == 2


def _exercise_transaction_rollback(client, collection):
Expand All @@ -66,7 +66,7 @@ def _exercise(transaction):

with pytest.raises(RuntimeError):
_exercise(client.transaction())
assert len(list(collection.list_documents())) == 3
assert len([_ for _ in collection.list_documents()]) == 3


def test_firestore_transaction_commit(client, collection):
Expand Down

0 comments on commit b9a91e5

Please sign in to comment.