Skip to content

Commit

Permalink
Merge pull request #11 from stfc/unittests
Browse files Browse the repository at this point in the history
Resurrect Unittests
  • Loading branch information
Oli-Rest authored Jul 15, 2024
2 parents 8752fa7 + efcab03 commit 96a2a21
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 79 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Unit Tests

on: [push]

jobs:
build:
runs-on: ubuntu-20.04
container:
image: python:2.7.18-buster
steps:
- uses: actions/checkout@v4
- name: Run Unit Tests
run: python runtests.py
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ all:
@echo "There is nothing to be build. Try install !"

install:
install -Dp -m0755 mrepo $(DESTDIR)$(bindir)/mrepo
install -Dp -m0755 mrepo.py $(DESTDIR)$(bindir)/mrepo
[ ! -f $(DESTDIR)$(sysconfdir)/mrepo.conf ] && install -D -m0600 config/mrepo.conf $(DESTDIR)$(sysconfdir)/mrepo.conf || :
install -d -m0755 $(DESTDIR)$(sysconfdir)/mrepo.conf.d/

Expand Down
File renamed without changes.
96 changes: 19 additions & 77 deletions tests/unittest.py → runtests.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,11 @@
import sys

import os.path
testdir = os.path.abspath(os.path.dirname(__file__))
parentdir = os.path.dirname(testdir)
sys.path.insert(1, parentdir)

import unittest
import mrepo
from mrepo import mySet
from shutil import rmtree
from tempfile import mkdtemp

class TestmySet(unittest.TestCase):

def setUp(self):
self.s = mySet([1, 2, 3, 4])

def test_initempty(self):
s = mySet()
self.assert_(isinstance(s, mrepo.mySet))

def test_init(self):
s = mySet([ 1, 2, 3, 4 ])
self.assert_(isinstance(s, mrepo.mySet))
self.assert_(repr(s) == 'mySet([1, 2, 3, 4])')

def test_add(self):
s = self.s
self.assert_(9 not in s)
s.add(9)
self.assert_(9 in s)

def test_eq(self):
s1 = mySet([1, 2, 3])
s2 = mySet([1, 2, 3])
self.assertEqual(s1, s2)

def test_difference(self):
s1 = mySet([ 1, 2, 3, 4 ])
s2 = mySet([ 1, 3 ])
s = s1.difference(s2)
self.assertEqual(s, mySet([2, 4]))

def test_iter(self):
s = mySet([1, 2, 3])
l = []
for i in s:
l.append(i)
self.assertEqual(l, [1, 2, 3])
import mrepo


class TestSync(unittest.TestCase):
Expand Down Expand Up @@ -103,24 +63,23 @@ def test_synciter2(self):
self.assertEqual(keyequal, [((2, 'l2'), (2, 'r2')),
((5, 'l5'), (5, 'r5'))])


class Testlinksync(unittest.TestCase):
def setUp(self):
mkdir = os.mkdir
pj= os.path.join
self.tmpdir = tmpdir = pj(testdir, 'tmp')
pj = os.path.join

os.mkdir(tmpdir)
self.tmpdir = tmpdir = mkdtemp(prefix='mrepo_tests_')

# global "op" is needed by mrepo.Config, horrible for testing!

class TestConfig:
pass

self.cf = cf = TestConfig()

cf.srcdir = pj(tmpdir, 'src')
cf.wwwdir = pj(tmpdir, 'dst')

self.dist = mrepo.Dist('testdist', 'i386', cf)
self.repo = repo = mrepo.Repo('testrepo', '', self.dist, cf)
srcdir = repo.srcdir
Expand All @@ -135,7 +94,7 @@ class TestConfig:
for f in xrange(4):
__touch(pj(srcdir, str(f) + '.rpm'))
__touch(pj(srcdir, 'dontsync.txt'))

os.mkdir(pj(srcdir, 'a'))
__touch(pj(srcdir, 'a', '2.rpm'))
__touch(pj(srcdir, 'a', 'a.rpm'))
Expand All @@ -156,36 +115,22 @@ class TestConfig:
]
self.links.sort()


def tearDown(self):
isdir = os.path.isdir
walk = os.path.walk
pathjoin= os.path.join
tmpdir = self.tmpdir

# for safety-reasons:
if tmpdir.count('/') < 3:
raise "Will not remove tmpdir %s" % ( tmpdir, )

def rmfile(arg, path, files):
for file in files:
# print "%s" % ( file, )
f = pathjoin(path, file)
if isdir(f):
walk(f, rmfile, None)
#print "rmdir %s" % ( f, )
os.rmdir(f)
else:
#print "unlink %s" % ( f, )
os.unlink(f)

os.path.walk(tmpdir, rmfile, None)
os.rmdir(tmpdir)
if tmpdir.count('/') < 2:
raise Exception("Will not remove tmpdir %s" % ( tmpdir, ))

rmtree(tmpdir)

def readlinks(self, dir):
"""return a list of (linkname, linktarget) tuples for all files in a directory"""
pj = os.path.join
readlink = os.readlink
return [ (l, readlink(pj(dir, l))) for l in os.listdir(dir) ]
result = [ (l, readlink(pj(dir, l))) for l in os.listdir(dir) ]
result.sort()
return result

def genlinks(self, links, dir=''):
if not dir:
Expand Down Expand Up @@ -246,7 +191,6 @@ def test_linksync_missing(self):

actual = self.readlinks(repo.wwwdir)
target = self.links
actual.sort()
self.assertEqual(actual, target)

def test_linksync_additional(self):
Expand All @@ -263,7 +207,6 @@ def test_linksync_additional(self):
self.dist.linksync(repo)

actual = self.readlinks(repo.wwwdir)
actual.sort()
target = self.links
self.assertEqual(actual, target)

Expand All @@ -273,7 +216,7 @@ def test_linksync_targetchange(self):

pj = os.path.join
# add some links

# basename != target basename
links[1] = (links[1][0], pj(self.linkbase, 'illegal.rpm'))
# different dir
Expand All @@ -286,7 +229,6 @@ def test_linksync_targetchange(self):
self.dist.linksync(repo)

actual = self.readlinks(repo.wwwdir)
actual.sort()
target = self.links
self.assertEqual(actual, target)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
author = 'Dag Wieers',
author_email ='[email protected]',
url = "http://dag.wieers.com/home-made/mrepo/",
scripts=['mrepo', 'gensystemid'],
scripts=['mrepo.py', 'gensystemid'],
data_files=[
('/etc', ['config/mrepo.conf']),
('/etc/init.d', ['config/mrepo']),
Expand Down

0 comments on commit 96a2a21

Please sign in to comment.