diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 5b7a51c63..57d64763a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -14,8 +14,34 @@ concurrency: cancel-in-progress: true jobs: + unit: + name: "unit - read only fixtures" + runs-on: 'ubuntu-latest' + strategy: + fail-fast: false + + steps: + - name: 'Install packages' + run: | + sudo apt-get -y update + sudo apt-get -y --no-install-recommends install git-lfs + sudo apt-get -y --no-install-recommends install diffstat diffutils git-core python3 python3-cryptography python3-pip python3-rpm python3-setuptools python3-urllib3 + + - uses: actions/checkout@v3 + + - name: 'Change owner to root:root' + run: | + sudo chown -R root:root tests + + - name: 'Run unit tests' + run: | + pip3 config set global.break-system-packages 1 + pip3 install -e . + python3 setup.py test + unit: name: "unit" + needs: "unit - read only fixtures" runs-on: 'ubuntu-latest' strategy: fail-fast: false diff --git a/tests/test_init_package.py b/tests/test_init_package.py index 7fd92ec3a..a99d71163 100644 --- a/tests/test_init_package.py +++ b/tests/test_init_package.py @@ -16,15 +16,10 @@ def suite(): class TestInitPackage(OscTestCase): def _get_fixtures_dir(self): - # workaround for git because it doesn't allow empty dirs - if not os.path.exists(os.path.join(FIXTURES_DIR, 'osctest')): - os.mkdir(os.path.join(FIXTURES_DIR, 'osctest')) return FIXTURES_DIR - def tearDown(self): - if os.path.exists(os.path.join(FIXTURES_DIR, 'osctest')): - os.rmdir(os.path.join(FIXTURES_DIR, 'osctest')) - super().tearDown() + def setUp(self): + super().setUp(copytree=False) def test_simple(self): """initialize a package dir""" diff --git a/tests/test_init_project.py b/tests/test_init_project.py index 4c0f24f61..d30af4a95 100644 --- a/tests/test_init_project.py +++ b/tests/test_init_project.py @@ -17,15 +17,10 @@ def suite(): class TestInitProject(OscTestCase): def _get_fixtures_dir(self): - # workaround for git because it doesn't allow empty dirs - if not os.path.exists(os.path.join(FIXTURES_DIR, 'osctest')): - os.mkdir(os.path.join(FIXTURES_DIR, 'osctest')) return FIXTURES_DIR - def tearDown(self): - if os.path.exists(os.path.join(FIXTURES_DIR, 'osctest')): - os.rmdir(os.path.join(FIXTURES_DIR, 'osctest')) - super().tearDown() + def setUp(self): + super().setUp(copytree=False) def test_simple(self): """initialize a project dir""" diff --git a/tests/test_prdiff.py b/tests/test_prdiff.py index 8e36cb727..a5439260e 100644 --- a/tests/test_prdiff.py +++ b/tests/test_prdiff.py @@ -1,6 +1,8 @@ import os import re +import shutil import sys +import tempfile import unittest import osc.commandline @@ -50,6 +52,18 @@ def suite(): class TestProjectDiff(OscTestCase): diff_hdr = 'Index: %s\n===================================================================' + def setUp(self, copytree=True): + super().setUp(copytree=copytree) + self.tmpdir_fixtures = tempfile.mkdtemp(prefix='osc_test') + shutil.copytree(self._get_fixtures_dir(), os.path.join(self.tmpdir_fixtures, "fixtures")) + + def tearDown(self): + try: + shutil.rmtree(self.tmpdir_fixtures) + except: + pass + super().tearDown() + def _get_fixtures_dir(self): return FIXTURES_DIR @@ -85,10 +99,10 @@ def runner(): os.chdir('/tmp') self.assertRaises(osc.oscerr.WrongArgs, runner) - self._change_to_tmpdir(FIXTURES_DIR, UPSTREAM) + self._change_to_tmpdir(self.tmpdir_fixtures, "fixtures", UPSTREAM) self.assertRaises(osc.oscerr.WrongArgs, runner) - self._change_to_tmpdir(FIXTURES_DIR, BRANCH) + self._change_to_tmpdir(self.tmpdir_fixtures, "fixtures", BRANCH) out = self._run_prdiff() self.assertEqualMultiline(out, exp)