1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-02-09 20:45:47 +01:00

Fix tests so they don't modify fixtures

This commit is contained in:
Daniel Mach 2024-06-25 08:28:33 +02:00
parent e9b57c82d1
commit b8e187cc70
5 changed files with 47 additions and 16 deletions

View File

@ -17,6 +17,7 @@ concurrency:
jobs: jobs:
rpmbuild: rpmbuild:
name: 'rpmbuild test' name: 'rpmbuild test'
needs: unit-ro
runs-on: 'ubuntu-latest' runs-on: 'ubuntu-latest'
strategy: strategy:
fail-fast: false fail-fast: false

View File

@ -14,8 +14,34 @@ concurrency:
cancel-in-progress: true cancel-in-progress: true
jobs: jobs:
unit-ro:
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: unit:
name: "unit" name: "unit"
needs: unit-ro
runs-on: 'ubuntu-latest' runs-on: 'ubuntu-latest'
strategy: strategy:
fail-fast: false fail-fast: false

View File

@ -16,15 +16,10 @@ def suite():
class TestInitPackage(OscTestCase): class TestInitPackage(OscTestCase):
def _get_fixtures_dir(self): 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 return FIXTURES_DIR
def tearDown(self): def setUp(self):
if os.path.exists(os.path.join(FIXTURES_DIR, 'osctest')): super().setUp(copytree=False)
os.rmdir(os.path.join(FIXTURES_DIR, 'osctest'))
super().tearDown()
def test_simple(self): def test_simple(self):
"""initialize a package dir""" """initialize a package dir"""

View File

@ -17,15 +17,10 @@ def suite():
class TestInitProject(OscTestCase): class TestInitProject(OscTestCase):
def _get_fixtures_dir(self): 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 return FIXTURES_DIR
def tearDown(self): def setUp(self):
if os.path.exists(os.path.join(FIXTURES_DIR, 'osctest')): super().setUp(copytree=False)
os.rmdir(os.path.join(FIXTURES_DIR, 'osctest'))
super().tearDown()
def test_simple(self): def test_simple(self):
"""initialize a project dir""" """initialize a project dir"""

View File

@ -1,6 +1,8 @@
import os import os
import re import re
import shutil
import sys import sys
import tempfile
import unittest import unittest
import osc.commandline import osc.commandline
@ -50,6 +52,18 @@ def suite():
class TestProjectDiff(OscTestCase): class TestProjectDiff(OscTestCase):
diff_hdr = 'Index: %s\n===================================================================' 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): def _get_fixtures_dir(self):
return FIXTURES_DIR return FIXTURES_DIR
@ -85,10 +99,10 @@ identical: only-in-new
os.chdir('/tmp') os.chdir('/tmp')
self.assertRaises(osc.oscerr.WrongArgs, runner) 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.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() out = self._run_prdiff()
self.assertEqualMultiline(out, exp) self.assertEqualMultiline(out, exp)