add integration tests

This commit is contained in:
Jörg Thalheim 2021-01-09 08:55:05 +01:00
parent f6e0adb59b
commit 05dccf154e
No known key found for this signature in database
GPG Key ID: 003F2096411B5F92
8 changed files with 98 additions and 18 deletions

View File

@ -8,4 +8,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v12
- run: nix-build -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixpkgs-unstable.tar.gz
- name: build
run: NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixpkgs-unstable.tar.gz nix-build
- name: Run tests
run: NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixpkgs-unstable.tar.gz nix-shell --command "py.test -s ."

View File

@ -16,12 +16,11 @@ python3.pkgs.buildPythonApplication rec {
mypy
# technically not a test input, but we need it for development in PATH
nixFlakes
nix-prefetch
];
checkPhase = ''
echo -e "\x1b[32m## run black\x1b[0m"
LC_ALL=en_US.utf-8 black --check .
echo -e "\x1b[32m## run pytest\x1b[0m"
py.test -s .
echo -e "\x1b[32m## run flake8\x1b[0m"
flake8 nix_update
echo -e "\x1b[32m## run mypy\x1b[0m"

View File

@ -3,12 +3,12 @@ from dataclasses import dataclass
@dataclass
class Options:
version: str
import_path: str
commit: bool
attribute: str
shell: bool
run: bool
build: bool
test: bool
version_regex: str
version: str = "auto"
version_regex: str = "(.*)"
import_path: str = "./."
commit: bool = False
shell: bool = False
run: bool = False
build: bool = False
test: bool = False

33
tests/conftest.py Normal file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env python3
import pytest
import sys
from pathlib import Path
from typing import Type, Iterator, Any
import shutil
import tempfile
from contextlib import contextmanager
TEST_ROOT = Path(__file__).parent.resolve()
sys.path.append(str(TEST_ROOT.parent))
class Helpers:
@staticmethod
def root() -> Path:
return TEST_ROOT
@staticmethod
@contextmanager
def testpkgs() -> Iterator[Path]:
with tempfile.TemporaryDirectory() as tmpdirname:
shutil.copytree(
Helpers.root().joinpath("testpkgs"), tmpdirname, dirs_exist_ok=True
)
yield Path(tmpdirname)
@pytest.fixture
def helpers() -> Type[Helpers]:
return Helpers

View File

@ -1,16 +1,14 @@
#!/usr/bin/env python3
from pathlib import Path
from unittest import TestCase
from nix_update.git import old_version_from_diff
import conftest
TEST_ROOT = Path(__file__).parent.resolve()
class WordDiff(TestCase):
def test_worddiff(self) -> None:
with open(TEST_ROOT.joinpath("consul.patch")) as f:
diff = f.read()
def test_worddiff(helpers: conftest.Helpers) -> None:
with open(helpers.root().joinpath("consul.patch")) as f:
diff = f.read()
s = old_version_from_diff(diff, 5, "1.9.0")
self.assertEqual(s, "1.8.6")
assert s == "1.8.6"

27
tests/test_pypi.py Normal file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env python3
from nix_update.options import Options
from nix_update.update import update
import subprocess
import conftest
def test_update(helpers: conftest.Helpers) -> None:
with helpers.testpkgs() as path:
opts = Options(attribute="pypi", import_path=path)
update(opts)
version = subprocess.run(
[
"nix",
"eval",
"--raw",
"--experimental-features",
"nix-command",
"-f",
path,
"pypi.version",
],
text=True,
stdout=subprocess.PIPE,
)
assert version.stdout.strip() >= "3.0.1"

View File

@ -0,0 +1,4 @@
{ pkgs ? import <nixpkgs> {} }:
{
pypi = pkgs.python3.pkgs.callPackage ./pypi.nix {};
}

16
tests/testpkgs/pypi.nix Normal file
View File

@ -0,0 +1,16 @@
{ buildPythonPackage, fetchPypi, twisted, mock, pytestCheckHook }:
buildPythonPackage rec {
pname = "python-mpd2";
version = "1.0.0";
src = fetchPypi {
inherit pname version;
sha256 = "0000000000000000000000000000000000000000000000000000";
};
checkInputs = [
pytestCheckHook
twisted
mock
];
pytestFlagsArray = [ "mpd/tests.py" ];
}