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