mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-10 14:56:14 +01:00
Merge pull request #1210 from dmach/projpac
Migrate more commands to the new project/package parsing
This commit is contained in:
commit
c1f0cfa1b7
23
behave/features/aggregatepac.feature
Normal file
23
behave/features/aggregatepac.feature
Normal file
@ -0,0 +1,23 @@
|
||||
Feature: `osc aggregatepac` command
|
||||
|
||||
|
||||
# common steps for all scenarios
|
||||
Background:
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
|
||||
|
||||
@destructive
|
||||
Scenario: Run `osc aggregatepac <project>/<package> <target-project>`
|
||||
When I execute osc with args "aggregatepac test:factory/test-pkgA home:Admin"
|
||||
Then the exit code is 0
|
||||
|
||||
|
||||
@destructive
|
||||
Scenario: Run `osc aggregatepac <project>/<package> <target-project>/<target-package>`
|
||||
When I execute osc with args "aggregatepac test:factory/test-pkgA home:Admin/test-pkgAA"
|
||||
Then the exit code is 0
|
||||
|
||||
|
||||
Scenario: Run `osc aggregatepac` where the source and target are the same
|
||||
When I execute osc with args "aggregatepac test:factory/test-pkgA test:factory"
|
||||
Then the exit code is 1
|
23
behave/features/copypac.feature
Normal file
23
behave/features/copypac.feature
Normal file
@ -0,0 +1,23 @@
|
||||
Feature: `osc copypac` command
|
||||
|
||||
|
||||
# common steps for all scenarios
|
||||
Background:
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
|
||||
|
||||
@destructive
|
||||
Scenario: Run `osc copypac <project>/<package> <target-project>`
|
||||
When I execute osc with args "copypac test:factory/test-pkgA home:Admin"
|
||||
Then the exit code is 0
|
||||
|
||||
|
||||
@destructive
|
||||
Scenario: Run `osc copypac <project>/<package> <target-project>/<target-package>`
|
||||
When I execute osc with args "copypac test:factory/test-pkgA home:Admin/test-pkgAA"
|
||||
Then the exit code is 0
|
||||
|
||||
|
||||
Scenario: Run `osc copypac` where the source and target are the same
|
||||
When I execute osc with args "copypac test:factory/test-pkgA test:factory"
|
||||
Then the exit code is 1
|
27
behave/features/detachbranch.feature
Normal file
27
behave/features/detachbranch.feature
Normal file
@ -0,0 +1,27 @@
|
||||
Feature: `osc detachbranch` command
|
||||
|
||||
|
||||
# common steps for all scenarios
|
||||
Background:
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
And I execute osc with args "linkpac test:factory/test-pkgA home:Admin"
|
||||
|
||||
|
||||
@destructive
|
||||
Scenario: Run `osc detachbranch <project> <package>`
|
||||
When I execute osc with args "detachbranch home:Admin test-pkgA"
|
||||
Then the exit code is 0
|
||||
|
||||
|
||||
@destructive
|
||||
Scenario: Run `osc detachbranch <project>`
|
||||
When I execute osc with args "detachbranch home:Admin"
|
||||
Then the exit code is 1
|
||||
|
||||
|
||||
@destructive
|
||||
Scenario: Run `osc detachbranch` from a package working copy
|
||||
Given I execute osc with args "co home:Admin/test-pkgA"
|
||||
And I set working directory to "{context.osc.temp}/home:Admin/test-pkgA"
|
||||
When I execute osc with args "detachbranch"
|
||||
Then the exit code is 0
|
27
behave/features/linktobranch.feature
Normal file
27
behave/features/linktobranch.feature
Normal file
@ -0,0 +1,27 @@
|
||||
Feature: `osc linktobranch` command
|
||||
|
||||
|
||||
# common steps for all scenarios
|
||||
Background:
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
And I execute osc with args "linkpac test:factory/test-pkgA home:Admin"
|
||||
|
||||
|
||||
@destructive
|
||||
Scenario: Run `osc linktobranch <project> <package>`
|
||||
When I execute osc with args "linktobranch home:Admin test-pkgA"
|
||||
Then the exit code is 0
|
||||
|
||||
|
||||
@destructive
|
||||
Scenario: Run `osc linktobranch <project>`
|
||||
When I execute osc with args "linktobranch home:Admin"
|
||||
Then the exit code is 1
|
||||
|
||||
|
||||
@destructive
|
||||
Scenario: Run `osc linktobranch` from a package working copy
|
||||
Given I execute osc with args "co home:Admin/test-pkgA"
|
||||
And I set working directory to "{context.osc.temp}/home:Admin/test-pkgA"
|
||||
When I execute osc with args "linktobranch"
|
||||
Then the exit code is 0
|
20
behave/features/undelete.feature
Normal file
20
behave/features/undelete.feature
Normal file
@ -0,0 +1,20 @@
|
||||
Feature: `osc undelete` command
|
||||
|
||||
|
||||
# common steps for all scenarios
|
||||
Background:
|
||||
Given I set working directory to "{context.osc.temp}"
|
||||
|
||||
|
||||
@destructive
|
||||
Scenario: Run `osc undelete <project>/<package>`
|
||||
Given I execute osc with args "rdelete test:factory/test-pkgA -m 'why:delete'"
|
||||
When I execute osc with args "undelete test:factory/test-pkgA -m 'why:undelete'"
|
||||
Then the exit code is 0
|
||||
|
||||
|
||||
@destructive
|
||||
Scenario: Run `osc undelete <project>`
|
||||
Given I execute osc with args "rdelete test:factory --recursive -m 'why:delete'"
|
||||
When I execute osc with args "undelete test:factory -m 'why:undelete'"
|
||||
Then the exit code is 0
|
@ -10,5 +10,6 @@ These are the packages in the osc package.
|
||||
osc.util
|
||||
osc.credentials
|
||||
osc.build
|
||||
osc.commandline
|
||||
osc.conf
|
||||
osc.OscConfigParser
|
||||
|
13
doc/api/osc.commandline.rst
Normal file
13
doc/api/osc.commandline.rst
Normal file
@ -0,0 +1,13 @@
|
||||
commandline
|
||||
===========
|
||||
|
||||
|
||||
The `osc.commandline` module provides argument parsing functionality to osc plugins.
|
||||
|
||||
|
||||
.. automodule:: osc.commandline
|
||||
:members: ensure_no_remaining_args,
|
||||
pop_project_package_from_args,
|
||||
pop_project_package_targetproject_targetpackage_from_args,
|
||||
pop_project_package_repository_arch_from_args,
|
||||
pop_repository_arch_from_args
|
@ -4,6 +4,7 @@
|
||||
# The cherry-picked imports will be the supported API.
|
||||
|
||||
from .api_build import BuildHistory
|
||||
from .api_configuration import get_configuration_value
|
||||
from .api_source import add_channels
|
||||
from .api_source import add_containers
|
||||
from .api_source import enable_channels
|
||||
|
12
osc/_private/api_configuration.py
Normal file
12
osc/_private/api_configuration.py
Normal file
@ -0,0 +1,12 @@
|
||||
from . import api
|
||||
from .. import oscerr
|
||||
|
||||
|
||||
def get_configuration_value(apiurl, option):
|
||||
url_path = ["configuration"]
|
||||
url_query = {}
|
||||
root = api.get(apiurl, url_path, url_query)
|
||||
node = api.find_node(root, "configuration", option)
|
||||
if node is None or not node.text:
|
||||
raise oscerr.APIError(f"Couldn't get configuration option '{option}'")
|
||||
return node.text
|
File diff suppressed because it is too large
Load Diff
44
osc/core.py
44
osc/core.py
@ -5631,6 +5631,9 @@ def aggregate_pac(
|
||||
- "map" is a dictionary SRC => TARGET repository mappings
|
||||
- "repo_check" determines if presence of repos in the source and destination repos is checked
|
||||
"""
|
||||
if (src_project, src_package) == (dst_project, dst_package):
|
||||
raise oscerr.OscValueError("Cannot aggregate package. Source and target are the same.")
|
||||
|
||||
meta_change = False
|
||||
dst_meta = ''
|
||||
apiurl = conf.config['apiurl']
|
||||
@ -5925,6 +5928,10 @@ def copy_pac(
|
||||
them into the other by uploading them (client-side copy) --
|
||||
or by the server, in a single api call.
|
||||
"""
|
||||
if (src_apiurl, src_project, src_package) == (dst_apiurl, dst_project, dst_package):
|
||||
# copypac is also used to expand sources, let's allow that
|
||||
if not expand:
|
||||
raise oscerr.OscValueError("Cannot copy package. Source and target are the same.")
|
||||
|
||||
if not (src_apiurl == dst_apiurl and src_project == dst_project
|
||||
and src_package == dst_package):
|
||||
@ -5993,6 +6000,23 @@ def copy_pac(
|
||||
return 'Done.'
|
||||
|
||||
|
||||
def lock(apiurl: str, project: str, package: str, msg: str = None):
|
||||
url_path = ["source", project]
|
||||
if package:
|
||||
url_path += [package]
|
||||
|
||||
url_query = {
|
||||
"cmd": "set_flag",
|
||||
"flag": "lock",
|
||||
"status": "enable",
|
||||
}
|
||||
|
||||
if msg:
|
||||
url_query["comment"] = msg
|
||||
|
||||
_private.api.post(apiurl, url_path, url_query)
|
||||
|
||||
|
||||
def unlock_package(apiurl: str, prj: str, pac: str, msg):
|
||||
query = {'cmd': 'unlock', 'comment': msg}
|
||||
u = makeurl(apiurl, ['source', prj, pac], query)
|
||||
@ -6026,6 +6050,15 @@ def undelete_project(apiurl: str, prj: str, msg=None):
|
||||
|
||||
|
||||
def delete_package(apiurl: str, prj: str, pac: str, force=False, msg=None):
|
||||
if not force:
|
||||
requests = get_request_collection(apiurl, project=prj, package=pac)
|
||||
if requests:
|
||||
error_msg = \
|
||||
"Package has pending requests. Deleting the package will break them. " \
|
||||
"They should be accepted/declined/revoked before deleting the package. " \
|
||||
"Or just use the 'force' option"
|
||||
raise oscerr.PackageError(prj, pac, error_msg)
|
||||
|
||||
query = {}
|
||||
if force:
|
||||
query['force'] = "1"
|
||||
@ -6035,7 +6068,16 @@ def delete_package(apiurl: str, prj: str, pac: str, force=False, msg=None):
|
||||
http_DELETE(u)
|
||||
|
||||
|
||||
def delete_project(apiurl: str, prj: str, force=False, msg=None):
|
||||
def delete_project(apiurl: str, prj: str, force=False, msg=None, recursive=False):
|
||||
if not recursive:
|
||||
packages = meta_get_packagelist(apiurl, project)
|
||||
if packages:
|
||||
error_msg = \
|
||||
"Project contains packages. It must be empty before deleting it. " \
|
||||
"If you are sure that you want to remove this project and all its " \
|
||||
"packages use the 'recursive' option."
|
||||
raise oscerr.ProjectError(prj, error_msg)
|
||||
|
||||
query = {}
|
||||
if force:
|
||||
query['force'] = "1"
|
||||
|
@ -32,49 +32,13 @@ class TestPopProjectPackageFromArgs(unittest.TestCase):
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
def test_explicit_project_and_package(self):
|
||||
def test_individual_args(self):
|
||||
args = ["project", "package", "another-arg"]
|
||||
project, package = pop_project_package_from_args(args)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, "package")
|
||||
self.assertEqual(args, ["another-arg"])
|
||||
|
||||
def test_defaults(self):
|
||||
args = ["project"]
|
||||
self.assertRaises(
|
||||
OscValueError,
|
||||
pop_project_package_from_args,
|
||||
args,
|
||||
default_package="default-package",
|
||||
)
|
||||
|
||||
args = ["project"]
|
||||
project, package = pop_project_package_from_args(
|
||||
args, default_package="default-package", package_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, "default-package")
|
||||
self.assertEqual(args, [])
|
||||
|
||||
args = []
|
||||
project, package = pop_project_package_from_args(
|
||||
args, default_project="default-project", default_package="default-package"
|
||||
)
|
||||
self.assertEqual(project, "default-project")
|
||||
self.assertEqual(package, "default-package")
|
||||
self.assertEqual(args, [])
|
||||
|
||||
args = []
|
||||
project, package = pop_project_package_from_args(
|
||||
args,
|
||||
default_project="default-project",
|
||||
default_package="default-package",
|
||||
package_is_optional=True,
|
||||
)
|
||||
self.assertEqual(project, "default-project")
|
||||
self.assertEqual(package, "default-package")
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_slash_separator(self):
|
||||
args = ["project/package", "another-arg"]
|
||||
project, package = pop_project_package_from_args(args)
|
||||
@ -88,6 +52,76 @@ class TestPopProjectPackageFromArgs(unittest.TestCase):
|
||||
self.assertEqual(package, "")
|
||||
self.assertEqual(args, ["another-arg"])
|
||||
|
||||
args = ["/", "another-arg"]
|
||||
project, package = pop_project_package_from_args(args)
|
||||
self.assertEqual(project, "")
|
||||
self.assertEqual(package, "")
|
||||
self.assertEqual(args, ["another-arg"])
|
||||
|
||||
def test_missing_project(self):
|
||||
args = []
|
||||
self.assertRaises(
|
||||
OscValueError,
|
||||
pop_project_package_from_args,
|
||||
args,
|
||||
)
|
||||
|
||||
def test_optional_project(self):
|
||||
args = []
|
||||
project, package = pop_project_package_from_args(
|
||||
args, project_is_optional=True,
|
||||
)
|
||||
self.assertEqual(project, None)
|
||||
self.assertEqual(package, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_default_project(self):
|
||||
args = []
|
||||
project, package = pop_project_package_from_args(
|
||||
args, default_project="default-project", package_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "default-project")
|
||||
self.assertEqual(package, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_missing_package(self):
|
||||
args = ["project"]
|
||||
self.assertRaises(
|
||||
OscValueError,
|
||||
pop_project_package_from_args,
|
||||
args,
|
||||
)
|
||||
|
||||
def test_optional_package(self):
|
||||
args = ["project"]
|
||||
project, package = pop_project_package_from_args(
|
||||
args, package_is_optional=True,
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_default_package(self):
|
||||
args = ["project"]
|
||||
project, package = pop_project_package_from_args(
|
||||
args, package_is_optional=True, default_package="default-package",
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, "default-package")
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_default_project_package(self):
|
||||
args = []
|
||||
project, package = pop_project_package_from_args(
|
||||
args,
|
||||
default_project="default-project",
|
||||
default_package="default-package",
|
||||
package_is_optional=True,
|
||||
)
|
||||
self.assertEqual(project, "default-project")
|
||||
self.assertEqual(package, "default-package")
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_no_working_copy(self):
|
||||
args = [".", "."]
|
||||
self.assertRaises(NoWorkingCopy, pop_project_package_from_args, args)
|
||||
@ -158,6 +192,28 @@ class TestPopProjectPackageFromArgs(unittest.TestCase):
|
||||
self.assertEqual(package, "store_package")
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_project_requires_to_specify_package(self):
|
||||
args = ["project"]
|
||||
self.assertRaises(
|
||||
OscValueError,
|
||||
pop_project_package_from_args,
|
||||
args,
|
||||
default_project=".",
|
||||
default_package=".",
|
||||
)
|
||||
|
||||
# The project from store is ignored because we've specified one.
|
||||
# Specifying a package is expected.
|
||||
self._write_store("store_project")
|
||||
args = ["project"]
|
||||
self.assertRaises(
|
||||
OscValueError,
|
||||
pop_project_package_from_args,
|
||||
args,
|
||||
default_project=".",
|
||||
default_package=".",
|
||||
)
|
||||
|
||||
|
||||
class TestPopRepositoryArchFromArgs(unittest.TestCase):
|
||||
def test_individial_args(self):
|
||||
@ -174,14 +230,54 @@ class TestPopRepositoryArchFromArgs(unittest.TestCase):
|
||||
self.assertEqual(arch, "arch")
|
||||
self.assertEqual(args, ["another-arg"])
|
||||
|
||||
args = ["repo/", "another-arg"]
|
||||
repo, arch = pop_repository_arch_from_args(args)
|
||||
self.assertEqual(repo, "repo")
|
||||
self.assertEqual(arch, "")
|
||||
self.assertEqual(args, ["another-arg"])
|
||||
|
||||
args = ["/", "another-arg"]
|
||||
repo, arch = pop_repository_arch_from_args(args)
|
||||
self.assertEqual(repo, "")
|
||||
self.assertEqual(arch, "")
|
||||
self.assertEqual(args, ["another-arg"])
|
||||
|
||||
def test_missing_repository(self):
|
||||
args = []
|
||||
self.assertRaises(OscValueError, pop_repository_arch_from_args, args)
|
||||
|
||||
def test_optional_repository(self):
|
||||
args = []
|
||||
repo, arch = pop_repository_arch_from_args(args, repository_is_optional=True)
|
||||
self.assertEqual(repo, None)
|
||||
self.assertEqual(arch, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_default_repository(self):
|
||||
args = []
|
||||
repo, arch = pop_repository_arch_from_args(args, default_repository="repo", arch_is_optional=True)
|
||||
self.assertEqual(repo, "repo")
|
||||
self.assertEqual(arch, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_missing_arch(self):
|
||||
args = ["repo"]
|
||||
self.assertRaises(OscValueError, pop_repository_arch_from_args, args)
|
||||
|
||||
def test_optional_arch(self):
|
||||
args = ["repo"]
|
||||
repo, arch = pop_repository_arch_from_args(args, arch_is_optional=True)
|
||||
self.assertEqual(repo, "repo")
|
||||
self.assertEqual(arch, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_default_arch(self):
|
||||
args = ["repo"]
|
||||
repo, arch = pop_repository_arch_from_args(args, default_arch="arch")
|
||||
self.assertEqual(repo, "repo")
|
||||
self.assertEqual(arch, "arch")
|
||||
self.assertEqual(args, [])
|
||||
|
||||
|
||||
class TestPopProjectPackageRepositoryArchFromArgs(unittest.TestCase):
|
||||
def _write_store(self, project=None, package=None):
|
||||
@ -226,23 +322,135 @@ class TestPopProjectPackageRepositoryArchFromArgs(unittest.TestCase):
|
||||
self.assertEqual(arch, "arch")
|
||||
self.assertEqual(args, ["another-arg"])
|
||||
|
||||
def test_missing_project(self):
|
||||
args = []
|
||||
self.assertRaises(
|
||||
OscValueError, pop_project_package_repository_arch_from_args, args
|
||||
)
|
||||
|
||||
def test_optional_project(self):
|
||||
args = []
|
||||
project, package, repo, arch = pop_project_package_repository_arch_from_args(
|
||||
args, project_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, None)
|
||||
self.assertEqual(package, None)
|
||||
self.assertEqual(repo, None)
|
||||
self.assertEqual(arch, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_default_project(self):
|
||||
args = []
|
||||
project, package, repo, arch = pop_project_package_repository_arch_from_args(
|
||||
args, default_project="project", package_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, None)
|
||||
self.assertEqual(repo, None)
|
||||
self.assertEqual(arch, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_missing_package(self):
|
||||
args = ["project"]
|
||||
self.assertRaises(
|
||||
OscValueError, pop_project_package_repository_arch_from_args, args
|
||||
)
|
||||
|
||||
def test_optional_package(self):
|
||||
args = ["project"]
|
||||
project, package, repo, arch = pop_project_package_repository_arch_from_args(
|
||||
args, package_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, None)
|
||||
self.assertEqual(repo, None)
|
||||
self.assertEqual(arch, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_default_package(self):
|
||||
args = ["project"]
|
||||
project, package, repo, arch = pop_project_package_repository_arch_from_args(
|
||||
args, default_package="package", repository_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, "package")
|
||||
self.assertEqual(repo, None)
|
||||
self.assertEqual(arch, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_missing_repository(self):
|
||||
args = ["project", "package"]
|
||||
self.assertRaises(
|
||||
OscValueError, pop_project_package_repository_arch_from_args, args
|
||||
)
|
||||
|
||||
def test_optional_repository(self):
|
||||
args = ["project", "package"]
|
||||
project, package, repo, arch = pop_project_package_repository_arch_from_args(
|
||||
args, repository_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, "package")
|
||||
self.assertEqual(repo, None)
|
||||
self.assertEqual(arch, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_default_repository(self):
|
||||
args = ["project", "package"]
|
||||
project, package, repo, arch = pop_project_package_repository_arch_from_args(
|
||||
args, default_repository="repository", arch_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, "package")
|
||||
self.assertEqual(repo, "repository")
|
||||
self.assertEqual(arch, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_missing_arch(self):
|
||||
args = ["project", "package", "repo"]
|
||||
self.assertRaises(
|
||||
OscValueError, pop_project_package_repository_arch_from_args, args
|
||||
)
|
||||
|
||||
def test_optional_arch(self):
|
||||
args = ["project", "package", "repository"]
|
||||
project, package, repo, arch = pop_project_package_repository_arch_from_args(
|
||||
args, arch_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, "package")
|
||||
self.assertEqual(repo, "repository")
|
||||
self.assertEqual(arch, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_default_arch(self):
|
||||
args = ["project", "package", "repository"]
|
||||
project, package, repo, arch = pop_project_package_repository_arch_from_args(
|
||||
args, default_arch="arch"
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, "package")
|
||||
self.assertEqual(repo, "repository")
|
||||
self.assertEqual(arch, "arch")
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_no_working_copy(self):
|
||||
args = ["repo", "arch"]
|
||||
self.assertRaises(
|
||||
NoWorkingCopy, pop_project_package_repository_arch_from_args, args
|
||||
NoWorkingCopy,
|
||||
pop_project_package_repository_arch_from_args,
|
||||
args,
|
||||
default_project=".",
|
||||
default_package=".",
|
||||
)
|
||||
|
||||
def test_working_copy(self):
|
||||
self._write_store("store_project", "store_package")
|
||||
args = ["repo", "arch"]
|
||||
project, package, repo, arch = pop_project_package_repository_arch_from_args(
|
||||
args
|
||||
args,
|
||||
default_project=".",
|
||||
default_package=".",
|
||||
)
|
||||
self.assertEqual(project, "store_project")
|
||||
self.assertEqual(package, "store_package")
|
||||
@ -254,9 +462,27 @@ class TestPopProjectPackageRepositoryArchFromArgs(unittest.TestCase):
|
||||
args = ["repo", "arch", "another-arg"]
|
||||
# example of invalid usage, working copy is not used when there's 3+ args; [project, package, ...] are expected
|
||||
self.assertRaises(
|
||||
OscValueError, pop_project_package_repository_arch_from_args, args
|
||||
OscValueError,
|
||||
pop_project_package_repository_arch_from_args,
|
||||
args,
|
||||
default_project=".",
|
||||
default_package=".",
|
||||
)
|
||||
|
||||
def test_working_copy_optional_arch(self):
|
||||
self._write_store("store_project", "store_package")
|
||||
args = ["repository"]
|
||||
project, package, repo, arch = pop_project_package_repository_arch_from_args(
|
||||
args,
|
||||
default_project=".",
|
||||
default_package=".",
|
||||
arch_is_optional=True,
|
||||
)
|
||||
self.assertEqual(project, "store_project")
|
||||
self.assertEqual(package, "store_package")
|
||||
self.assertEqual(repo, "repository")
|
||||
self.assertEqual(arch, None)
|
||||
|
||||
|
||||
class TestPopProjectPackageTargetProjectTargetPackageFromArgs(unittest.TestCase):
|
||||
def _write_store(self, project=None, package=None):
|
||||
@ -301,6 +527,95 @@ class TestPopProjectPackageTargetProjectTargetPackageFromArgs(unittest.TestCase)
|
||||
self.assertEqual(target_package, "target-package")
|
||||
self.assertEqual(args, ["another-arg"])
|
||||
|
||||
def test_missing_project(self):
|
||||
args = []
|
||||
self.assertRaises(
|
||||
OscValueError, pop_project_package_targetproject_targetpackage_from_args, args
|
||||
)
|
||||
|
||||
def test_optional_project(self):
|
||||
args = []
|
||||
project, package, target_project, target_package = pop_project_package_targetproject_targetpackage_from_args(
|
||||
args, project_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, None)
|
||||
self.assertEqual(package, None)
|
||||
self.assertEqual(target_project, None)
|
||||
self.assertEqual(target_package, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_default_project(self):
|
||||
args = []
|
||||
project, package, target_project, target_package = pop_project_package_targetproject_targetpackage_from_args(
|
||||
args, default_project="project", package_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, None)
|
||||
self.assertEqual(target_project, None)
|
||||
self.assertEqual(target_package, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_missing_package(self):
|
||||
args = ["project"]
|
||||
self.assertRaises(
|
||||
OscValueError, pop_project_package_targetproject_targetpackage_from_args, args
|
||||
)
|
||||
|
||||
def test_optional_package(self):
|
||||
args = ["project"]
|
||||
project, package, target_project, target_package = pop_project_package_targetproject_targetpackage_from_args(
|
||||
args, package_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, None)
|
||||
self.assertEqual(target_project, None)
|
||||
self.assertEqual(target_package, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_default_package(self):
|
||||
args = ["project"]
|
||||
project, package, target_project, target_package = pop_project_package_targetproject_targetpackage_from_args(
|
||||
args, default_package="package", target_project_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, "package")
|
||||
self.assertEqual(target_project, None)
|
||||
self.assertEqual(target_package, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_missing_target_project(self):
|
||||
args = ["project", "package"]
|
||||
project, package, target_project, target_package = pop_project_package_targetproject_targetpackage_from_args(
|
||||
args, target_project_is_optional=True, target_package_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, "package")
|
||||
self.assertEqual(target_project, None)
|
||||
self.assertEqual(target_package, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_optional_target_project(self):
|
||||
args = ["project", "package"]
|
||||
project, package, target_project, target_package = pop_project_package_targetproject_targetpackage_from_args(
|
||||
args, target_project_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, "package")
|
||||
self.assertEqual(target_project, None)
|
||||
self.assertEqual(target_package, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_default_target_project(self):
|
||||
args = ["project", "package"]
|
||||
project, package, target_project, target_package = pop_project_package_targetproject_targetpackage_from_args(
|
||||
args, default_target_project="package", target_package_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, "package")
|
||||
self.assertEqual(target_project, "package")
|
||||
self.assertEqual(target_package, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_missing_target_package(self):
|
||||
args = ["project", "package", "target-project"]
|
||||
project, package, target_project, target_package = pop_project_package_targetproject_targetpackage_from_args(
|
||||
@ -312,19 +627,45 @@ class TestPopProjectPackageTargetProjectTargetPackageFromArgs(unittest.TestCase)
|
||||
self.assertEqual(target_package, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_optional_target_package(self):
|
||||
args = ["project", "package", "target-project"]
|
||||
project, package, target_project, target_package = pop_project_package_targetproject_targetpackage_from_args(
|
||||
args, target_package_is_optional=True
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, "package")
|
||||
self.assertEqual(target_project, "target-project")
|
||||
self.assertEqual(target_package, None)
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_default_target_package(self):
|
||||
args = ["project", "package", "target-project"]
|
||||
project, package, target_project, target_package = pop_project_package_targetproject_targetpackage_from_args(
|
||||
args, default_target_package="target-package"
|
||||
)
|
||||
self.assertEqual(project, "project")
|
||||
self.assertEqual(package, "package")
|
||||
self.assertEqual(target_project, "target-project")
|
||||
self.assertEqual(target_package, "target-package")
|
||||
self.assertEqual(args, [])
|
||||
|
||||
def test_no_working_copy(self):
|
||||
args = ["target-project", "target-package"]
|
||||
self.assertRaises(
|
||||
NoWorkingCopy,
|
||||
pop_project_package_targetproject_targetpackage_from_args,
|
||||
args,
|
||||
default_project=".",
|
||||
default_package=".",
|
||||
)
|
||||
|
||||
def test_working_copy(self):
|
||||
self._write_store("store_project", "store_package")
|
||||
args = ["target-project", "target-package"]
|
||||
project, package, target_project, target_package = pop_project_package_targetproject_targetpackage_from_args(
|
||||
args
|
||||
args,
|
||||
default_project=".",
|
||||
default_package=".",
|
||||
)
|
||||
self.assertEqual(project, "store_project")
|
||||
self.assertEqual(package, "store_package")
|
||||
@ -335,7 +676,10 @@ class TestPopProjectPackageTargetProjectTargetPackageFromArgs(unittest.TestCase)
|
||||
self._write_store("store_project", "store_package")
|
||||
args = ["target-project"]
|
||||
project, package, target_project, target_package = pop_project_package_targetproject_targetpackage_from_args(
|
||||
args, target_package_is_optional=True
|
||||
args,
|
||||
default_project=".",
|
||||
default_package=".",
|
||||
target_package_is_optional=True,
|
||||
)
|
||||
self.assertEqual(project, "store_project")
|
||||
self.assertEqual(package, "store_package")
|
||||
|
Loading…
Reference in New Issue
Block a user