File: run_tests.py

package info (click to toggle)
pydantic-core 2.37.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,784 kB
  • sloc: python: 34,800; javascript: 211; makefile: 126
file content (65 lines) | stat: -rw-r--r-- 1,847 bytes parent folder | download
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
import base64
import importlib
import re
import sys
import traceback
from io import BytesIO
from pathlib import Path
from zipfile import ZipFile

import micropip
import pyodide
import pytest

# this seems to be required for me on M1 Mac
sys.setrecursionlimit(200)


async def main(tests_zip: str, tag_name: str):
    print(f'Using pyodide version: {pyodide.__version__}')
    print(f'Extracting test files (size: {len(tests_zip):,})...')
    # File saved on the GH release
    pydantic_core_wheel = (
        'https://githubproxy.samuelcolvin.workers.dev/pydantic/pydantic-core/releases/'
        f'download/{tag_name}/pydantic_core-{tag_name.lstrip("v")}-cp312-cp312-emscripten_3_1_58_wasm32.whl'
    )
    zip_file = ZipFile(BytesIO(base64.b64decode(tests_zip)))
    count = 0
    for name in zip_file.namelist():
        if name.endswith('.py'):
            path, subs = re.subn(r'^pydantic-core-.+?/tests/', 'tests/', name)
            if subs:
                count += 1
                path = Path(path)
                path.parent.mkdir(parents=True, exist_ok=True)
                with zip_file.open(name, 'r') as f:
                    path.write_bytes(f.read())

    print(f'Mounted {count} test files, installing dependencies...')

    await micropip.install(
        [
            'dirty-equals',
            'hypothesis',
            'pytest-speed',
            'pytest-mock',
            'tzdata',
            'inline-snapshot<0.21',
            'typing-extensions>=4.14.1',
            'typing-inspection',
            pydantic_core_wheel,
        ]
    )
    importlib.invalidate_caches()

    # print('installed packages:')
    # print(micropip.list())
    print('Running tests...')
    pytest.main()


try:
    await main(tests_zip, pydantic_core_version)  # noqa: F821,F704
except Exception:
    traceback.print_exc()
    raise