mirror of
https://github.com/Mic92/nix-update.git
synced 2024-09-17 13:27:27 +03:00
add integration tests
This commit is contained in:
parent
f6e0adb59b
commit
05dccf154e
5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
@ -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 ."
|
||||
|
@ -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"
|
||||
|
@ -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
33
tests/conftest.py
Normal 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
|
@ -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
27
tests/test_pypi.py
Normal 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"
|
4
tests/testpkgs/default.nix
Normal file
4
tests/testpkgs/default.nix
Normal file
@ -0,0 +1,4 @@
|
||||
{ pkgs ? import <nixpkgs> {} }:
|
||||
{
|
||||
pypi = pkgs.python3.pkgs.callPackage ./pypi.nix {};
|
||||
}
|
16
tests/testpkgs/pypi.nix
Normal file
16
tests/testpkgs/pypi.nix
Normal 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" ];
|
||||
}
|
Loading…
Reference in New Issue
Block a user