Skip to content

Commit

Permalink
Add integration tests for sources/patches
Browse files Browse the repository at this point in the history
Signed-off-by: Nikola Forró <nforro@redhat.com>
  • Loading branch information
nforro committed Mar 16, 2022
1 parent fd3802c commit 5615235
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 12 deletions.
11 changes: 11 additions & 0 deletions tests/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

from pathlib import Path

TESTS_DIR = Path(__file__).parent
DATA_DIR = TESTS_DIR / "data"
SPEC_MINIMAL = DATA_DIR / "spec_minimal"
SPEC_PATCHLIST = DATA_DIR / "spec_patchlist"

SPECFILE = "test.spec"
File renamed without changes.
18 changes: 18 additions & 0 deletions tests/data/spec_patchlist/patch0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
From b7af0b9194585c6d208de3a0e9978d5ad9c5d97b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
Date: Wed, 16 Mar 2022 10:29:59 +0100
Subject: [PATCH 1/3] patch0

---
test.txt | 1 +
1 file changed, 1 insertion(+)

diff --git a/test.txt b/test.txt
index 9daeafb..dec2cbe 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1,2 @@
test
+test
--
2.35.1
19 changes: 19 additions & 0 deletions tests/data/spec_patchlist/patch1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
From 6d5d1561b3ccf2df9d001a7af011144acc352361 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
Date: Wed, 16 Mar 2022 10:30:15 +0100
Subject: [PATCH 2/3] patch1

---
test.txt | 1 +
1 file changed, 1 insertion(+)

diff --git a/test.txt b/test.txt
index dec2cbe..0867e73 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,3 @@
test
test
+test
--
2.35.1
20 changes: 20 additions & 0 deletions tests/data/spec_patchlist/patch2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
From ae1d3bbca0caf1cce1842ceab4c6d7252c0a7bd8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
Date: Wed, 16 Mar 2022 10:30:29 +0100
Subject: [PATCH 3/3] patch2

---
test.txt | 1 +
1 file changed, 1 insertion(+)

diff --git a/test.txt b/test.txt
index 0867e73..d0c7fbe 100644
--- a/test.txt
+++ b/test.txt
@@ -1,3 +1,4 @@
test
test
test
+test
--
2.35.1
Binary file added tests/data/spec_patchlist/test-0.1.tar.xz
Binary file not shown.
27 changes: 27 additions & 0 deletions tests/data/spec_patchlist/test.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Name: test
Version: 0.1
Release: 1%{?dist}
Summary: Test package

License: MIT

Source: %{name}-%{version}.tar.xz
Patch0: patch0.patch


%description
Test package


%patchlist
patch1.patch
patch2.patch


%prep
%autosetup


%changelog
* Thu Jun 07 2018 Nikola Forró <nforro@redhat.com> - 0.1-1
- first version
22 changes: 22 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

import shutil

import pytest

from tests.constants import SPEC_MINIMAL, SPEC_PATCHLIST, SPECFILE


@pytest.fixture(scope="function")
def spec_minimal(tmp_path):
specfile_path = tmp_path / SPECFILE
shutil.copyfile(SPEC_MINIMAL / SPECFILE, specfile_path)
return specfile_path


@pytest.fixture(scope="function")
def spec_patchlist(tmp_path):
destination = tmp_path / "spec_patchlist"
shutil.copytree(SPEC_PATCHLIST, destination)
return destination / SPECFILE
47 changes: 35 additions & 12 deletions tests/integration/test_specfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# SPDX-License-Identifier: MIT

import datetime
import shutil
import subprocess
from pathlib import Path

import pytest
from flexmock import flexmock
Expand All @@ -13,16 +11,41 @@
from specfile.sections import Section
from specfile.specfile import Specfile

TESTS_DIR = Path(__file__).parent
DATA_DIR = TESTS_DIR / "data"
SPECFILE = DATA_DIR / "test.spec"

def test_sources(spec_minimal):
spec = Specfile(spec_minimal)
source = "test.tar.gz"
with spec.sources() as sources:
assert not sources
sources.append(source)
assert sources.count(source) == len(sources) == 1
with spec.tags() as tags:
assert [source] == [t.value for t in tags if t.name.startswith("Source")]
with spec.sources() as sources:
sources.remove(source)
assert not sources
sources.insert(0, source)
assert sources[0].location == source
sources.clear()
assert not sources

@pytest.fixture(scope="function")
def specfile(tmp_path):
specfile_path = tmp_path / "test.spec"
shutil.copyfile(SPECFILE, specfile_path)
return specfile_path

def test_patches(spec_patchlist):
spec = Specfile(spec_patchlist)
patch = "test.patch"
with spec.patches() as patches:
patches.insert(0, patch)
assert patches[0].location == patch
assert patches[1].index == 1
with spec.tags() as tags:
assert len([t for t in tags if t.name.startswith("Patch")]) == 2
with spec.patches() as patches:
patches.remove(patch)
patches.insert(1, patch)
patches[1].comments.append("test")
with spec.sections() as sections:
assert len([sl for sl in sections.patchlist if sl]) == 4
assert sections.patchlist[0] == "# test"


@pytest.mark.parametrize(
Expand Down Expand Up @@ -91,7 +114,7 @@ def specfile(tmp_path):
],
)
def test_add_changelog_entry(
specfile, rpmdev_packager_available, entry, author, email, timestamp, result
spec_minimal, rpmdev_packager_available, entry, author, email, timestamp, result
):
if not rpmdev_packager_available:
flexmock(subprocess).should_receive("check_output").with_args(
Expand All @@ -101,7 +124,7 @@ def test_add_changelog_entry(
flexmock(subprocess).should_receive("check_output").with_args(
"rpmdev-packager"
).and_return(b"John Doe <john@doe.net>")
spec = Specfile(specfile)
spec = Specfile(spec_minimal)
if not rpmdev_packager_available:
with pytest.raises(SpecfileException):
spec.add_changelog_entry(entry, author, email, timestamp)
Expand Down

0 comments on commit 5615235

Please sign in to comment.