Python argparse.Namespace() Examples
The following are 30
code examples of argparse.Namespace().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
argparse
, or try the search function
.
Example #1
Source File: deploy.py From aegea with Apache License 2.0 | 7 votes |
def grant(args): """ Given an IAM role or instance name, attach an IAM policy granting appropriate permissions to subscribe to deployments. Given a GitHub repo URL, create and record deployment keys for the repo and any of its private submodules, making the keys accessible to the IAM role. """ try: role = resources.iam.Role(args.iam_role_or_instance) role.load() except ClientError: role = get_iam_role_for_instance(args.iam_role_or_instance) role.attach_policy(PolicyArn=ensure_deploy_iam_policy().arn) for private_repo in [args.repo] + list(private_submodules(args.repo)): gh_owner_name, gh_repo_name = parse_repo_name(private_repo) secret = secrets.put(argparse.Namespace(secret_name="deploy.{}.{}".format(gh_owner_name, gh_repo_name), iam_role=role.name, instance_profile=None, iam_group=None, iam_user=None, generate_ssh_key=True)) get_repo(private_repo).create_key(__name__ + "." + role.name, secret["ssh_public_key"]) logger.info("Created deploy key %s for IAM role %s to access GitHub repo %s", secret["ssh_key_fingerprint"], role.name, private_repo)
Example #2
Source File: fire.py From fireprox with GNU General Public License v3.0 | 7 votes |
def __init__(self, arguments: argparse.Namespace, help_text: str): self.profile_name = arguments.profile_name self.access_key = arguments.access_key self.secret_access_key = arguments.secret_access_key self.session_token = arguments.session_token self.region = arguments.region self.command = arguments.command self.api_id = arguments.api_id self.url = arguments.url self.api_list = [] self.client = None self.help = help_text if self.access_key and self.secret_access_key: if not self.region: self.error('Please provide a region with AWS credentials') if not self.load_creds(): self.error('Unable to load AWS credentials') if not self.command: self.error('Please provide a valid command')
Example #3
Source File: test_components_repository_repository.py From skelebot with MIT License | 6 votes |
def test_execute_push_artifactory_all(self, mock_artifactory, mock_remove, mock_copy): config = sb.objects.config.Config(version="1.0.0") args = argparse.Namespace(job="push", force=True, artifact='ALL', user='sean', token='abc123') self.artifactory.execute(config, args) mock_artifactory.assert_has_calls([ mock.call("artifactory.test.com/ml/test/test_v1.0.0.pkl", auth=('sean', 'abc123')), mock.call("artifactory.test.com/ml/test/test2_v1.0.0.pkl", auth=('sean', 'abc123')) ], any_order=True) mock_copy.assert_has_calls([ mock.call("test.pkl", "test_v1.0.0.pkl"), mock.call("test2.pkl", "test2_v1.0.0.pkl") ], any_order=True) mock_remove.assert_has_calls([ mock.call("test_v1.0.0.pkl"), mock.call("test2_v1.0.0.pkl") ], any_order=True)
Example #4
Source File: test_components_repository_repository.py From skelebot with MIT License | 6 votes |
def test_execute_push_conflict_s3(self, mock_boto3_session): mock_client = mock.Mock() mock_session = mock.Mock() mock_client.list_objects_v2.return_value = {"Contents": [{"Key": "test_v1.0.0.pkl"}]} mock_session.client.return_value = mock_client mock_boto3_session.return_value = mock_session config = sb.objects.config.Config(version="1.0.0") args = argparse.Namespace(job="push", force=False, artifact='test', user='sean', token='abc123') expectedException = "This artifact version already exists. Please bump the version or use the force parameter (-f) to overwrite the artifact." try: self.s3.execute(config, args) self.fail("Exception Not Thrown") except Exception as exc: self.assertEqual(str(exc), expectedException) mock_client.list_objects_v2.assert_called_with(Bucket="my-bucket", Prefix="test_v1.0.0.pkl")
Example #5
Source File: pipeline_common.py From gcp-variant-transforms with Apache License 2.0 | 6 votes |
def parse_args(argv, command_line_options): # type: (List[str], List[type]) -> (argparse.Namespace, List[str]) """Parses the arguments. Args: argv: A list of string representing the pipeline arguments. command_line_options: A list of type ``VariantTransformsOptions`` that specifies the options that will be added to parser. """ parser = argparse.ArgumentParser() parser.register('type', 'bool', lambda v: v.lower() == 'true') options = [option() for option in command_line_options] for transform_options in options: transform_options.add_arguments(parser) known_args, pipeline_args = parser.parse_known_args(argv) for transform_options in options: transform_options.validate(known_args) _raise_error_on_invalid_flags(pipeline_args) if hasattr(known_args, 'input_pattern') or hasattr(known_args, 'input_file'): known_args.all_patterns = _get_all_patterns( known_args.input_pattern, known_args.input_file) return known_args, pipeline_args
Example #6
Source File: test_systems_execution_commandBuilder.py From skelebot with MIT License | 6 votes |
def test_build_list_param(self, mock_getcwd, mock_expanduser): folderPath = "{path}/test/files".format(path=self.path) args = Namespace(version='0.1', test_test=[1, 2, 3], arg_arg="argy") mock_expanduser.return_value = "{path}/test/plugins".format(path=self.path) mock_getcwd.return_value = folderPath config = sb.systems.generators.yaml.loadConfig() job = config.jobs[0] param = sb.objects.param.Param("test-test", "t", accepts="list") arg = sb.objects.arg.Arg("arg-arg") job.params.append(param) job.args.append(arg) expected = "bash build.sh 0.1 argy --env local --test-test 1 2 3 --log info" command = sb.systems.execution.commandBuilder.build(config, job, args) self.assertEqual(command, expected)
Example #7
Source File: test_systems_execution_docker.py From skelebot with MIT License | 6 votes |
def test_run_docker_params_entrypoint(self, mock_getcwd, mock_call, mock_expanduser): folderPath = "{path}/test/files".format(path=self.path) memory = 256 args = Namespace(version='0.1') homePath = "{path}/test/plugins".format(path=self.path) mock_expanduser.return_value = homePath mock_getcwd.return_value = folderPath mock_call.return_value = 0 config = sb.systems.generators.yaml.loadConfig() config.primaryExe = "ENTRYPOINT" config.components.append(LimitMemory(memory)) job = sb.objects.job.Job(name='some_command', help='Dummy', source='echo some_command') command = sb.systems.execution.commandBuilder.build(config, job, args) expected = "docker run --name test-some_command --rm -i --memory {memory}GB --entrypoint echo test some_command".format(memory=memory) sb.systems.execution.docker.run(config, command, job.mode, config.ports, job.mappings, job.name) mock_call.assert_called_once_with(expected, shell=True)
Example #8
Source File: test_systems_execution_docker.py From skelebot with MIT License | 6 votes |
def test_run_docker_params(self, mock_getcwd, mock_call, mock_expanduser): folderPath = "{path}/test/files".format(path=self.path) memory = 256 args = Namespace(version='0.1') homePath = "{path}/test/plugins".format(path=self.path) mock_expanduser.return_value = homePath mock_getcwd.return_value = folderPath mock_call.return_value = 0 config = sb.systems.generators.yaml.loadConfig() config.components.append(LimitMemory(memory)) job = sb.objects.job.Job(name='some_command', help='Dummy', source='echo some_command') command = sb.systems.execution.commandBuilder.build(config, job, args) expected = "docker run --name test-some_command --rm -i --memory {memory}GB test /bin/bash -c \"echo some_command\"".format(memory=memory) sb.systems.execution.docker.run(config, command, job.mode, config.ports, job.mappings, job.name) mock_call.assert_called_once_with(expected, shell=True)
Example #9
Source File: test_edit_command.py From S4 with GNU General Public License v3.0 | 5 votes |
def test_no_changes(self, get_input, config_file): fake_stream = ["", "", "", "", "", ""] get_input.side_effect = fake_stream args = argparse.Namespace(target="foo") config = { "targets": { "foo": { "local_folder": "/home/mark/documents", "endpoint_url": "https://customurl.com", "s3_uri": "s3://buckets/mybackup", "aws_access_key_id": "23123123123313", "aws_secret_access_key": "edwdadwadwadwdd", "region_name": "eu-west-1", } } } command = EditCommand(args, config, utils.create_logger()) command.run() with open(config_file, "r") as fp: config = json.load(fp) expected_config = { "targets": { "foo": { "local_folder": "/home/mark/documents", "endpoint_url": "https://customurl.com", "s3_uri": "s3://buckets/mybackup", "aws_access_key_id": "23123123123313", "aws_secret_access_key": "edwdadwadwadwdd", "region_name": "eu-west-1", } } } assert expected_config == config
Example #10
Source File: test_rm_command.py From S4 with GNU General Public License v3.0 | 5 votes |
def test_remove_target(self, capsys, config_file): args = argparse.Namespace(target="foo") command = RmCommand(args, {"targets": {"bar": {}, "foo": {}}}, create_logger()) command.run() out, err = capsys.readouterr() assert out == err == "" with open(config_file, "rt") as fp: new_config = json.load(fp) expected_config = {"targets": {"bar": {}}} assert new_config == expected_config
Example #11
Source File: test_daemon_command.py From S4 with GNU General Public License v3.0 | 5 votes |
def test_wrong_target(self, INotifyRecursive, SyncWorker, capsys): args = argparse.Namespace(targets=["foo"], conflicts="ignore", read_delay=0) command = DaemonCommand(args, {"targets": {"bar": {}}}, create_logger()) command.run(terminator=self.single_term) out, err = capsys.readouterr() assert out == "" assert err == ("Unknown target: foo\n") assert SyncWorker.call_count == 0 assert INotifyRecursive.call_count == 0
Example #12
Source File: test_daemon_command.py From S4 with GNU General Public License v3.0 | 5 votes |
def test_no_targets(self, INotifyRecursive, SyncWorker, capsys): args = argparse.Namespace(targets=None, conflicts="ignore", read_delay=0) command = DaemonCommand(args, {"targets": {}}, create_logger()) command.run(terminator=self.single_term) out, err = capsys.readouterr() assert out == "" assert err == ("No targets available\n" 'Use "add" command first\n') assert SyncWorker.call_count == 0 assert INotifyRecursive.call_count == 0
Example #13
Source File: test_daemon_command.py From S4 with GNU General Public License v3.0 | 5 votes |
def test_os_not_supported(self, INotifyRecursive, SyncWorker, capsys): args = argparse.Namespace(targets=None, conflicts="ignore", read_delay=0) command = DaemonCommand(args, {}, create_logger()) command.run(terminator=self.single_term) out, err = capsys.readouterr() assert out == "" assert err == ( "Cannot run INotify on your operating system\n" "Only Linux machines are officially supported for this command\n" ) assert SyncWorker.call_count == 0 assert INotifyRecursive.call_count == 0
Example #14
Source File: variant_transform_options_test.py From gcp-variant-transforms with Apache License 2.0 | 5 votes |
def _make_args(self, args): # type: (List[str]) -> argparse.Namespace return make_args(self._options, args)
Example #15
Source File: test_daemon_command.py From S4 with GNU General Public License v3.0 | 5 votes |
def test_specific_target(self, INotifyRecursive, SyncWorker): INotifyRecursive.return_value = FakeINotify( events={ Event(wd=1, mask=flags.CREATE, cookie=None, name="hello.txt"), Event(wd=2, mask=flags.CREATE, cookie=None, name="bar.txt"), }, wd_map={1: "/home/jon/code/", 2: "/home/jon/code/hoot"}, ) args = argparse.Namespace(targets=["foo"], conflicts="ignore", read_delay=0) config = { "targets": { "foo": { "local_folder": "/home/jon/code", "s3_uri": "s3://bucket/code", "aws_secret_access_key": "23232323", "aws_access_key_id": "########", "region_name": "eu-west-2", }, "bar": {}, } } command = DaemonCommand(args, config, create_logger()) command.run(terminator=self.single_term) assert SyncWorker.call_count == 2 assert INotifyRecursive.call_count == 1
Example #16
Source File: test_deps.py From alibuild with GNU General Public License v3.0 | 5 votes |
def test_deps(self, mockOpen, mockExecute, mockDepsOpen): mockOpen.side_effect = lambda f: { "/dist/aliroot.sh" : StringIO(RECIPE_ALIROOT), "/dist/root.sh" : StringIO(RECIPE_ROOT), "/dist/gcc-toolchain.sh" : StringIO(RECIPE_GCC_TOOLCHAIN), "/dist/defaults-release.sh" : StringIO(RECIPE_DEFAULTS_RELEASE) }[f] class NamedStringIO(StringIO): name = "" def depsOpen(fn, mode): dot.name = fn return dot dot = NamedStringIO() mockExecute.side_effect = lambda cmd: True mockDepsOpen.side_effect = depsOpen args = Namespace(workDir="/work", configDir="/dist", debug=False, docker=False, preferSystem=[], noSystem=True, architecture="slc7_x86-64", disable=[], neat=True, outdot="/tmp/out.dot", outgraph="/tmp/outgraph.pdf", package="AliRoot", defaults="release") doDeps(args, MagicMock()) # Same check without explicit intermediate dotfile args.outdot = None doDeps(args, MagicMock())
Example #17
Source File: test.py From harmony-ops with MIT License | 5 votes |
def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(description='Wrapper python script to test API using newman.') parser.add_argument("--test_dir", dest="test_dir", default="./tests/default", help="Path to test directory. Default is './tests/default'", type=str) parser.add_argument("--iterations", dest="iterations", default=5, help="Number of attempts for a successful test. Default is 5.", type=int) parser.add_argument("--start_epoch", dest="start_epoch", default=1, help="The minimum epoch before starting tests. Default is 1.", type=int) parser.add_argument("--rpc_endpoint_src", dest="hmy_endpoint_src", default="https://api.s0.b.hmny.io/", help="Source endpoint for Cx. Default is https://api.s0.b.hmny.io/", type=str) parser.add_argument("--rpc_endpoint_dst", dest="hmy_endpoint_dst", default="https://api.s1.b.hmny.io/", help="Destination endpoint for Cx. Default is https://api.s1.b.hmny.io/", type=str) parser.add_argument("--src_shard", dest="src_shard", default=None, type=str, help=f"The source shard of the Cx. Default assumes associated shard from src endpoint.") parser.add_argument("--dst_shard", dest="dst_shard", default=None, type=str, help=f"The destination shard of the Cx. Default assumes associated shard from dst endpoint.") parser.add_argument("--exp_endpoint", dest="hmy_exp_endpoint", default="http://e0.b.hmny.io:5000/", help="Default is http://e0.b.hmny.io:5000/", type=str) parser.add_argument("--delay", dest="txn_delay", default=45, help="The time to wait before checking if a Cx/Tx is on the blockchain. " "Default is 45 seconds. (Input is in seconds)", type=int) parser.add_argument("--chain_id", dest="chain_id", default="testnet", help="Chain ID for the CLI. Default is 'testnet'", type=str) parser.add_argument("--cli_path", dest="hmy_binary_path", default=None, help=f"ABSOLUTE PATH of CLI binary. " f"Default uses the CLI included in pyhmy module", type=str) parser.add_argument("--cli_passphrase", dest="passphrase", default='', help=f"Passphrase used to unlock the keystore. " f"Default is ''", type=str) parser.add_argument("--keystore", dest="keys_dir", default="TestnetValidatorKeys", help=f"Directory of keystore to import. Must follow the format of CLI's keystore. " f"Default is ./TestnetValidatorKeys", type=str) parser.add_argument("--ignore_regression_test", dest="ignore_regression_test", action='store_true', default=False, help="Disable the regression tests.") parser.add_argument("--ignore_staking_test", dest="ignore_staking_test", action='store_true', default=False, help="Disable the staking tests.") return parser.parse_args()
Example #18
Source File: test_falcon_plugin.py From py2swagger with MIT License | 5 votes |
def test_run_invalid_app(self): arguments = argparse.Namespace(app='falcon_app:invalid_app', config=None, output=None, plugin='falcon') self.assertRaises(Py2SwaggerPluginException, FalconPy2SwaggerPlugin().run, arguments)
Example #19
Source File: test_falcon_plugin.py From py2swagger with MIT License | 5 votes |
def test_run_invalid_module(self): arguments = argparse.Namespace(app='falcon_invalid_app:app', config=None, output=None, plugin='falcon') self.assertRaises(Py2SwaggerPluginException, FalconPy2SwaggerPlugin().run, arguments)
Example #20
Source File: test_falcon_plugin.py From py2swagger with MIT License | 5 votes |
def test_run(self): expected_result = { 'paths': { '/test': { 'get': {'summary': 'Handles GET requests'} }, '/test2/{id}': { 'get': { 'tags': ['test'], 'summary': 'Handles GET requests for another test', 'security': ['api_key'], 'responses': { '200': {'schema': {'type': 'string'}} } } } }, 'security_definitions': { 'api_key': { 'type': 'apiKey', 'in': 'Header', 'name': 'Authorization' } }, 'definitions': {} } arguments = argparse.Namespace(app='falcon_app:app', config=None, output=None, plugin='falcon') swagger_part = FalconPy2SwaggerPlugin().run(arguments) self.assertDictEqual(expected_result, unordered(swagger_part))
Example #21
Source File: test_components_prime.py From skelebot with MIT License | 5 votes |
def test_execute_exception(self, mock_docker): mock_docker.build.return_value = 0 mock_docker.save.return_value = 1 config = sb.objects.config.Config() args = argparse.Namespace(output="my-image.img") prime = sb.components.prime.Prime() try: prime.execute(config, args) self.fail("Exception Expected") except Exception as exc: self.assertEqual(str(exc), "Priming Failed") mock_docker.build.assert_called_with(config) mock_docker.save.assert_called_with(config, "my-image.img")
Example #22
Source File: test_components_prime.py From skelebot with MIT License | 5 votes |
def test_execute_output(self, mock_docker): mock_docker.build.return_value = 0 mock_docker.save.return_value = 0 config = sb.objects.config.Config() args = argparse.Namespace(output="my-image.img") prime = sb.components.prime.Prime() prime.execute(config, args) mock_docker.build.assert_called_with(config) mock_docker.save.assert_called_with(config, "my-image.img")
Example #23
Source File: test_components_bump.py From skelebot with MIT License | 5 votes |
def test_execute_major(self, mock_getcwd, mock_expanduser): mock_expanduser.return_value = "{path}/test/plugins".format(path=self.path) mock_getcwd.return_value = "{path}/test/files".format(path=self.path) config = sb.systems.generators.yaml.loadConfig() args = argparse.Namespace(version='major') bump = sb.components.bump.Bump() bump.execute(config, args) bumpVersion = sb.systems.generators.yaml.loadVersion() sb.systems.generators.yaml.saveVersion("6.6.6") self.assertEqual(bumpVersion, "7.0.0")
Example #24
Source File: test_components_prime.py From skelebot with MIT License | 5 votes |
def test_execute(self, mock_docker): mock_docker.build.return_value = 0 mock_docker.save.return_value = 0 config = sb.objects.config.Config() args = argparse.Namespace(output=None) prime = sb.components.prime.Prime() prime.execute(config, args) mock_docker.build.assert_called_with(config)
Example #25
Source File: test_components_registry.py From skelebot with MIT License | 5 votes |
def test_execute_tags(self, mock_docker): mock_docker.build.return_value = 0 config = sb.objects.config.Config(language="R") args = argparse.Namespace(tags=["test", "dev", "stage"]) registry = sb.components.registry.Registry(host="docker.io", port=88, user="skelebot") registry.execute(config, args) mock_docker.login.assert_called_with("docker.io") mock_docker.build.assert_called_with(config) mock_docker.push.assert_called_with(config, "docker.io", 88, "skelebot", tags=['test', 'dev', 'stage'])
Example #26
Source File: test_components_bump.py From skelebot with MIT License | 5 votes |
def test_execute_minor(self, mock_getcwd, mock_expanduser): mock_expanduser.return_value = "{path}/test/plugins".format(path=self.path) mock_getcwd.return_value = "{path}/test/files".format(path=self.path) config = sb.systems.generators.yaml.loadConfig() args = argparse.Namespace(version='minor') bump = sb.components.bump.Bump() bump.execute(config, args) bumpVersion = sb.systems.generators.yaml.loadVersion() sb.systems.generators.yaml.saveVersion("6.6.6") self.assertEqual(bumpVersion, "6.7.0")
Example #27
Source File: test_components_registry.py From skelebot with MIT License | 5 votes |
def test_execute(self, mock_docker): mock_docker.build.return_value = 0 config = sb.objects.config.Config(language="R") args = argparse.Namespace(tags=None) registry = sb.components.registry.Registry(host="docker.io", port=88, user="skelebot") registry.execute(config, args) mock_docker.login.assert_called_with("docker.io") mock_docker.build.assert_called_with(config) mock_docker.push.assert_called_with(config, "docker.io", 88, "skelebot", tags=None)
Example #28
Source File: test_components_dexec.py From skelebot with MIT License | 5 votes |
def test_execute_map(self, mock_docker): config = sb.objects.config.Config(name="test-dexec") args = argparse.Namespace(map=True) dexec = sb.components.dexec.Dexec() dexec.execute(config, args) mock_docker.build.assert_called_with(config) mock_docker.run.assert_called_with(config, "/bin/bash", "it", [], ["."], "exec")
Example #29
Source File: test_components_bump.py From skelebot with MIT License | 5 votes |
def test_execute_patch(self, mock_getcwd, mock_expanduser): mock_expanduser.return_value = "{path}/test/plugins".format(path=self.path) mock_getcwd.return_value = "{path}/test/files".format(path=self.path) config = sb.systems.generators.yaml.loadConfig() args = argparse.Namespace(version='patch') bump = sb.components.bump.Bump() bump.execute(config, args) bumpVersion = sb.systems.generators.yaml.loadVersion() sb.systems.generators.yaml.saveVersion("6.6.6") self.assertEqual(bumpVersion, "6.6.7")
Example #30
Source File: test_components_dexec.py From skelebot with MIT License | 5 votes |
def test_execute_nomap(self, mock_docker): config = sb.objects.config.Config(name="test-dexec") args = argparse.Namespace(map=False) dexec = sb.components.dexec.Dexec() dexec.execute(config, args) mock_docker.build.assert_called_with(config) mock_docker.run.assert_called_with(config, "/bin/bash", "it", [], [], "exec")