1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-26 09:56:13 +01:00
github.com_openSUSE_osc/tests/test_addfiles.py

91 lines
3.1 KiB
Python
Raw Normal View History

import os
import sys
2022-09-09 11:46:28 +02:00
import unittest
import osc.core
import osc.oscerr
2022-02-17 13:28:47 +01:00
from .common import OscTestCase
2022-02-17 13:28:47 +01:00
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'addfile_fixtures')
2022-09-12 13:43:10 +02:00
def suite():
return unittest.defaultTestLoader.loadTestsFromTestCase(TestAddFiles)
2022-09-12 13:43:10 +02:00
class TestAddFiles(OscTestCase):
def _get_fixtures_dir(self):
return FIXTURES_DIR
def testSimpleAdd(self):
"""add one file ('toadd1') to the wc"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
p.addfile('toadd1')
exp = 'A toadd1\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd1')))
self._check_status(p, 'toadd1', 'A')
self._check_addlist('toadd1\n')
def testSimpleMultipleAdd(self):
"""add multiple files ('toadd1', 'toadd2') to the wc"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
p.addfile('toadd1')
p.addfile('toadd2')
exp = 'A toadd1\nA toadd2\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd1')))
self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd2')))
self._check_status(p, 'toadd1', 'A')
self._check_status(p, 'toadd2', 'A')
self._check_addlist('toadd1\ntoadd2\n')
def testAddVersionedFile(self):
"""add a versioned file"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
self.assertRaises(osc.oscerr.PackageFileConflict, p.addfile, 'merge')
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
self._check_status(p, 'merge', ' ')
def testAddUnversionedFileTwice(self):
"""add the same file twice"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
p.addfile('toadd1')
self.assertRaises(osc.oscerr.PackageFileConflict, p.addfile, 'toadd1')
exp = 'A toadd1\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd1')))
self._check_status(p, 'toadd1', 'A')
self._check_addlist('toadd1\n')
def testReplace(self):
"""replace a deleted file ('foo')"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
2022-08-24 08:43:09 +02:00
with open('foo', 'w') as f:
f.write('replaced file\n')
p.addfile('foo')
exp = 'A foo\n'
self.assertEqual(sys.stdout.getvalue(), exp)
2022-08-24 08:43:09 +02:00
self.assertFileContentNotEqual(os.path.join('.osc', 'foo'), 'replaced file\n')
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
self._check_status(p, 'foo', 'R')
self._check_addlist('foo\n')
def testAddNonExistentFile(self):
"""add a non existent file"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
self.assertRaises(osc.oscerr.OscIOError, p.addfile, 'doesnotexist')
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
2022-09-12 13:43:10 +02:00
if __name__ == '__main__':
unittest.main()