1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-09-05 20:58:42 +02:00

rework testsuite, and add a testcase for successful merging

This commit is contained in:
Dr. Peter Poeml
2007-01-23 06:52:08 +00:00
parent e6a65dab44
commit 3e1d1a1e78

151
tests.py
View File

@@ -1,28 +1,58 @@
#!/usr/bin/python
import os, sys, time
import os
import sys
import time
import re
import unittest
import shutil
from textwrap import dedent
from osc import commandline
chdir = os.chdir
mkdir = os.mkdir
# here, all tests will happen...
BASEDIR = os.path.join(os.getcwd(), 't')
PRJ = 'home:poeml'
PAC = 'test'
testpacdir = os.path.join(PRJ, PAC)
testdir = 't'
TESTPACDIR = os.path.join(PRJ, PAC)
def remove_revid(s):
return re.sub('revision \d*', 'revision XX', s)
def checkout_and_clean(self):
"""check out the package and delete all files
leave behind the empty package dir"""
runosc('co %s %s' % (PRJ, PAC))
chdir(TESTPACDIR)
files, err = runosc('ls %s %s' %(PRJ, PAC))
files = files.strip().split('\n')
if files != ['']:
for file in files:
runosc('rm %s' % file)
runosc('ci')
class TestOsc(unittest.TestCase):
def setUp(self):
os.chdir(oldpwd)
self.wd = testdir
shutil.rmtree(self.wd, ignore_errors=True)
os.mkdir(self.wd)
pass
if not os.path.isabs(BASEDIR):
sys.exit('BASEDIR must be absolute')
shutil.rmtree(BASEDIR, ignore_errors=True)
mkdir(BASEDIR)
chdir(BASEDIR)
#####################################################################
#####################################################################
def testUsermeta(self):
expect = """<person>
@@ -61,7 +91,7 @@ class TestOsc(unittest.TestCase):
self.assertEqual(self.out, expect)
#####################################################################
#####################################################################
def testLs(self):
self.out, self.err = runosc('ls')
@@ -81,7 +111,7 @@ class TestOsc(unittest.TestCase):
self.assertEqual(self.err, '')
self.assert_('favicon.ico' in self.out)
#####################################################################
#####################################################################
def testMetaPrj(self):
self.out, self.err = runosc('meta Apache')
@@ -95,7 +125,7 @@ class TestOsc(unittest.TestCase):
self.assert_('<package name="apache2" project="Apache">' in self.out)
#####################################################################
#####################################################################
def testPlatforms(self):
self.out, self.err = runosc('platforms')
@@ -110,10 +140,78 @@ class TestOsc(unittest.TestCase):
self.assert_('openSUSE_Factory' in self.out)
#####################################################################
#####################################################################
def testMerge(self):
wc1 = os.path.join(BASEDIR, TESTPACDIR)
wc2 = os.path.join(BASEDIR, 'otherwc')
checkout_and_clean(self)
# from wc1, create and check in a file
open('foo', 'w').write(dedent("""\
ein
blaues
Haus
"""))
runosc('add foo')
runosc('ci')
# create second working copy, and do a local modification
mkdir(wc2)
chdir(wc2)
runosc('init %s %s' % (PRJ, PAC))
runosc('up')
open('foo', 'w').write(dedent("""\
kein
blaues
Haus
"""))
self.out, self.err = runosc('st')
self.assertEqual(self.err, '')
self.assertEqual(self.out, 'M foo\n')
# from wc1, commit a change
chdir(wc1)
open('foo', 'a').write("""geht aus""")
runosc('ci')
# in wc2, update, and the change should be merged in
chdir(wc2)
self.out, self.err = runosc('up')
self.assertEqual(self.err, '')
self.assertEqual(remove_revid(self.out), 'G foo\nAt revision XX.\n')
self.out, self.err = runosc('st')
self.assertEqual(self.err, '')
self.assertEqual(self.out, 'M foo\n')
# successful merge is one thing, but checking the local modification
# makes sure that the store copy has been updated to the upstream revision
self.out, self.err = runosc('diff')
self.assertEqual(self.err, '')
expected = dedent("""\
Index: foo
===================================================================
--- foo (revision XX)
+++ foo (working copy)
@@ -1,4 +1,4 @@
-ein
+kein
blaues
Haus
geht aus
""")
self.assertEqual(remove_revid(self.out), expected)
#####################################################################
def testCoPrj(self):
os.chdir(self.wd)
self.out, self.err = runosc('co %s' % PRJ)
self.assertEqual(self.err, '')
self.assert_('A %s/%s' %(PRJ, PAC) in self.out)
@@ -121,25 +219,12 @@ class TestOsc(unittest.TestCase):
def testCoPac(self):
# check out package dir
os.chdir(self.wd)
self.out, self.err = runosc('co %s %s' % (PRJ, PAC))
self.assertEqual(self.err, '')
self.assert_('A %s/%s' %(PRJ, PAC) in self.out)
# work in the package dir
os.chdir(testpacdir)
# delete all existing files
self.upstream_files, err = runosc('ls %s %s' %(PRJ, PAC))
self.upstream_files = self.upstream_files.strip().split('\n')
if self.upstream_files != ['']:
for file in self.upstream_files:
self.out, self.err = runosc('rm %s' % file)
self.assertEqual(self.err, '')
self.assert_('D %s' % file in self.out)
self.out, self.err = runosc('ci')
def testCoPacAndDoStuff(self):
checkout_and_clean(self)
# check in a file
# give an error if it doesn't exist
@@ -237,8 +322,10 @@ Transmitting file data .
def runosc(argstring):
time.sleep(1) # don't stress the server
return runcmd(os.path.join(oldpwd, 'osc-wrapper.py'), argstring)
#time.sleep(1) # don't stress the server
# we test the osc in this directory, not a system one
return runcmd(os.path.join(startdir, 'osc-wrapper.py'), argstring)
def runcmd(cmd, argstring):
@@ -253,6 +340,6 @@ def touch(filename):
if __name__ == '__main__':
#unittest.main()
oldpwd = os.getcwd()
startdir = os.getcwd()
suite = unittest.makeSuite(TestOsc)
unittest.TextTestRunner(verbosity=2).run(suite)