mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-26 09:56:13 +01:00
- added testcases for "def revert"
This commit is contained in:
parent
80bf280d8b
commit
9c0076d726
@ -1781,6 +1781,8 @@ rev: %s
|
|||||||
def revert(self, filename):
|
def revert(self, filename):
|
||||||
if not filename in self.filenamelist and not filename in self.to_be_added:
|
if not filename in self.filenamelist and not filename in self.to_be_added:
|
||||||
raise IOError('file \'%s\' is not under version control' % filename)
|
raise IOError('file \'%s\' is not under version control' % filename)
|
||||||
|
elif filename in self.skipped:
|
||||||
|
raise IOError('file \'%s\' is marked as skipped and cannot be reverted')
|
||||||
if filename in self.filenamelist and not os.path.exists(os.path.join(self.storedir, filename)):
|
if filename in self.filenamelist and not os.path.exists(os.path.join(self.storedir, filename)):
|
||||||
raise oscerr.PackageInternalError('file \'%s\' is listed in filenamelist but no storefile exists' % filename)
|
raise oscerr.PackageInternalError('file \'%s\' is listed in filenamelist but no storefile exists' % filename)
|
||||||
state = self.status(filename)
|
state = self.status(filename)
|
||||||
|
104
tests/revertfile_fixtures/oscrc
Normal file
104
tests/revertfile_fixtures/oscrc
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
[general]
|
||||||
|
# URL to access API server, e.g. https://api.opensuse.org
|
||||||
|
# you also need a section [https://api.opensuse.org] with the credentials
|
||||||
|
apiurl = http://localhost
|
||||||
|
# Downloaded packages are cached here. Must be writable by you.
|
||||||
|
#packagecachedir = /var/tmp/osbuild-packagecache
|
||||||
|
# Wrapper to call build as root (sudo, su -, ...)
|
||||||
|
#su-wrapper = su -c
|
||||||
|
# rootdir to setup the chroot environment
|
||||||
|
# can contain %(repo)s, %(arch)s, %(project)s and %(package)s for replacement, e.g.
|
||||||
|
# /srv/oscbuild/%(repo)s-%(arch)s or
|
||||||
|
# /srv/oscbuild/%(repo)s-%(arch)s-%(project)s-%(package)s
|
||||||
|
#build-root = /var/tmp/build-root
|
||||||
|
# compile with N jobs (default: "getconf _NPROCESSORS_ONLN")
|
||||||
|
#build-jobs = N
|
||||||
|
# build-type to use - values can be (depending on the capabilities of the 'build' script)
|
||||||
|
# empty - chroot build
|
||||||
|
# kvm - kvm VM build (needs build-device, build-swap, build-memory)
|
||||||
|
# xen - xen VM build (needs build-device, build-swap, build-memory)
|
||||||
|
# experimental:
|
||||||
|
# qemu - qemu VM build
|
||||||
|
# lxc - lxc build
|
||||||
|
#build-type =
|
||||||
|
# build-device is the disk-image file to use as root for VM builds
|
||||||
|
# e.g. /var/tmp/FILE.root
|
||||||
|
#build-device = /var/tmp/FILE.root
|
||||||
|
# build-swap is the disk-image to use as swap for VM builds
|
||||||
|
# e.g. /var/tmp/FILE.swap
|
||||||
|
#build-swap = /var/tmp/FILE.swap
|
||||||
|
# build-memory is the amount of memory used in the VM
|
||||||
|
# value in MB - e.g. 512
|
||||||
|
#build-memory = 512
|
||||||
|
# build-vmdisk-rootsize is the size of the disk-image used as root in a VM build
|
||||||
|
# values in MB - e.g. 4096
|
||||||
|
#build-vmdisk-rootsize = 4096
|
||||||
|
# build-vmdisk-swapsize is the size of the disk-image used as swap in a VM build
|
||||||
|
# values in MB - e.g. 1024
|
||||||
|
#build-vmdisk-swapsize = 1024
|
||||||
|
# Numeric uid:gid to assign to the "abuild" user in the build-root
|
||||||
|
# or "caller" to use the current users uid:gid
|
||||||
|
# This is convenient when sharing the buildroot with ordinary userids
|
||||||
|
# on the host.
|
||||||
|
# This should not be 0
|
||||||
|
# build-uid =
|
||||||
|
# extra packages to install when building packages locally (osc build)
|
||||||
|
# this corresponds to osc build's -x option and can be overridden with that
|
||||||
|
# -x '' can also be given on the command line to override this setting, or
|
||||||
|
# you can have an empty setting here.
|
||||||
|
#extra-pkgs = vim gdb strace
|
||||||
|
# build platform is used if the platform argument is omitted to osc build
|
||||||
|
#build_repository = openSUSE_Factory
|
||||||
|
# default project for getpac or bco
|
||||||
|
#getpac_default_project = openSUSE:Factory
|
||||||
|
# alternate filesystem layout: have multiple subdirs, where colons were.
|
||||||
|
#checkout_no_colon = 0
|
||||||
|
# local files to ignore with status, addremove, ....
|
||||||
|
#exclude_glob = .osc CVS .svn .* _linkerror *~ #*# *.orig *.bak *.changes.*
|
||||||
|
# keep passwords in plaintext. If you see this comment, your osc
|
||||||
|
# already uses the encrypted password, and only keeps them in plain text
|
||||||
|
# for backwards compatibility. Default will change to 0 in future releases.
|
||||||
|
# You can remove the plaintext password without harm, if you do not need
|
||||||
|
# backwards compatibility.
|
||||||
|
#plaintext_passwd = 1
|
||||||
|
# limit the age of requests shown with 'osc req list'.
|
||||||
|
# this is a default only, can be overridden by 'osc req list -D NNN'
|
||||||
|
# Use 0 for unlimted.
|
||||||
|
#request_list_days = 0
|
||||||
|
# show info useful for debugging
|
||||||
|
#debug = 1
|
||||||
|
# show HTTP traffic useful for debugging
|
||||||
|
#http_debug = 1
|
||||||
|
# Skip signature verification of packages used for build.
|
||||||
|
#no_verify = 1
|
||||||
|
# jump into the debugger in case of errors
|
||||||
|
#post_mortem = 1
|
||||||
|
# print call traces in case of errors
|
||||||
|
#traceback = 1
|
||||||
|
# use KDE/Gnome/MacOS/Windows keyring for credentials if available
|
||||||
|
#use_keyring = 1
|
||||||
|
# check for unversioned/removed files before commit
|
||||||
|
#check_filelist = 1
|
||||||
|
# check for pending requests after executing an action (e.g. checkout, update, commit)
|
||||||
|
#check_for_request_on_action = 0
|
||||||
|
# what to do with the source package if the submitrequest has been accepted. If
|
||||||
|
# nothing is specified the API default is used
|
||||||
|
#submitrequest_on_accept_action = cleanup|update|noupdate
|
||||||
|
#review requests interactively (default: off)
|
||||||
|
#request_show_review = 1
|
||||||
|
# Directory with executables to validate sources, esp before committing
|
||||||
|
#source_validator_directory = /usr/lib/osc/source_validators
|
||||||
|
|
||||||
|
[http://localhost]
|
||||||
|
user = Admin
|
||||||
|
pass = opensuse
|
||||||
|
passx = QlpoOTFBWSZTWeTSblkAAAGBgAIBygAgADDACGNEHxaYXckU4UJDk0m5ZA==
|
||||||
|
# set aliases for this apiurl
|
||||||
|
# aliases = foo, bar
|
||||||
|
# email used in .changes, unless the one from osc meta prj <user> will be used
|
||||||
|
# email =
|
||||||
|
# additional headers to pass to a request, e.g. for special authentication
|
||||||
|
#http_headers = Host: foofoobar,
|
||||||
|
# User: mumblegack
|
||||||
|
# Force using of keyring for this API
|
||||||
|
#keyring = 1
|
1
tests/revertfile_fixtures/osctest/.osc/_apiurl
Normal file
1
tests/revertfile_fixtures/osctest/.osc/_apiurl
Normal file
@ -0,0 +1 @@
|
|||||||
|
http://localhost
|
1
tests/revertfile_fixtures/osctest/.osc/_packages
Normal file
1
tests/revertfile_fixtures/osctest/.osc/_packages
Normal file
@ -0,0 +1 @@
|
|||||||
|
<project name="osctest" />
|
1
tests/revertfile_fixtures/osctest/.osc/_project
Normal file
1
tests/revertfile_fixtures/osctest/.osc/_project
Normal file
@ -0,0 +1 @@
|
|||||||
|
osctest
|
1
tests/revertfile_fixtures/osctest/simple/.osc/_apiurl
Normal file
1
tests/revertfile_fixtures/osctest/simple/.osc/_apiurl
Normal file
@ -0,0 +1 @@
|
|||||||
|
http://localhost
|
9
tests/revertfile_fixtures/osctest/simple/.osc/_files
Normal file
9
tests/revertfile_fixtures/osctest/simple/.osc/_files
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<directory name="conflict" rev="2" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="2">
|
||||||
|
<entry md5="0d62ceea6020d75154078a20d8c9f9ba" mtime="1282047302" name="foo" size="23" />
|
||||||
|
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282047303" name="merge" size="48" />
|
||||||
|
<entry md5="7efa70f68983fad1cf487f69dedf93e9" mtime="1282047303" name="nochange" size="25" />
|
||||||
|
<entry md5="eb9c2bf0eb63f3a7bc0ea37ef18aeba5" mtime="1282730880" name="somefile" size="13" />
|
||||||
|
<entry md5="81be947db54c2e225dc8eacce64d8a4a" mtime="1282731457" name="replaced" size="17" />
|
||||||
|
<entry md5="676513fde5797c3785164942c97dfec1" mtime="1282731738" name="missing" size="8" />
|
||||||
|
<entry md5="ffffffffffffffffffffffffffffffff" mtime="1111111111" name="skipped" size="12" skipped="true" />
|
||||||
|
</directory>
|
@ -0,0 +1 @@
|
|||||||
|
foo
|
@ -0,0 +1 @@
|
|||||||
|
1.0
|
1
tests/revertfile_fixtures/osctest/simple/.osc/_package
Normal file
1
tests/revertfile_fixtures/osctest/simple/.osc/_package
Normal file
@ -0,0 +1 @@
|
|||||||
|
simple
|
1
tests/revertfile_fixtures/osctest/simple/.osc/_project
Normal file
1
tests/revertfile_fixtures/osctest/simple/.osc/_project
Normal file
@ -0,0 +1 @@
|
|||||||
|
osctest
|
@ -0,0 +1,2 @@
|
|||||||
|
toadd1
|
||||||
|
replaced
|
@ -0,0 +1,2 @@
|
|||||||
|
somefile
|
||||||
|
modified
|
1
tests/revertfile_fixtures/osctest/simple/.osc/foo
Normal file
1
tests/revertfile_fixtures/osctest/simple/.osc/foo
Normal file
@ -0,0 +1 @@
|
|||||||
|
This is a simple test.
|
4
tests/revertfile_fixtures/osctest/simple/.osc/merge
Normal file
4
tests/revertfile_fixtures/osctest/simple/.osc/merge
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Is it
|
||||||
|
possible to
|
||||||
|
merge this file?
|
||||||
|
I hope so...
|
1
tests/revertfile_fixtures/osctest/simple/.osc/missing
Normal file
1
tests/revertfile_fixtures/osctest/simple/.osc/missing
Normal file
@ -0,0 +1 @@
|
|||||||
|
missing
|
1
tests/revertfile_fixtures/osctest/simple/.osc/nochange
Normal file
1
tests/revertfile_fixtures/osctest/simple/.osc/nochange
Normal file
@ -0,0 +1 @@
|
|||||||
|
This file didn't change.
|
1
tests/revertfile_fixtures/osctest/simple/.osc/replaced
Normal file
1
tests/revertfile_fixtures/osctest/simple/.osc/replaced
Normal file
@ -0,0 +1 @@
|
|||||||
|
yet another file
|
1
tests/revertfile_fixtures/osctest/simple/.osc/somefile
Normal file
1
tests/revertfile_fixtures/osctest/simple/.osc/somefile
Normal file
@ -0,0 +1 @@
|
|||||||
|
some content
|
5
tests/revertfile_fixtures/osctest/simple/foo
Normal file
5
tests/revertfile_fixtures/osctest/simple/foo
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<<<<<<< foo.mine
|
||||||
|
This is no test.
|
||||||
|
=======
|
||||||
|
This is a simple test.
|
||||||
|
>>>>>>> foo.r2
|
4
tests/revertfile_fixtures/osctest/simple/merge
Normal file
4
tests/revertfile_fixtures/osctest/simple/merge
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Is it
|
||||||
|
possible to
|
||||||
|
merge this file?
|
||||||
|
I hope so...
|
2
tests/revertfile_fixtures/osctest/simple/nochange
Normal file
2
tests/revertfile_fixtures/osctest/simple/nochange
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
This file didn't change but
|
||||||
|
is modified.
|
1
tests/revertfile_fixtures/osctest/simple/replaced
Normal file
1
tests/revertfile_fixtures/osctest/simple/replaced
Normal file
@ -0,0 +1 @@
|
|||||||
|
foo replaced
|
1
tests/revertfile_fixtures/osctest/simple/toadd1
Normal file
1
tests/revertfile_fixtures/osctest/simple/toadd1
Normal file
@ -0,0 +1 @@
|
|||||||
|
toadd1
|
1
tests/revertfile_fixtures/osctest/simple/toadd2
Normal file
1
tests/revertfile_fixtures/osctest/simple/toadd2
Normal file
@ -0,0 +1 @@
|
|||||||
|
toadd2
|
@ -2,9 +2,11 @@ import unittest
|
|||||||
import test_update
|
import test_update
|
||||||
import test_addfiles
|
import test_addfiles
|
||||||
import test_deletefiles
|
import test_deletefiles
|
||||||
|
import test_revertfiles
|
||||||
|
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
suite.addTests(test_addfiles.suite())
|
suite.addTests(test_addfiles.suite())
|
||||||
suite.addTests(test_deletefiles.suite())
|
suite.addTests(test_deletefiles.suite())
|
||||||
|
suite.addTests(test_revertfiles.suite())
|
||||||
suite.addTests(test_update.suite())
|
suite.addTests(test_update.suite())
|
||||||
unittest.TextTestRunner(verbosity=1).run(suite)
|
unittest.TextTestRunner(verbosity=1).run(suite)
|
||||||
|
90
tests/test_revertfiles.py
Normal file
90
tests/test_revertfiles.py
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
import osc.core
|
||||||
|
import osc.oscerr
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from common import GET, OscTestCase
|
||||||
|
|
||||||
|
FIXTURES_DIR = os.path.join(os.getcwd(), 'revertfile_fixtures')
|
||||||
|
|
||||||
|
def suite():
|
||||||
|
import unittest
|
||||||
|
return unittest.makeSuite(TestRevertFiles)
|
||||||
|
|
||||||
|
class TestRevertFiles(OscTestCase):
|
||||||
|
def _get_fixtures_dir(self):
|
||||||
|
return FIXTURES_DIR
|
||||||
|
|
||||||
|
def testRevertUnchanged(self):
|
||||||
|
"""revert an unchanged file (state == ' ')"""
|
||||||
|
self._change_to_pkg('simple')
|
||||||
|
p = osc.core.Package('.')
|
||||||
|
self.assertRaises(IOError, p.revert, 'toadd2')
|
||||||
|
self._check_status(p, 'toadd2', '?')
|
||||||
|
|
||||||
|
def testRevertModified(self):
|
||||||
|
"""revert a modified file"""
|
||||||
|
self._change_to_pkg('simple')
|
||||||
|
p = osc.core.Package('.')
|
||||||
|
p.revert('nochange')
|
||||||
|
self.__check_file('nochange')
|
||||||
|
self._check_status(p, 'nochange', ' ')
|
||||||
|
|
||||||
|
def testRevertAdded(self):
|
||||||
|
"""revert an added file"""
|
||||||
|
self._change_to_pkg('simple')
|
||||||
|
p = osc.core.Package('.')
|
||||||
|
p.revert('toadd1')
|
||||||
|
self.assertTrue(os.path.exists('toadd1'))
|
||||||
|
self._check_addlist('replaced\n')
|
||||||
|
self._check_status(p, 'toadd1', '?')
|
||||||
|
|
||||||
|
def testRevertDeleted(self):
|
||||||
|
"""revert a deleted file"""
|
||||||
|
self._change_to_pkg('simple')
|
||||||
|
p = osc.core.Package('.')
|
||||||
|
p.revert('somefile')
|
||||||
|
self.__check_file('somefile')
|
||||||
|
self._check_deletelist('modified\n')
|
||||||
|
self._check_status(p, 'somefile', ' ')
|
||||||
|
|
||||||
|
def testRevertMissing(self):
|
||||||
|
"""revert a missing (state == '!') file"""
|
||||||
|
self._change_to_pkg('simple')
|
||||||
|
p = osc.core.Package('.')
|
||||||
|
p.revert('missing')
|
||||||
|
self.__check_file('missing')
|
||||||
|
self._check_status(p, 'missing', ' ')
|
||||||
|
|
||||||
|
def testRevertReplaced(self):
|
||||||
|
"""revert a replaced (state == 'R') file"""
|
||||||
|
self._change_to_pkg('simple')
|
||||||
|
p = osc.core.Package('.')
|
||||||
|
p.revert('replaced')
|
||||||
|
self.__check_file('replaced')
|
||||||
|
self._check_addlist('toadd1\n')
|
||||||
|
self._check_status(p, 'replaced', ' ')
|
||||||
|
|
||||||
|
def testRevertConflict(self):
|
||||||
|
"""revert a file which is in the conflict state"""
|
||||||
|
self._change_to_pkg('simple')
|
||||||
|
p = osc.core.Package('.')
|
||||||
|
p.revert('foo')
|
||||||
|
self.__check_file('foo')
|
||||||
|
self.assertFalse(os.path.exists(os.path.join('.osc', '_in_conflict')))
|
||||||
|
self._check_status(p, 'foo', ' ')
|
||||||
|
|
||||||
|
def testRevertSkipped(self):
|
||||||
|
"""revert a skipped file"""
|
||||||
|
self._change_to_pkg('simple')
|
||||||
|
p = osc.core.Package('.')
|
||||||
|
self.assertRaises(IOError, p.revert, 'skipped')
|
||||||
|
|
||||||
|
def __check_file(self, fname):
|
||||||
|
storefile = os.path.join('.osc', fname)
|
||||||
|
self.assertTrue(os.path.exists(fname))
|
||||||
|
self.assertTrue(os.path.exists(storefile))
|
||||||
|
self.assertEqual(open(fname, 'r').read(), open(storefile, 'r').read())
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import unittest
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user