File: test_bench_sync.py

package info (click to toggle)
python-odmantic 1.0.2-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,640 kB
  • sloc: python: 8,547; sh: 37; makefile: 34; xml: 13; javascript: 3
file content (74 lines) | stat: -rw-r--r-- 1,988 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import pytest

from odmantic import SyncEngine

from .models import VALID_LEVELS, SmallJournal


@pytest.fixture(params=[10, 50, 100])
def count(request):
    return request.param


def test_insert_small_single(benchmark, sync_engine: SyncEngine, count: int):
    instances = list(SmallJournal.get_random_instances("test_write_small", count))

    @benchmark
    def _():
        for instance in instances:
            sync_engine.save(instance)


def test_write_small_bulk(
    benchmark,
    sync_engine: SyncEngine,
    count: int,
):
    instances = list(SmallJournal.get_random_instances("test_write_small", count))

    @benchmark
    def _():
        sync_engine.save_all(instances)


def test_filter_by_level_small(benchmark, sync_engine: SyncEngine, count: int):
    instances = list(SmallJournal.get_random_instances("test_write_small", count))
    sync_engine.save_all(instances)

    @benchmark
    def _():
        total = 0
        for level in VALID_LEVELS:
            total += len(
                list(sync_engine.find(SmallJournal, SmallJournal.level == level))
            )


def test_filter_limit_skip_by_level_small(
    benchmark, sync_engine: SyncEngine, count: int
):
    instances = list(SmallJournal.get_random_instances("test_write_small", count))
    sync_engine.save_all(instances)

    @benchmark
    def _():
        total = 0
        for level in VALID_LEVELS:
            total += len(
                list(
                    sync_engine.find(
                        SmallJournal, SmallJournal.level == level, limit=20, skip=20
                    )
                )
            )


def test_find_one_by_id(benchmark, sync_engine: SyncEngine, count: int):
    instances = list(SmallJournal.get_random_instances("test_write_small", count))
    sync_engine.save_all(instances)
    ids = [instance.id for instance in instances]

    @benchmark
    def _():
        for id_ in ids:
            sync_engine.find_one(SmallJournal, SmallJournal.id == id_)