Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Møldrup committed Jan 6, 2025
1 parent fbddf62 commit ad7f48a
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 49 deletions.
61 changes: 42 additions & 19 deletions .github/workflows/continuous_integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,51 @@ name: Continuous Integration
on: [push, pull_request]

jobs:
lint_and_type_check:
runs-on: ubuntu-latest
lint_and_type_check:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9"
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9"

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install dependencies
run: poetry install --no-interaction
- name: Install dependencies
run: poetry install --no-interaction

- name: Run ruff
run: poetry run ruff check snappylapy
- name: Run ruff
run: poetry run ruff check snappylapy

- name: Run mypy
run: poetry run mypy snappylapy
- name: Run mypy
run: poetry run mypy snappylapy

test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9"

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install dependencies
run: poetry install --no-interaction

- name: Run tests
run: poetry run pytest tests/
125 changes: 95 additions & 30 deletions tests/test_snappylapy.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,111 @@
import pathlib
from snappylapy import Expect
import json
import pytest
from pytest import Pytester

def test_snapshot_string(expect: Expect):
def test_snapshot_string(pytester: Pytester):
"""Test snapshot with string data."""
expect.string("Hello World").to_match_snapshot()
test_code = """
from snappylapy import Expect
def test_snapshot_bytes(expect: Expect):
def test_snapshot_string(expect: Expect):
expect.string("Hello World").to_match_snapshot()
"""
pytester.makepyfile(test_code)
result = pytester.runpytest('-v')
assert result.ret == 0

def test_snapshot_bytes(pytester: Pytester):
"""Test snapshot with bytes data."""
expect.bytes(b"Hello World", name="bytes_snapshot").to_match_snapshot()
test_code = """
from snappylapy import Expect
def test_snapshot_bytes(expect: Expect):
expect.bytes(b"Hello World", name="bytes_snapshot").to_match_snapshot()
"""
pytester.makepyfile(test_code)
result = pytester.runpytest('-v')
assert result.ret == 0

def test_snapshot_dict(expect: Expect):
def test_snapshot_dict(pytester: Pytester):
"""Test snapshot with dictionary data."""
expect.dict({
"name": "John Doe",
"age": 31
}).to_match_snapshot()
test_code = """
from snappylapy import Expect
def test_snapshot_list(expect: Expect):
def test_snapshot_dict(expect: Expect):
expect.dict({
"name": "John Doe",
"age": 31
}).to_match_snapshot()
"""
pytester.makepyfile(test_code)
result = pytester.runpytest('-v')
assert result.ret == 0

def test_snapshot_list(pytester: Pytester):
"""Test snapshot with list data."""
expect.list(["John Doe", 31]).to_match_snapshot()
test_code = """
from snappylapy import Expect
def test_snapshot_list(expect: Expect):
expect.list(["John Doe", 31]).to_match_snapshot()
"""
pytester.makepyfile(test_code)
result = pytester.runpytest('-v')
assert result.ret == 0

def test_snapshot_json_bytes(expect: Expect):
def test_snapshot_json_bytes(pytester: Pytester):
"""Test snapshot with JSON bytes data."""
data = json.dumps({"name": "John Doe", "age": 31}).encode()
expect.bytes(data, name="json_bytes_snapshot").to_match_snapshot()
test_code = """
import json
from snappylapy import Expect
def test_snapshot_python_code(expect: Expect):
def test_snapshot_json_bytes(expect: Expect):
data = json.dumps({"name": "John Doe", "age": 31}).encode()
expect.bytes(data, name="json_bytes_snapshot").to_match_snapshot()
"""
pytester.makepyfile(test_code)
result = pytester.runpytest('-v')
assert result.ret == 0

def test_snapshot_python_code(pytester: Pytester):
"""Test snapshot with Python code string."""
py_code = "print('Hello World')"
expect.string(py_code, filetype="py", name="python_code_snapshot").to_match_snapshot()
test_code = """
from snappylapy import Expect
def test_snapshot_python_code(expect: Expect):
py_code = "print('Hello World')"
expect.string(py_code, filetype="py", name="python_code_snapshot").to_match_snapshot()
"""
pytester.makepyfile(test_code)
result = pytester.runpytest('-v')
assert result.ret == 0

def test_snapshot_with_custom_directories(expect: Expect):
def test_snapshot_with_custom_directories(pytester: Pytester):
"""Test snapshot with custom directories."""
expect.snapshot_dir = pathlib.Path("__snapshots_other_location__")
expect.test_results_dir = pathlib.Path("__test_results_other_location__")
expect.string("Hello World").to_match_snapshot()
test_code = """
import pathlib
from snappylapy import Expect
def test_snapshot_multiple_assertions(expect: Expect):
def test_snapshot_with_custom_directories(expect: Expect):
expect.snapshot_dir = pathlib.Path("__snapshots_other_location__")
expect.test_results_dir = pathlib.Path("__test_results_other_location__")
expect.string("Hello World").to_match_snapshot()
"""
pytester.makepyfile(test_code)
result = pytester.runpytest('-v')
assert result.ret == 0

def test_snapshot_multiple_assertions(pytester: Pytester):
"""Test snapshot with multiple assertions."""
expect.string("Hello World").to_match_snapshot()
expect.dict({
"name": "John Doe",
"age": 31
}).to_match_snapshot()
test_code = """
from snappylapy import Expect
def test_snapshot_multiple_assertions(expect: Expect):
expect.string("Hello World").to_match_snapshot()
expect.dict({
"name": "John Doe",
"age": 31
}).to_match_snapshot()
"""
pytester.makepyfile(test_code)
result = pytester.runpytest('-v')
assert result.ret == 0

0 comments on commit ad7f48a

Please sign in to comment.