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

Modernize code with pyupgrade

pyupgrade --keep-percent-format --py36-plus `find -name '*.py'`
This commit is contained in:
2022-07-28 19:11:29 +02:00
parent e7af9cebb3
commit feb53212dd
38 changed files with 126 additions and 138 deletions

View File

@@ -228,7 +228,7 @@ class OscTestCase(unittest.TestCase):
def _check_list(self, fname, exp):
fname = os.path.join('.osc', fname)
self.assertTrue(os.path.exists(fname))
self.assertEqual(open(fname, 'r').read(), exp)
self.assertEqual(open(fname).read(), exp)
def _check_addlist(self, exp):
self._check_list('_to_be_added', exp)
@@ -244,9 +244,9 @@ class OscTestCase(unittest.TestCase):
def _check_digests(self, fname, *skipfiles):
fname = os.path.join(self._get_fixtures_dir(), fname)
with open(os.path.join('.osc', '_files'), 'r') as f:
with open(os.path.join('.osc', '_files')) as f:
files_act = f.read()
with open(fname, 'r') as f:
with open(fname) as f:
files_exp = f.read()
self.assertXMLEqual(files_act, files_exp)
root = ET.fromstring(files_act)

View File

@@ -11,7 +11,7 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'addfile_fixtures')
def suite():
import unittest
return unittest.makeSuite(TestAddFiles)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestAddFiles)
class TestAddFiles(OscTestCase):
def _get_fixtures_dir(self):
@@ -71,7 +71,7 @@ class TestAddFiles(OscTestCase):
exp = 'A foo\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
self.assertNotEqual(open(os.path.join('.osc', 'foo'), 'r').read(), 'replaced file\n')
self.assertNotEqual(open(os.path.join('.osc', 'foo')).read(), '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')

View File

@@ -13,7 +13,7 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'commit_fixtures')
def suite():
import unittest
return unittest.makeSuite(TestCommit)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestCommit)
rev_dummy = '<revision rev="repository">\n <srcmd5>empty</srcmd5>\n</revision>'
@@ -40,7 +40,7 @@ class TestCommit(OscTestCase):
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testSimple_cfilesremote')
self.assertTrue(os.path.exists('nochange'))
self.assertEqual(open('nochange', 'r').read(), open(os.path.join('.osc', 'nochange'), 'r').read())
self.assertEqual(open('nochange').read(), open(os.path.join('.osc', 'nochange')).read())
self._check_status(p, 'nochange', ' ')
self._check_status(p, 'foo', ' ')
self._check_status(p, 'merge', ' ')
@@ -64,7 +64,7 @@ class TestCommit(OscTestCase):
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testAddfile_cfilesremote')
self.assertTrue(os.path.exists('add'))
self.assertEqual(open('add', 'r').read(), open(os.path.join('.osc', 'add'), 'r').read())
self.assertEqual(open('add').read(), open(os.path.join('.osc', 'add')).read())
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
self._check_status(p, 'add', ' ')
self._check_status(p, 'foo', ' ')
@@ -241,7 +241,7 @@ class TestCommit(OscTestCase):
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testAddfile_cfilesremote')
self.assertTrue(os.path.exists('add'))
self.assertEqual(open('add', 'r').read(), open(os.path.join('.osc', 'add'), 'r').read())
self.assertEqual(open('add').read(), open(os.path.join('.osc', 'add')).read())
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
self._check_status(p, 'add', ' ')
self._check_status(p, 'foo', ' ')
@@ -341,7 +341,7 @@ class TestCommit(OscTestCase):
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testSimple_cfilesremote')
self.assertTrue(os.path.exists('nochange'))
self.assertEqual(open('nochange', 'r').read(), open(os.path.join('.osc', 'nochange'), 'r').read())
self.assertEqual(open('nochange').read(), open(os.path.join('.osc', 'nochange')).read())
self._check_status(p, 'nochange', ' ')
self._check_status(p, 'foo', ' ')
self._check_status(p, 'merge', ' ')

View File

@@ -10,7 +10,7 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'deletefile_fixtures')
def suite():
import unittest
return unittest.makeSuite(TestDeleteFiles)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestDeleteFiles)
class TestDeleteFiles(OscTestCase):
def _get_fixtures_dir(self):

View File

@@ -12,7 +12,7 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'difffile_fixtures')
def suite():
import unittest
return unittest.makeSuite(TestDiffFiles)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestDiffFiles)
class TestDiffFiles(OscTestCase):
diff_hdr = 'Index: %s\n==================================================================='
@@ -325,9 +325,9 @@ Binary file 'binary' has changed.
def __canonise_diff(diff):
# we cannot use re.M because python 2.6's re.sub does
# not support a flags argument
diff = [re.sub('^@@ -(\d+) ', '@@ -\\1,\\1 ', line)
diff = [re.sub(r'^@@ -(\d+) ', '@@ -\\1,\\1 ', line)
for line in diff.split('\n')]
diff = [re.sub('^(@@ -\d+,\d+) \+(\d+) ', '\\1 +\\2,\\2 ', line)
diff = [re.sub(r'^(@@ -\d+,\d+) \+(\d+) ', '\\1 +\\2,\\2 ', line)
for line in diff]
return '\n'.join(diff)

View File

@@ -4,7 +4,7 @@ from osc.util.helper import decode_it, decode_list
def suite():
return unittest.makeSuite(TestResults)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestResults)
class TestResults(unittest.TestCase):
def testDecodeList(self):

View File

@@ -10,7 +10,7 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'init_package_fixtures')
def suite():
import unittest
return unittest.makeSuite(TestInitPackage)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestInitPackage)
class TestInitPackage(OscTestCase):
def _get_fixtures_dir(self):

View File

@@ -10,7 +10,7 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'init_project_fixtures')
def suite():
import unittest
return unittest.makeSuite(TestInitProject)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestInitProject)
class TestInitProject(OscTestCase):
def _get_fixtures_dir(self):

View File

@@ -10,7 +10,7 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'project_package_status_f
def suite():
import unittest
return unittest.makeSuite(TestPackageStatus)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestPackageStatus)
class TestPackageStatus(OscTestCase):
def _get_fixtures_dir(self):

View File

@@ -43,7 +43,7 @@ def POST_RDIFF(oldprj, newprj):
def suite():
import unittest
return unittest.makeSuite(TestProjectDiff)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestProjectDiff)
class TestProjectDiff(OscTestCase):
diff_hdr = 'Index: %s\n==================================================================='

View File

@@ -10,7 +10,7 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'project_package_status_f
def suite():
import unittest
return unittest.makeSuite(TestProjectStatus)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestProjectStatus)
class TestProjectStatus(OscTestCase):
def _get_fixtures_dir(self):

View File

@@ -12,7 +12,7 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'repairwc_fixtures')
def suite():
import unittest
return unittest.makeSuite(TestRepairWC)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestRepairWC)
class TestRepairWC(OscTestCase):
def _get_fixtures_dir(self):
@@ -223,7 +223,7 @@ class TestRepairWC(OscTestCase):
prj.wc_repair('http://localhost')
self.assertTrue(os.path.exists(os.path.join(storedir, '_apiurl')))
self.assertTrue(os.path.exists(os.path.join(storedir, '_apiurl')))
self.assertEqual(open(os.path.join(storedir, '_apiurl'), 'r').read(), 'http://localhost\n')
self.assertEqual(open(os.path.join(storedir, '_apiurl')).read(), 'http://localhost\n')
if __name__ == '__main__':

View File

@@ -11,7 +11,7 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'request_fixtures')
def suite():
import unittest
return unittest.makeSuite(TestRequest)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestRequest)
class TestRequest(OscTestCase):
def _get_fixtures_dir(self):
@@ -322,7 +322,7 @@ class TestRequest(OscTestCase):
def test_read_request1(self):
"""read in a request"""
xml = open(os.path.join(self._get_fixtures_dir(), 'test_read_request1.xml'), 'r').read().strip()
xml = open(os.path.join(self._get_fixtures_dir(), 'test_read_request1.xml')).read().strip()
r = osc.core.Request()
r.read(ET.fromstring(xml))
self.assertEqual(r.reqid, '42')
@@ -353,7 +353,7 @@ class TestRequest(OscTestCase):
def test_read_request2(self):
"""read in a request (with reviews)"""
xml = open(os.path.join(self._get_fixtures_dir(), 'test_read_request2.xml'), 'r').read().strip()
xml = open(os.path.join(self._get_fixtures_dir(), 'test_read_request2.xml')).read().strip()
r = osc.core.Request()
r.read(ET.fromstring(xml))
self.assertEqual(r.reqid, '123')
@@ -427,7 +427,7 @@ class TestRequest(OscTestCase):
def test_request_list_view1(self):
"""test the list_view method"""
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view1.xml'), 'r').read().strip()
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view1.xml')).read().strip()
exp = """\
62 State:new By:Admin When:2010-12-29T14:57:25
set_bugowner: buguser foo
@@ -444,7 +444,7 @@ class TestRequest(OscTestCase):
def test_request_list_view2(self):
"""test the list_view method (with history elements and description)"""
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view2.xml'), 'r').read().strip()
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view2.xml')).read().strip()
r = osc.core.Request()
r.read(ET.fromstring(xml))
exp = """\
@@ -458,7 +458,7 @@ class TestRequest(OscTestCase):
def test_request_str1(self):
"""test the __str__ method"""
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_str1.xml'), 'r').read().strip()
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_str1.xml')).read().strip()
r = osc.core.Request()
r = osc.core.Request()
r.read(ET.fromstring(xml))
@@ -555,7 +555,7 @@ Comment: <no comment>"""
def test_get_actions(self):
"""test get_actions method"""
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view1.xml'), 'r').read().strip()
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view1.xml')).read().strip()
r = osc.core.Request()
r.read(ET.fromstring(xml))
sr_actions = r.get_actions('submit')

View File

@@ -8,7 +8,7 @@ from .common import GET, OscTestCase
def suite():
import unittest
return unittest.makeSuite(TestResults)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestResults)
class TestResults(OscTestCase):
def setUp(self):
@@ -29,7 +29,7 @@ class TestResults(OscTestCase):
return sys.stdout.getvalue()
def _get_fixture(self, filename):
return open(os.path.join(self._get_fixtures_dir(), filename), 'r').read()
return open(os.path.join(self._get_fixtures_dir(), filename)).read()
@GET('http://localhost/build/testproject/_result', file='result.xml')
def testPrjresults(self):

View File

@@ -10,7 +10,7 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'revertfile_fixtures')
def suite():
import unittest
return unittest.makeSuite(TestRevertFiles)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestRevertFiles)
class TestRevertFiles(OscTestCase):
def _get_fixtures_dir(self):
@@ -93,7 +93,7 @@ class TestRevertFiles(OscTestCase):
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())
self.assertEqual(open(fname).read(), open(storefile).read())
if __name__ == '__main__':
import unittest

View File

@@ -10,7 +10,7 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'setlinkrev_fixtures')
def suite():
import unittest
return unittest.makeSuite(TestSetLinkRev)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestSetLinkRev)
class TestSetLinkRev(OscTestCase):
def setUp(self):

View File

@@ -11,7 +11,7 @@ FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'update_fixtures')
def suite():
import unittest
return unittest.makeSuite(TestUpdate)
return unittest.defaultTestLoader.loadTestsFromTestCase(TestUpdate)
class TestUpdate(OscTestCase):
def _get_fixtures_dir(self):
@@ -115,7 +115,7 @@ class TestUpdate(OscTestCase):
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_deletelist('foo\n')
self._check_conflictlist('merge\n')
self.assertEqual(open('foo', 'r').read(), open(os.path.join('.osc', 'foo'), 'r').read())
self.assertEqual(open('foo').read(), open(os.path.join('.osc', 'foo')).read())
self._check_digests('testUpdateLocalDeletions_files')
@GET('http://localhost/source/osctest/restore?rev=latest', file='testUpdateRestore_files')