From 81b983fdf6b43aa8259b2ce3f6ccde79c5c55617 Mon Sep 17 00:00:00 2001 From: James Adams Date: Mon, 15 Jul 2024 13:51:16 +0100 Subject: [PATCH 1/7] Add extension to mrepo script to allow tests to import it --- Makefile | 2 +- mrepo => mrepo.py | 0 setup.py | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename mrepo => mrepo.py (100%) diff --git a/Makefile b/Makefile index f2964a3..710621b 100644 --- a/Makefile +++ b/Makefile @@ -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/ diff --git a/mrepo b/mrepo.py similarity index 100% rename from mrepo rename to mrepo.py diff --git a/setup.py b/setup.py index a7eac82..4bb03c9 100755 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ author = 'Dag Wieers', author_email ='dag@wieers.com', 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']), From a68d694cfca94b2f711e9ea77c007681a952fe5b Mon Sep 17 00:00:00 2001 From: James Adams Date: Mon, 15 Jul 2024 13:52:13 +0100 Subject: [PATCH 2/7] Move tests to top-level and rename They can't be called unittest otherwise they try to import themselves. --- tests/unittest.py => runtests.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/unittest.py => runtests.py (100%) mode change 100644 => 100755 diff --git a/tests/unittest.py b/runtests.py old mode 100644 new mode 100755 similarity index 100% rename from tests/unittest.py rename to runtests.py From 0340e359ac7f3b8382c84c9295e959ec1d99b707 Mon Sep 17 00:00:00 2001 From: James Adams Date: Mon, 15 Jul 2024 13:55:06 +0100 Subject: [PATCH 3/7] Remove trailing whitespace --- runtests.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/runtests.py b/runtests.py index 33e42c4..f0cd9fb 100755 --- a/runtests.py +++ b/runtests.py @@ -112,15 +112,15 @@ def setUp(self): os.mkdir(tmpdir) # 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 @@ -135,7 +135,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')) @@ -156,7 +156,7 @@ class TestConfig: ] self.links.sort() - + def tearDown(self): isdir = os.path.isdir walk = os.path.walk @@ -273,7 +273,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 From 7cd1d4dc2f865b0265def33c245ad9b011df94d1 Mon Sep 17 00:00:00 2001 From: James Adams Date: Mon, 15 Jul 2024 13:53:41 +0100 Subject: [PATCH 4/7] Remove mySet tests mySet was a workaround for ancient Python versions and was removed in 36957bc7c97fad83a227f2f5e43ebb67f370cea5 --- runtests.py | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/runtests.py b/runtests.py index f0cd9fb..69b18c0 100755 --- a/runtests.py +++ b/runtests.py @@ -10,45 +10,6 @@ import unittest import mrepo -from mrepo import mySet - -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]) class TestSync(unittest.TestCase): From e13b4e2623502b38fc88c51b8687dc521d871e27 Mon Sep 17 00:00:00 2001 From: James Adams Date: Mon, 15 Jul 2024 14:19:59 +0100 Subject: [PATCH 5/7] Always sort output of readlinks Almost every call sorts the output to match links due to ordering instability, this fixes the one racy test. --- runtests.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/runtests.py b/runtests.py index 69b18c0..0d26a29 100755 --- a/runtests.py +++ b/runtests.py @@ -146,7 +146,9 @@ 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: @@ -207,7 +209,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): @@ -224,7 +225,6 @@ def test_linksync_additional(self): self.dist.linksync(repo) actual = self.readlinks(repo.wwwdir) - actual.sort() target = self.links self.assertEqual(actual, target) @@ -247,7 +247,6 @@ def test_linksync_targetchange(self): self.dist.linksync(repo) actual = self.readlinks(repo.wwwdir) - actual.sort() target = self.links self.assertEqual(actual, target) From 884a107b41710544a8894d46e3ebfa2a02b61570 Mon Sep 17 00:00:00 2001 From: James Adams Date: Mon, 15 Jul 2024 14:25:31 +0100 Subject: [PATCH 6/7] Use standard modules to create and remove temporary directory --- runtests.py | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/runtests.py b/runtests.py index 0d26a29..bfbcbd3 100755 --- a/runtests.py +++ b/runtests.py @@ -4,11 +4,10 @@ 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 +from shutil import rmtree +from tempfile import mkdtemp + import mrepo @@ -64,13 +63,12 @@ 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! @@ -117,30 +115,14 @@ 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""" From efcab0365b29941a69f7b1825aa23fd0a2ae28c3 Mon Sep 17 00:00:00 2001 From: James Adams Date: Mon, 15 Jul 2024 14:37:12 +0100 Subject: [PATCH 7/7] Add GitHub Action to run the Unit Tests --- .github/workflows/unittest.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/unittest.yml diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml new file mode 100644 index 0000000..a903740 --- /dev/null +++ b/.github/workflows/unittest.yml @@ -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