|
5 | 5 | import sqlite3
|
6 | 6 | from dataclasses import dataclass
|
7 | 7 | from typing import Counter, Dict
|
| 8 | +from unittest.mock import patch |
8 | 9 |
|
9 | 10 | import pytest
|
10 | 11 |
|
|
15 | 16 | )
|
16 | 17 |
|
17 | 18 |
|
| 19 | +def test_set_use_sqlite_on_conflict(): |
| 20 | + with patch("sqlite3.sqlite_version_info", (3, 24, 0)): |
| 21 | + cache = FileBackedDict[int]( |
| 22 | + tablename="cache", |
| 23 | + cache_max_size=10, |
| 24 | + cache_eviction_batch_size=10, |
| 25 | + ) |
| 26 | + assert cache._use_sqlite_on_conflict is True |
| 27 | + |
| 28 | + with pytest.raises(RuntimeError): |
| 29 | + with patch("sqlite3.sqlite_version_info", (3, 23, 1)): |
| 30 | + cache = FileBackedDict[int]( |
| 31 | + tablename="cache", |
| 32 | + cache_max_size=10, |
| 33 | + cache_eviction_batch_size=10, |
| 34 | + ) |
| 35 | + assert cache._use_sqlite_on_conflict is False |
| 36 | + |
| 37 | + with patch("sqlite3.sqlite_version_info", (3, 23, 1)), patch( |
| 38 | + "datahub.utilities.file_backed_collections.OVERRIDE_SQLITE_VERSION_REQUIREMENT", |
| 39 | + True, |
| 40 | + ): |
| 41 | + cache = FileBackedDict[int]( |
| 42 | + tablename="cache", |
| 43 | + cache_max_size=10, |
| 44 | + cache_eviction_batch_size=10, |
| 45 | + ) |
| 46 | + assert cache._use_sqlite_on_conflict is False |
| 47 | + |
| 48 | + |
18 | 49 | @pytest.mark.parametrize("use_sqlite_on_conflict", [True, False])
|
19 | 50 | def test_file_dict(use_sqlite_on_conflict: bool) -> None:
|
20 | 51 | cache = FileBackedDict[int](
|
|
0 commit comments