SameerMesiah97 commented on code in PR #66658:
URL: https://github.com/apache/airflow/pull/66658#discussion_r3221597164
##########
providers/elasticsearch/tests/unit/elasticsearch/hooks/test_elasticsearch.py:
##########
@@ -109,22 +126,72 @@ def test_fetchone(self):
assert cursor.fetchone() == ROWS[0]
- def test_fetchmany(self):
+ @pytest.mark.parametrize(
+ ("size", "expected"),
+ [
+ (1, ROWS[:1]),
+ (2, ROWS[:2]),
+ (5, ROWS[:5]),
+ ],
+ )
+ def test_fetchmany(self, size, expected):
cursor = ElasticsearchSQLCursor(es=self.es, options={})
cursor.execute("SELECT * FROM hollywood.actors")
- with pytest.raises(NotImplementedError):
- cursor.fetchmany()
+ records = cursor.fetchmany(size)
+
+ assert records == expected
+
+ def test_fetchmany_consumes_rows(self):
+ cursor = ElasticsearchSQLCursor(es=self.es, options={})
+ cursor.execute("SELECT * FROM hollywood.actors")
+
+ first_batch = cursor.fetchmany(2)
+ second_batch = cursor.fetchmany(2)
+
+ assert first_batch == ROWS[:2]
+ assert second_batch == ROWS[2:4]
+
+ def test_fetchmany_exhausts_rows(self):
+ cursor = ElasticsearchSQLCursor(es=self.es, options={})
+ cursor.execute("SELECT * FROM hollywood.actors")
+
+ records = cursor.fetchmany(100)
+
+ assert records == ROWS
+
+ # Further calls should return empty list.
+ assert cursor.fetchmany(10) == []
+
+ def test_fetchmany_uses_default_fetch_size(self):
+ cursor = ElasticsearchSQLCursor(es=self.es, fetch_size=2)
+ cursor.execute("SELECT * FROM hollywood.actors")
+
+ records = cursor.fetchmany()
+
+ assert records == ROWS[:2]
def test_fetchall(self):
Review Comment:
A functional version of this test has now been added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]