Skip to content

Commit

Permalink
Fix tests so they don't modify fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
dmach committed Jun 25, 2024
1 parent e9b57c8 commit b8e187c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ concurrency:
jobs:
rpmbuild:
name: 'rpmbuild test'
needs: unit-ro
runs-on: 'ubuntu-latest'
strategy:
fail-fast: false
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,34 @@ concurrency:
cancel-in-progress: true

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:
name: "unit"
needs: unit-ro
runs-on: 'ubuntu-latest'
strategy:
fail-fast: false
Expand Down
9 changes: 2 additions & 7 deletions tests/test_init_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
9 changes: 2 additions & 7 deletions tests/test_init_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
18 changes: 16 additions & 2 deletions tests/test_prdiff.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import re
import shutil
import sys
import tempfile
import unittest

import osc.commandline
Expand Down Expand Up @@ -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:

Check notice

Code scanning / CodeQL

Empty except Note test

'except' clause does nothing but pass and there is no explanatory comment.

Check notice

Code scanning / CodeQL

Except block handles 'BaseException' Note test

Except block directly handles BaseException.
pass
super().tearDown()

def _get_fixtures_dir(self):
return FIXTURES_DIR

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit b8e187c

Please sign in to comment.