mirror of
https://github.com/openSUSE/osc.git
synced 2025-09-06 21:28:42 +02:00
Replace core.findpacs() with Package.from_paths() and Package.from_paths_nofail()
The original findpacs() was returning either [Package] or ([Package], [str]) depending on the `fatal` option. This confused pylint and it was returning false-positives: E1101: Instance of 'list' has no '...' member (no-member)
This commit is contained in:
7
tests/fixtures/packages/oscrc
vendored
Normal file
7
tests/fixtures/packages/oscrc
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[general]
|
||||
apiurl = http://localhost
|
||||
|
||||
[http://localhost]
|
||||
user=Admin
|
||||
pass=opensuse
|
||||
allow_http=1
|
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgA/.osc/_apiurl
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgA/.osc/_apiurl
vendored
Normal file
@@ -0,0 +1 @@
|
||||
http://example.com
|
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgA/.osc/_files
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgA/.osc/_files
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<directory name="pkgA" rev="1" srcmd5="d41d8cd98f00b204e9800998ecf8427e" vrev="1" />
|
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgA/.osc/_osclib_version
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgA/.osc/_osclib_version
vendored
Normal file
@@ -0,0 +1 @@
|
||||
1.0
|
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgA/.osc/_package
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgA/.osc/_package
vendored
Normal file
@@ -0,0 +1 @@
|
||||
pkgA
|
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgA/.osc/_project
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgA/.osc/_project
vendored
Normal file
@@ -0,0 +1 @@
|
||||
projectA
|
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgB/.osc/_apiurl
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgB/.osc/_apiurl
vendored
Normal file
@@ -0,0 +1 @@
|
||||
http://example.com
|
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgB/.osc/_files
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgB/.osc/_files
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<directory name="pkgA" rev="1" srcmd5="d41d8cd98f00b204e9800998ecf8427e" vrev="1" />
|
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgB/.osc/_osclib_version
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgB/.osc/_osclib_version
vendored
Normal file
@@ -0,0 +1 @@
|
||||
1.0
|
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgB/.osc/_package
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgB/.osc/_package
vendored
Normal file
@@ -0,0 +1 @@
|
||||
pkgB
|
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgB/.osc/_project
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA-different-apiurl/pkgB/.osc/_project
vendored
Normal file
@@ -0,0 +1 @@
|
||||
projectA
|
1
tests/fixtures/packages/osctest/projectA/pkgA/.osc/_apiurl
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA/pkgA/.osc/_apiurl
vendored
Normal file
@@ -0,0 +1 @@
|
||||
http://localhost
|
1
tests/fixtures/packages/osctest/projectA/pkgA/.osc/_files
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA/pkgA/.osc/_files
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<directory name="pkgA" rev="1" srcmd5="d41d8cd98f00b204e9800998ecf8427e" vrev="1" />
|
1
tests/fixtures/packages/osctest/projectA/pkgA/.osc/_osclib_version
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA/pkgA/.osc/_osclib_version
vendored
Normal file
@@ -0,0 +1 @@
|
||||
1.0
|
1
tests/fixtures/packages/osctest/projectA/pkgA/.osc/_package
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA/pkgA/.osc/_package
vendored
Normal file
@@ -0,0 +1 @@
|
||||
pkgA
|
1
tests/fixtures/packages/osctest/projectA/pkgA/.osc/_project
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA/pkgA/.osc/_project
vendored
Normal file
@@ -0,0 +1 @@
|
||||
projectA
|
1
tests/fixtures/packages/osctest/projectA/pkgB/.osc/_apiurl
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA/pkgB/.osc/_apiurl
vendored
Normal file
@@ -0,0 +1 @@
|
||||
http://localhost
|
1
tests/fixtures/packages/osctest/projectA/pkgB/.osc/_files
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA/pkgB/.osc/_files
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<directory name="pkgA" rev="1" srcmd5="d41d8cd98f00b204e9800998ecf8427e" vrev="1" />
|
1
tests/fixtures/packages/osctest/projectA/pkgB/.osc/_osclib_version
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA/pkgB/.osc/_osclib_version
vendored
Normal file
@@ -0,0 +1 @@
|
||||
1.0
|
1
tests/fixtures/packages/osctest/projectA/pkgB/.osc/_package
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA/pkgB/.osc/_package
vendored
Normal file
@@ -0,0 +1 @@
|
||||
pkgB
|
1
tests/fixtures/packages/osctest/projectA/pkgB/.osc/_project
vendored
Normal file
1
tests/fixtures/packages/osctest/projectA/pkgB/.osc/_project
vendored
Normal file
@@ -0,0 +1 @@
|
||||
projectA
|
1
tests/fixtures/packages/osctest/projectB/pkgA/.osc/_apiurl
vendored
Normal file
1
tests/fixtures/packages/osctest/projectB/pkgA/.osc/_apiurl
vendored
Normal file
@@ -0,0 +1 @@
|
||||
http://localhost
|
1
tests/fixtures/packages/osctest/projectB/pkgA/.osc/_files
vendored
Normal file
1
tests/fixtures/packages/osctest/projectB/pkgA/.osc/_files
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<directory name="pkgA" rev="1" srcmd5="d41d8cd98f00b204e9800998ecf8427e" vrev="1" />
|
1
tests/fixtures/packages/osctest/projectB/pkgA/.osc/_osclib_version
vendored
Normal file
1
tests/fixtures/packages/osctest/projectB/pkgA/.osc/_osclib_version
vendored
Normal file
@@ -0,0 +1 @@
|
||||
1.0
|
1
tests/fixtures/packages/osctest/projectB/pkgA/.osc/_package
vendored
Normal file
1
tests/fixtures/packages/osctest/projectB/pkgA/.osc/_package
vendored
Normal file
@@ -0,0 +1 @@
|
||||
pkgA
|
1
tests/fixtures/packages/osctest/projectB/pkgA/.osc/_project
vendored
Normal file
1
tests/fixtures/packages/osctest/projectB/pkgA/.osc/_project
vendored
Normal file
@@ -0,0 +1 @@
|
||||
projectB
|
1
tests/fixtures/packages/osctest/projectB/pkgB/.osc/_apiurl
vendored
Normal file
1
tests/fixtures/packages/osctest/projectB/pkgB/.osc/_apiurl
vendored
Normal file
@@ -0,0 +1 @@
|
||||
http://localhost
|
1
tests/fixtures/packages/osctest/projectB/pkgB/.osc/_files
vendored
Normal file
1
tests/fixtures/packages/osctest/projectB/pkgB/.osc/_files
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<directory name="pkgA" rev="1" srcmd5="d41d8cd98f00b204e9800998ecf8427e" vrev="1" />
|
1
tests/fixtures/packages/osctest/projectB/pkgB/.osc/_osclib_version
vendored
Normal file
1
tests/fixtures/packages/osctest/projectB/pkgB/.osc/_osclib_version
vendored
Normal file
@@ -0,0 +1 @@
|
||||
1.0
|
1
tests/fixtures/packages/osctest/projectB/pkgB/.osc/_package
vendored
Normal file
1
tests/fixtures/packages/osctest/projectB/pkgB/.osc/_package
vendored
Normal file
@@ -0,0 +1 @@
|
||||
pkgB
|
1
tests/fixtures/packages/osctest/projectB/pkgB/.osc/_project
vendored
Normal file
1
tests/fixtures/packages/osctest/projectB/pkgB/.osc/_project
vendored
Normal file
@@ -0,0 +1 @@
|
||||
projectB
|
@@ -1,6 +1,13 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import osc.core
|
||||
import osc.oscerr
|
||||
|
||||
from .common import OscTestCase
|
||||
|
||||
|
||||
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), "fixtures", "packages")
|
||||
|
||||
|
||||
class PackageMock(osc.core.Package):
|
||||
@@ -58,5 +65,118 @@ class TestPackage(unittest.TestCase):
|
||||
self.assertIn(p2, packages)
|
||||
|
||||
|
||||
class TestPackageFromPaths(OscTestCase):
|
||||
def _get_fixtures_dir(self):
|
||||
return FIXTURES_DIR
|
||||
|
||||
def test_single_package(self):
|
||||
paths = ["projectA/pkgA"]
|
||||
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]
|
||||
pacs = osc.core.Package.from_paths(paths)
|
||||
self.assertEqual(len(pacs), 1)
|
||||
|
||||
pac = pacs[0]
|
||||
self.assertEqual(pac.name, "pkgA")
|
||||
self.assertEqual(pac.prjname, "projectA")
|
||||
self.assertEqual(pac.apiurl, "http://localhost")
|
||||
|
||||
def test_duplicates(self):
|
||||
paths = ["projectA/pkgA", "projectA/pkgA"]
|
||||
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]
|
||||
self.assertRaises(osc.oscerr.PackageExists, osc.core.Package.from_paths, paths)
|
||||
|
||||
def test_two_packages(self):
|
||||
paths = ["projectA/pkgA", "projectA/pkgB"]
|
||||
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]
|
||||
pacs = osc.core.Package.from_paths(paths)
|
||||
self.assertEqual(len(pacs), 2)
|
||||
|
||||
pac = pacs[0]
|
||||
self.assertEqual(pac.name, "pkgA")
|
||||
self.assertEqual(pac.prjname, "projectA")
|
||||
self.assertEqual(pac.apiurl, "http://localhost")
|
||||
|
||||
pac = pacs[1]
|
||||
self.assertEqual(pac.name, "pkgB")
|
||||
self.assertEqual(pac.prjname, "projectA")
|
||||
self.assertEqual(pac.apiurl, "http://localhost")
|
||||
|
||||
def test_two_projects(self):
|
||||
paths = ["projectA/pkgA", "projectA/pkgB", "projectB/pkgA", "projectB/pkgB"]
|
||||
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]
|
||||
pacs = osc.core.Package.from_paths(paths)
|
||||
self.assertEqual(len(pacs), 4)
|
||||
|
||||
pac = pacs[0]
|
||||
self.assertEqual(pac.name, "pkgA")
|
||||
self.assertEqual(pac.prjname, "projectA")
|
||||
self.assertEqual(pac.apiurl, "http://localhost")
|
||||
|
||||
pac = pacs[1]
|
||||
self.assertEqual(pac.name, "pkgB")
|
||||
self.assertEqual(pac.prjname, "projectA")
|
||||
self.assertEqual(pac.apiurl, "http://localhost")
|
||||
|
||||
pac = pacs[2]
|
||||
self.assertEqual(pac.name, "pkgA")
|
||||
self.assertEqual(pac.prjname, "projectB")
|
||||
self.assertEqual(pac.apiurl, "http://localhost")
|
||||
|
||||
pac = pacs[3]
|
||||
self.assertEqual(pac.name, "pkgB")
|
||||
self.assertEqual(pac.prjname, "projectB")
|
||||
self.assertEqual(pac.apiurl, "http://localhost")
|
||||
|
||||
def test_two_apiurls(self):
|
||||
paths = ["projectA/pkgA", "projectA/pkgB", "projectA-different-apiurl/pkgA", "projectA-different-apiurl/pkgB"]
|
||||
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]
|
||||
pacs = osc.core.Package.from_paths(paths)
|
||||
self.assertEqual(len(pacs), 4)
|
||||
|
||||
pac = pacs[0]
|
||||
self.assertEqual(pac.name, "pkgA")
|
||||
self.assertEqual(pac.prjname, "projectA")
|
||||
self.assertEqual(pac.apiurl, "http://localhost")
|
||||
|
||||
pac = pacs[1]
|
||||
self.assertEqual(pac.name, "pkgB")
|
||||
self.assertEqual(pac.prjname, "projectA")
|
||||
self.assertEqual(pac.apiurl, "http://localhost")
|
||||
|
||||
pac = pacs[2]
|
||||
self.assertEqual(pac.name, "pkgA")
|
||||
self.assertEqual(pac.prjname, "projectA")
|
||||
self.assertEqual(pac.apiurl, "http://example.com")
|
||||
|
||||
pac = pacs[3]
|
||||
self.assertEqual(pac.name, "pkgB")
|
||||
self.assertEqual(pac.prjname, "projectA")
|
||||
self.assertEqual(pac.apiurl, "http://example.com")
|
||||
|
||||
def test_invalid_package(self):
|
||||
paths = ["projectA/pkgA", "projectA"]
|
||||
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]
|
||||
self.assertRaises(osc.oscerr.NoWorkingCopy, osc.core.Package.from_paths, paths)
|
||||
|
||||
def test_nofail(self):
|
||||
# valid package, invalid package, nonexistent package
|
||||
paths = ["projectA/pkgA", "projectA", "does-not-exist"]
|
||||
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]
|
||||
pacs, nopacs = osc.core.Package.from_paths_nofail(paths)
|
||||
|
||||
self.assertEqual(len(pacs), 1)
|
||||
|
||||
pac = pacs[0]
|
||||
self.assertEqual(pac.name, "pkgA")
|
||||
self.assertEqual(pac.prjname, "projectA")
|
||||
self.assertEqual(pac.apiurl, "http://localhost")
|
||||
|
||||
expected = [
|
||||
os.path.join(self.tmpdir, "osctest", "projectA"),
|
||||
os.path.join(self.tmpdir, "osctest", "does-not-exist"),
|
||||
]
|
||||
self.assertEqual(nopacs, expected)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user