|
| 1 | +import collections |
1 | 2 | import datetime as dt |
2 | 3 | import sys |
3 | 4 | from pathlib import Path |
4 | 5 | from typing import List, Tuple, Union |
5 | 6 |
|
| 7 | +import databento |
6 | 8 | import numpy as np |
7 | 9 | import pandas as pd |
8 | 10 | import pytest |
@@ -184,6 +186,18 @@ def test_to_ndarray_with_stub_data_returns_expected_array() -> None: |
184 | 186 | ) |
185 | 187 |
|
186 | 188 |
|
| 189 | +def test_iterator_produces_expected_data() -> None: |
| 190 | + # Arrange |
| 191 | + stub_data = get_test_data(schema=Schema.MBO) |
| 192 | + data = Bento.from_bytes(data=stub_data) |
| 193 | + |
| 194 | + # Act (consume iterator) |
| 195 | + handler = collections.deque(data) |
| 196 | + |
| 197 | + # Assert |
| 198 | + assert len(handler) == 2 |
| 199 | + |
| 200 | + |
187 | 201 | def test_replay_with_stub_data_record_passes_to_callback() -> None: |
188 | 202 | # Arrange |
189 | 203 | stub_data = get_test_data(schema=Schema.MBO) |
@@ -372,14 +386,28 @@ def test_to_df_with_pretty_px_with_various_schemas_converts_prices_as_expected( |
372 | 386 | def test_from_file_given_various_paths_returns_expected_metadata( |
373 | 387 | expected_schema: Schema, |
374 | 388 | ) -> None: |
375 | | - # Arrange, Act |
| 389 | + # Arrange |
376 | 390 | path = get_test_data_path(schema=expected_schema) |
| 391 | + |
| 392 | + # Act |
377 | 393 | data = Bento.from_file(path=path) |
378 | 394 |
|
379 | 395 | # Assert |
380 | 396 | assert data.schema == expected_schema |
381 | 397 |
|
382 | 398 |
|
| 399 | +def test_from_dbn_alias() -> None: |
| 400 | + # Arrange |
| 401 | + path = get_test_data_path(schema=Schema.MBO) |
| 402 | + |
| 403 | + # Act |
| 404 | + data = databento.from_dbn(path=path) |
| 405 | + |
| 406 | + # Assert |
| 407 | + assert data.schema == Schema.MBO |
| 408 | + assert data.record_count == 2 |
| 409 | + |
| 410 | + |
383 | 411 | def test_mbo_to_csv_writes_expected_file_to_disk(tmp_path: Path) -> None: |
384 | 412 | # Arrange |
385 | 413 | test_data_path = get_test_data_path(schema=Schema.MBO) |
@@ -621,9 +649,9 @@ def test_bento_iterable() -> None: |
621 | 649 | "22993, 1170352)" |
622 | 650 | ) |
623 | 651 | assert ( |
624 | | - str(record_list[1]) == "(14, 160, 1, 5482, 1609160400000429831, 647784973705, " |
625 | | - "3722750000000, 1, -128, 0, b'C', b'A', 1609160400000704060, " |
626 | | - "22993, 1170352)" |
| 652 | + str(record_list[1]) == "(14, 160, 1, 5482, 1609160400000431665, 647784973631, " |
| 653 | + "3723000000000, 1, -128, 0, b'C', b'A', 1609160400000711344, " |
| 654 | + "19621, 1170353)" |
627 | 655 | ) |
628 | 656 |
|
629 | 657 |
|
@@ -651,14 +679,14 @@ def test_bento_iterable_parallel() -> None: |
651 | 679 | "22993, 1170352)" |
652 | 680 | ) |
653 | 681 | assert ( |
654 | | - str(next(second)) == "(14, 160, 1, 5482, 1609160400000429831, 647784973705, " |
655 | | - "3722750000000, 1, -128, 0, b'C', b'A', 1609160400000704060, " |
656 | | - "22993, 1170352)" |
| 682 | + str(next(second)) == "(14, 160, 1, 5482, 1609160400000431665, 647784973631, " |
| 683 | + "3723000000000, 1, -128, 0, b'C', b'A', 1609160400000711344, " |
| 684 | + "19621, 1170353)" |
657 | 685 | ) |
658 | 686 | assert ( |
659 | | - str(next(first)) == "(14, 160, 1, 5482, 1609160400000429831, 647784973705, " |
660 | | - "3722750000000, 1, -128, 0, b'C', b'A', 1609160400000704060, " |
661 | | - "22993, 1170352)" |
| 687 | + str(next(first)) == "(14, 160, 1, 5482, 1609160400000431665, 647784973631, " |
| 688 | + "3723000000000, 1, -128, 0, b'C', b'A', 1609160400000711344, " |
| 689 | + "19621, 1170353)" |
662 | 690 | ) |
663 | 691 |
|
664 | 692 |
|
|
0 commit comments