Skip to content

Commit

Permalink
Add basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
manics committed May 22, 2024
1 parent ae85188 commit 456fe2f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test

on:
pull_request:
push:
workflow_dispatch:

jobs:
pre-commit:
runs-on: ubuntu-22.04
timeout-minutes: 2

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: pip

# ref: https://github.com/pre-commit/action
# Run "pre-commit run --all-files"
- uses: pre-commit/[email protected]

test:
runs-on: ubuntu-22.04
timeout-minutes: 2

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: pip

- run: |
pip install ".[test]"
- run: |
python -mpytest -v
26 changes: 26 additions & 0 deletions tests/test_project_costs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from difflib import unified_diff
from pathlib import Path

import yaml

from aws_project_costs.project_costs import analyse_costs_csv

# from aws_project_costs.schema import validate

EXAMPLE_DIR = Path(__file__).parent / ".." / "example"


def test_analyse_costs_csv(tmp_path):
config_yaml = EXAMPLE_DIR / "projects.yaml"
input_csv = EXAMPLE_DIR / "2024-01-01_2024-02-01.csv"
output_csv = tmp_path / "output.csv"
reference_csv = EXAMPLE_DIR / "output.csv"

with (config_yaml).open() as f:
cfg = yaml.safe_load(f)
analyse_costs_csv(cfg, input_csv, output_csv)

reference = reference_csv.read_text().splitlines()
output = output_csv.read_text().splitlines()
diff = list(unified_diff(reference, output))
assert not diff, "\n".join(diff)

0 comments on commit 456fe2f

Please sign in to comment.