|
| 1 | +name: Test PyPI Package |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Version to test (e.g., 0.1.0). Leave empty for latest.' |
| 8 | + required: false |
| 9 | + default: '' |
| 10 | + |
| 11 | +jobs: |
| 12 | + smoke_test: |
| 13 | + name: Smoke test on ${{ matrix.os }} (Python ${{ matrix.python-version }}) |
| 14 | + runs-on: ${{ matrix.os }} |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + os: [ubuntu-latest, macos-latest] |
| 19 | + python-version: ['3.12', '3.13'] |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Set up Python ${{ matrix.python-version }} |
| 23 | + uses: actions/setup-python@v5 |
| 24 | + with: |
| 25 | + python-version: ${{ matrix.python-version }} |
| 26 | + |
| 27 | + - name: Install package from PyPI |
| 28 | + run: | |
| 29 | + python -m pip install --upgrade pip |
| 30 | + if [ -z "${{ inputs.version }}" ]; then |
| 31 | + echo "Installing latest version from PyPI..." |
| 32 | + pip install kh57 |
| 33 | + else |
| 34 | + echo "Installing version ${{ inputs.version }} from PyPI..." |
| 35 | + pip install kh57==${{ inputs.version }} |
| 36 | + fi |
| 37 | +
|
| 38 | + - name: Show installed version |
| 39 | + run: | |
| 40 | + python -c "import kh57; print('kh57 imported successfully')" |
| 41 | + pip show kh57 |
| 42 | +
|
| 43 | + - name: Smoke test - core primitives |
| 44 | + run: | |
| 45 | + python << 'EOF' |
| 46 | + import random |
| 47 | + import kh57 |
| 48 | +
|
| 49 | + # 1. uniform_hash is deterministic |
| 50 | + h1 = kh57.uniform_hash(12345) |
| 51 | + h2 = kh57.uniform_hash(12345) |
| 52 | + assert h1 == h2, f"uniform_hash not deterministic" |
| 53 | + assert isinstance(h1, int) |
| 54 | + print(f" uniform_hash(12345) ok") |
| 55 | +
|
| 56 | + # 2. kh57 encode/recover round-trip |
| 57 | + for key in [0, 1, 42, 12345, (1 << 57) - 1]: |
| 58 | + encoded = kh57.kh57(key) |
| 59 | + recovered = kh57.recover(encoded) |
| 60 | + assert recovered == key, f"kh57/recover broken for {key}: got {recovered}" |
| 61 | + print(f" kh57/recover round-trip ok") |
| 62 | +
|
| 63 | + # 3. sampling from a MemBackend |
| 64 | + backend = kh57.MemBackend() |
| 65 | + for i in range(1000): |
| 66 | + # store under kh57-encoded 8-byte big-endian keys, as the docstring specifies |
| 67 | + backend.put(kh57.kh57(i).to_bytes(8, "big"), f"v{i}".encode()) |
| 68 | +
|
| 69 | + rng_a = random.Random(42) |
| 70 | + rng_b = random.Random(42) |
| 71 | + samples_a = kh57.sample(backend, n=10, begin=0, end=1000, rng=rng_a) |
| 72 | + samples_b = kh57.sample(backend, n=10, begin=0, end=1000, rng=rng_b) |
| 73 | + assert set(samples_a) == set(samples_b), "sampling not deterministic with same seeded rng" |
| 74 | + assert len(samples_a) == 10, f"expected 10 samples, got {len(samples_a)}" |
| 75 | + # every sample must fall in the queried range |
| 76 | + for k, _v in samples_a: |
| 77 | + assert 0 <= k < 1000, f"sample key {k} out of range" |
| 78 | + print(f" sampling deterministic + in-range: {len(samples_a)} samples") |
| 79 | +
|
| 80 | + print("All smoke tests passed!") |
| 81 | + EOF |
0 commit comments