Python argparse.Namespace() Examples

The following are code examples for showing how to use argparse.Namespace(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: mutatest   Author: EvanKepner   File: cli.py    MIT License 6 votes vote down vote up
def cli_args(
    args: Sequence[str], ini_config_file: Path = Path("mutatest.ini")
) -> argparse.Namespace:
    """Command line arguments as parsed args.

    If a INI configuration file is set it is used to set additional default arguments, but
    the CLI arguments override any INI file settings.

    Args:
        args: the argument sequence from the command line
        ini_config_file: the ini config file for the default settings

    Returns:
        Parsed args from ArgumentParser
    """
    parser = cli_parser()

    if ini_config_file.exists():
        ini_config = read_ini_config(ini_config_file)
        ini_cli_args = parse_ini_config_with_cli(parser, ini_config, args)
        return parser.parse_args(ini_cli_args)

    return parser.parse_args(args) 
Example 2
Project: pyblish-win   Author: pyblish   File: test_argparse.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_get_default(self):
        parser = ErrorRaisingArgumentParser()
        self.assertEqual(None, parser.get_default("foo"))
        self.assertEqual(None, parser.get_default("bar"))

        parser.add_argument("--foo")
        self.assertEqual(None, parser.get_default("foo"))
        self.assertEqual(None, parser.get_default("bar"))

        parser.add_argument("--bar", type=int, default=42)
        self.assertEqual(None, parser.get_default("foo"))
        self.assertEqual(42, parser.get_default("bar"))

        parser.set_defaults(foo="badger")
        self.assertEqual("badger", parser.get_default("foo"))
        self.assertEqual(42, parser.get_default("bar"))

# ==========================
# Namespace 'contains' tests
# ========================== 
Example 3
Project: fireprox   Author: ustayready   File: fire.py    GNU General Public License v3.0 6 votes vote down vote up
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 4
Project: fireprox   Author: ustayready   File: fire.py    GNU General Public License v3.0 6 votes vote down vote up
def parse_arguments() -> Tuple[argparse.Namespace, str]:
    """Parse command line arguments and return namespace

    :return: Namespace for arguments and help text as a tuple
    """
    parser = argparse.ArgumentParser(description='FireProx API Gateway Manager')
    parser.add_argument('--profile_name',
                        help='AWS Profile Name to store/retrieve credentials', type=str, default=None)
    parser.add_argument('--access_key',
                        help='AWS Access Key', type=str, default=None)
    parser.add_argument('--secret_access_key',
                        help='AWS Secret Access Key', type=str, default=None)
    parser.add_argument('--session_token',
                        help='AWS Session Token', type=str, default=None)
    parser.add_argument('--region',
                        help='AWS Region', type=str, default=None)
    parser.add_argument('--command',
                        help='Commands: list, create, delete, update', type=str, default=None)
    parser.add_argument('--api_id',
                        help='API ID', type=str, required=False)
    parser.add_argument('--url',
                        help='URL end-point', type=str, required=False)
    return parser.parse_args(), parser.format_help() 
Example 5
Project: skelebot   Author: carsdotcom   File: test_systems_execution_commandBuilder.py    MIT License 6 votes vote down vote up
def test_build_kabob_params(self, mock_getcwd, mock_expanduser):
        folderPath = "{path}/test/files".format(path=self.path)
        args = Namespace(version='0.1', test_test="test", 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")
        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 test --log info"
        command = sb.systems.execution.commandBuilder.build(config, job, args)
        self.assertEqual(command, expected) 
Example 6
Project: skelebot   Author: carsdotcom   File: test_components_plugin.py    MIT License 6 votes vote down vote up
def test_execute(self, mock_zipfile, mock_makedirs, mock_exists, mock_expanduser):
        mock_expanduser.return_value = "test/dummy"
        mock_exists.return_value = False

        mock_zip = mock.MagicMock()
        mock_zipfile.ZipFile.return_value = mock_zip
        config = sb.objects.config.Config()
        args = argparse.Namespace(plugin="test.zip")

        plugin = sb.components.plugin.Plugin()
        plugin.execute(config, args)

        mock_zipfile.ZipFile.assert_called_with("test.zip", "r")
        mock_zip.extractall.assert_called()
        mock_zip.close.assert_called()

        mock_makedirs.assert_any_call("test/dummy", exist_ok=True) 
Example 7
Project: skelebot   Author: carsdotcom   File: test_systems_execution_docker.py    MIT License 6 votes vote down vote up
def test_run(self, mock_getcwd, mock_system, mock_expanduser):
        folderPath = "{path}/test/files".format(path=self.path)
        args = Namespace(version='0.1')

        homePath = "{path}/test/plugins".format(path=self.path)
        mock_expanduser.return_value = homePath
        mock_getcwd.return_value = folderPath
        mock_system.return_value = 0

        config = sb.systems.generators.yaml.loadConfig()
        config.ports = ["1127:1127"]
        job = config.jobs[0]
        job.mappings = ["data/", "/test/output/:/app/output/", "~/temp/:/app/temp/"]
        command = sb.systems.execution.commandBuilder.build(config, job, args)

        expected = "docker run --name test-build --rm -i -p 1127:1127 -v {cwd}/data/:/app/data/ -v /test/output/:/app/output/ -v {path}/temp/:/app/temp/ test /bin/bash -c \"bash build.sh 0.1 --env local --log info\"".format(cwd=folderPath, path=homePath)
        sb.systems.execution.docker.run(config, command, job.mode, config.ports, job.mappings, job.name)
        mock_system.assert_called_once_with(expected) 
Example 8
Project: skelebot   Author: carsdotcom   File: test_systems_execution_docker.py    MIT License 6 votes vote down vote up
def test_run_docker_params(self, mock_getcwd, mock_system, 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_system.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_system.assert_called_once_with(expected) 
Example 9
Project: crits_api_scripts   Author: puhley   File: os_list_update.py    MIT License 6 votes vote down vote up
def get_crits_config(Config,args,debug):
  """
  Retrieve the CRITs connection info from the config file and/or command line.
  Returns the username, API key and URL

  :param Config: The ConfigParser varialbe for the file containing the variable.
  :type Config: ConfigParser
  :param args: The section of the config file that contains the variable
  :type args: :class:`argparse.Namespace`
  :param debug: A boolean indicating whether the debug flag is set.
  :type debug: boolean
  :returns: str, str, str
  """
  username = get_config_setting(Config,"CritsCreds","username")
  api_key = get_config_setting(Config,"CritsCreds","API_key")
  crits_url = get_config_setting(Config,"CritsCreds","CRITs_URL")

  if args.username:
     username = args.username
  if args.api_key:
     api_key = args.api_key
  if args.crits_url:
     crits_url = args.crits_url
   
  return username,api_key,crits_url 
Example 10
Project: crits_api_scripts   Author: puhley   File: os_list_update.py    MIT License 6 votes vote down vote up
def get_campaign(Config,args,debug):
  """
  Retrieve the campaign setting from the config file and/or command line.
  Return the string containing the campaign name

  :param Config: The ConfigParser variable for the file containing the variable.
  :type Config: ConfigParser
  :param args: The section of the config file that contains the variable
  :type args: :class:`argparse.Namespace`
  :param debug: A boolean indicating whether the debug flag is set.
  :type debug: boolean
  :returns: str
  """
  campaign = get_config_setting(Config,"DefaultIndicatorInfo","campaign_name")

  if args.campaign:
    campaign = args.campaign

  if campaign == None:
    return("")

  return (campaign) 
Example 11
Project: crits_api_scripts   Author: puhley   File: os_list_update.py    MIT License 6 votes vote down vote up
def get_source(Config,args,debug):
  """
  Retrieve the source setting from the config file and/or command line.
  Return a string specifying the source name.

  :param Config: The ConfigParser variable for the file containing the variable.
  :type Config: ConfigParser
  :param args: The section of the config file that contains the variable
  :type args: :class:`argparse.Namespace`
  :param debug: A boolean indicating whether the debug flag is set.
  :type debug: boolean
  :returns: str
  """
  source = get_config_setting(Config,"DefaultIndicatorInfo","source")

  if args.source:
    source = args.source

  if source == None:
    return("")

  return (source) 
Example 12
Project: gcp-variant-transforms   Author: googlegenomics   File: pipeline_common.py    Apache License 2.0 6 votes vote down vote up
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 13
Project: pyblish-win   Author: pyblish   File: test_argparse.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_empty(self):
        ns = argparse.Namespace()
        self.assertEqual('' in ns, False)
        self.assertEqual('' not in ns, True)
        self.assertEqual('x' in ns, False) 
Example 14
Project: pyblish-win   Author: pyblish   File: test_argparse.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_non_empty(self):
        ns = argparse.Namespace(x=1, y=2)
        self.assertEqual('x' in ns, True)
        self.assertEqual('x' not in ns, False)
        self.assertEqual('y' in ns, True)
        self.assertEqual('' in ns, False)
        self.assertEqual('xx' in ns, False)
        self.assertEqual('z' in ns, False)

# =====================
# Help formatting tests
# ===================== 
Example 15
Project: pyblish-win   Author: pyblish   File: test_argparse.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_namespace(self):
        ns = argparse.Namespace(foo=42, bar='spam')
        string = "Namespace(bar='spam', foo=42)"
        self.assertStringEqual(ns, string) 
Example 16
Project: pyblish-win   Author: pyblish   File: test_argparse.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_parser(self):
        parser = argparse.ArgumentParser(prog='PROG')
        string = (
            "ArgumentParser(prog='PROG', usage=None, description=None, "
            "version=None, formatter_class=%r, conflict_handler='error', "
            "add_help=True)" % argparse.HelpFormatter)
        self.assertStringEqual(parser, string)

# ===============
# Namespace tests
# =============== 
Example 17
Project: pyblish-win   Author: pyblish   File: test_argparse.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_equality(self):
        ns1 = argparse.Namespace(a=1, b=2)
        ns2 = argparse.Namespace(b=2, a=1)
        ns3 = argparse.Namespace(a=1)
        ns4 = argparse.Namespace(b=2)

        self.assertEqual(ns1, ns2)
        self.assertNotEqual(ns1, ns3)
        self.assertNotEqual(ns1, ns4)
        self.assertNotEqual(ns2, ns3)
        self.assertNotEqual(ns2, ns4)
        self.assertTrue(ns1 != ns3)
        self.assertTrue(ns1 != ns4)
        self.assertTrue(ns2 != ns3)
        self.assertTrue(ns2 != ns4) 
Example 18
Project: pyblish-win   Author: pyblish   File: test_argparse.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_equality_returns_notimplemeted(self):
        # See issue 21481
        ns = argparse.Namespace(a=1, b=2)
        self.assertIs(ns.__eq__(None), NotImplemented)
        self.assertIs(ns.__ne__(None), NotImplemented)


# ===================
# File encoding tests
# =================== 
Example 19
Project: kvmd   Author: pikvm   File: __init__.py    GNU General Public License v3.0 5 votes vote down vote up
def _cmd_list(config: Section, _: argparse.Namespace) -> None:
    for user in sorted(passlib.apache.HtpasswdFile(_get_htpasswd_path(config)).users()):
        print(user) 
Example 20
Project: kvmd   Author: pikvm   File: __init__.py    GNU General Public License v3.0 5 votes vote down vote up
def _cmd_set(config: Section, options: argparse.Namespace) -> None:
    with _get_htpasswd_for_write(config) as htpasswd:
        if options.read_stdin:
            passwd = valid_passwd(input())
        else:
            passwd = valid_passwd(getpass.getpass("Password: ", stream=sys.stderr))
            if valid_passwd(getpass.getpass("Repeat: ", stream=sys.stderr)) != passwd:
                raise SystemExit("Sorry, passwords do not match")
        htpasswd.set_password(options.user, passwd) 
Example 21
Project: kvmd   Author: pikvm   File: __init__.py    GNU General Public License v3.0 5 votes vote down vote up
def _cmd_delete(config: Section, options: argparse.Namespace) -> None:
    with _get_htpasswd_for_write(config) as htpasswd:
        htpasswd.delete(options.user)


# ===== 
Example 22
Project: slidoc   Author: mitotic   File: md2md.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def create_args(self, *args, **kwargs):
        """Returns a argparse.Namespace object with argument values, optionally initialized from object args[0] (if not None) and updated with kwargs"""
        if args and args[0] is not None:
            arg_vals = dict( [(k, getattr(args[0], k)) for k in self.str_args+self.bool_args+self.int_args] )
        else:
            arg_vals = dict( [(k, '') for k in self.str_args] + [(k, False) for k in self.bool_args] + [(k, 0) for k in self.int_args] )
            arg_vals.update(self.defaults)
        arg_vals.update(kwargs)

        return argparse.Namespace(**arg_vals) 
Example 23
Project: utilities   Author: czbiohub   File: bcl2fastq.py    MIT License 5 votes vote down vote up
def get_default_requirements():
    return argparse.Namespace(
        vcpus=64,
        memory=256000,
        storage=5000,
        queue="aegea_batch_demux",
        ecr_image="demuxer",
        ulimits=["nofile:1000000"],
    ) 
Example 24
Project: utilities   Author: czbiohub   File: 10x_mkfastq.py    MIT License 5 votes vote down vote up
def get_default_requirements():
    return argparse.Namespace(
        vcpus=64,
        memory=256000,
        storage=2000,
        queue="aegea_batch_demux",
        ecr_image="demuxer",
        ulimits=["nofile:1000000"],
    ) 
Example 25
Project: utilities   Author: czbiohub   File: template.py    MIT License 5 votes vote down vote up
def get_default_requirements():
    """
    Optional: Define the default hardware requirements for this job
    """
    return argparse.Namespace(vcpus=4, memory=8000, storage=500) 
Example 26
Project: utilities   Author: czbiohub   File: 10x_count.py    MIT License 5 votes vote down vote up
def get_default_requirements():
    return argparse.Namespace(
        vcpus=64, memory=256000, storage=2000, ecr_image="demuxer"
    ) 
Example 27
Project: utilities   Author: czbiohub   File: run_star_and_htseq.py    MIT License 5 votes vote down vote up
def get_default_requirements():
    return argparse.Namespace(vcpus=16, memory=64000, storage=500, ecr_image="aligner") 
Example 28
Project: ticket_universe   Author: lotify   File: cli_test.py    MIT License 5 votes vote down vote up
def test_limiting_output(self):
        args = Namespace(positions=["binary", "binary", "binary"], limit=4, offset=0)
        with capture(cli.main, args) as output:
            self.assertEqual(4, output.count('\n')) 
Example 29
Project: ticket_universe   Author: lotify   File: cli_test.py    MIT License 5 votes vote down vote up
def test_offsetting_output(self):
        args = Namespace(positions=["binary", "binary", "binary"], limit=None, offset=4)
        with capture(cli.main, args) as output:
            self.assertEqual(4, output.count('\n')) 
Example 30
Project: ticket_universe   Author: lotify   File: cli_test.py    MIT License 5 votes vote down vote up
def test_calling_main_with_args_prints_universe(self):
        args = Namespace(positions=["binary"], limit=None, offset=0)
        with capture(cli.main, args) as output:
            self.assertEqual("0\n1\n", output) 
Example 31
Project: ticket_universe   Author: lotify   File: cli.py    MIT License 5 votes vote down vote up
def arguments(*args, **kwargs) -> argparse.Namespace:
    parser = argument_parser()
    args = parser.parse_args(*args, **kwargs)
    return args 
Example 32
Project: ticket_universe   Author: lotify   File: cli.py    MIT License 5 votes vote down vote up
def main(args: argparse.Namespace = None):
    _arguments = args or arguments()
    _universe = universe_from_args(_arguments)

    if len(_universe) == 0:
        print_help()

    for t in _universe.generate(_arguments.limit, _arguments.offset):
        print(t) 
Example 33
Project: ncssl_api_client   Author: antonku   File: test_invoker.py    MIT License 5 votes vote down vote up
def test_executes_command(self, command_map_mock, api_client_mock, config_manager_mock):

        mock.MagicMock.execute = lambda x: 'executed'
        arguments_mock = argparse.Namespace(command='mock_command', sandbox=True)
        invoker = Invoker(arguments_mock)
        result = invoker.run()
        self.assertEqual(result, 'executed') 
Example 34
Project: ncssl_api_client   Author: antonku   File: test_invoker.py    MIT License 5 votes vote down vote up
def test_uses_api_sandbox_client_config(self, command_map_mock, api_client_mock, config_manager_mock):

        mock.MagicMock.execute = lambda x: 'executed'
        arguments_mock = argparse.Namespace(command='mock_command', sandbox=True)
        invoker = Invoker(arguments_mock)
        invoker.run()
        config_manager_mock.get_api_sandbox_client_config.assert_called_once() 
Example 35
Project: ncssl_api_client   Author: antonku   File: test_invoker.py    MIT License 5 votes vote down vote up
def test_uses_api_production_client_config(self, command_map_mock, api_client_mock, config_manager_mock):

        mock.MagicMock.execute = lambda x: 'executed'
        arguments_mock = argparse.Namespace(command='mock_command', sandbox=False)
        invoker = Invoker(arguments_mock)
        invoker.run()
        config_manager_mock.get_api_production_client_config.assert_called_once() 
Example 36
Project: AshsSDK   Author: thehappydinoa   File: argparser.py    MIT License 5 votes vote down vote up
def parse_known_args(self, args, namespace=None):
        if len(args) == 1 and args[0] == 'help':
            namespace = argparse.Namespace()
            namespace.help = 'help'
            return namespace, []
        else:
            return super(ArgTableArgParser, self).parse_known_args(
                args, namespace) 
Example 37
Project: sumo   Author: ratan-lab   File: test_command_line.py    MIT License 5 votes vote down vote up
def test_parse_args(capsys):
    correct = [
        "./sumo.py prepare infile type outfile",
        "./sumo.py prepare infile1,infile2 type outfile",
        "./sumo.py prepare infile type1,type2 outfile",
        "./sumo.py run infile 2 outfile",
        "./sumo.py"
    ]

    for cmd in correct:
        args = command_line.parse_args(cmd.split()[1:])
        assert isinstance(args, Namespace)

    incorrect = [
        "./sumo.py prepare",
        "./sump.py prepare infile"
        "./sumo.py prepare infile outfile",
        "./sumo.py run",
        "./sumo.py run infile",
        "./sumo.py run infile 2",
        "./sumo.py run infile outfile",
        "./sumo.py run infile two outfile",
        "./sumo.py run infile 2.5 outfile",
        "./sumo.py not_a_command"
    ]

    for cmd in incorrect:
        with pytest.raises(SystemExit):
            command_line.parse_args(cmd.split()[1:])
        _ = capsys.readouterr()  # catch stdout 
Example 38
Project: skelebot   Author: carsdotcom   File: test_systems_execution_commandBuilder.py    MIT License 5 votes vote down vote up
def test_build(self, mock_getcwd, mock_expanduser):
        folderPath = "{path}/test/files".format(path=self.path)
        args = Namespace(version='0.1', test=True)

        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", "t", accepts="boolean")
        job.params.append(param)

        expected = "bash build.sh 0.1 --env local --test --log info"
        command = sb.systems.execution.commandBuilder.build(config, job, args)
        self.assertEqual(command, expected) 
Example 39
Project: skelebot   Author: carsdotcom   File: test_systems_execution_commandBuilder.py    MIT License 5 votes vote down vote up
def test_build_no_boolean(self, mock_getcwd, mock_expanduser):
        folderPath = "{path}/test/files".format(path=self.path)
        args = Namespace(version='1.1')

        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", "t", accepts="boolean")
        job.params.append(param)

        expected = "bash build.sh 1.1 --env local --log info"
        command = sb.systems.execution.commandBuilder.build(config, job, args)
        self.assertEqual(command, expected) 
Example 40
Project: skelebot   Author: carsdotcom   File: test_systems_execution_executor.py    MIT License 5 votes vote down vote up
def test_execute_version(self, mock_skeleParser, mock_print):
        config = sb.objects.config.Config()
        args = argparse.Namespace(job=None, version_global=True)
        mock_skeleParser.parseArgs.return_value = args

        sb.systems.execution.executor.execute(config, mock_skeleParser)

        mock_print.assert_called_with("Skelebot v6.6.6") 
Example 41
Project: skelebot   Author: carsdotcom   File: test_systems_execution_executor.py    MIT License 5 votes vote down vote up
def test_execute_contact(self, mock_skeleParser, mock_print):
        config = sb.objects.config.Config(contact="[email protected]")
        args = argparse.Namespace(job=None, contact_global=True)
        mock_skeleParser.parseArgs.return_value = args

        sb.systems.execution.executor.execute(config, mock_skeleParser)

        mock_print.assert_called_with("[email protected]") 
Example 42
Project: skelebot   Author: carsdotcom   File: test_systems_execution_executor.py    MIT License 5 votes vote down vote up
def test_execute_scaffold(self, mock_skeleParser, mock_scaffold):
        config = sb.objects.config.Config()
        args = argparse.Namespace(job="scaffold", existing=False)
        mock_skeleParser.parseArgs.return_value = args

        sb.systems.execution.executor.execute(config, mock_skeleParser)

        mock_scaffold.assert_called_once_with(False) 
Example 43
Project: skelebot   Author: carsdotcom   File: test_systems_execution_executor.py    MIT License 5 votes vote down vote up
def test_execute_job_skip(self, mock_skeleParser, mock_run):
        job = sb.objects.job.Job(name="test", source="test.py")
        config = sb.objects.config.Config(jobs=[job])
        args = argparse.Namespace(job="test", native_global=False, skip_build_global=True)
        mock_skeleParser.parseArgs.return_value = args

        sb.systems.execution.executor.execute(config, mock_skeleParser)

        mock_run.assert_called_once_with(config, "python -u test.py", "i", [], [], "test") 
Example 44
Project: skelebot   Author: carsdotcom   File: test_systems_execution_executor.py    MIT License 5 votes vote down vote up
def test_execute_job(self, mock_skeleParser, mock_run, mock_build):
        job = sb.objects.job.Job(name="test", source="test.py")
        config = sb.objects.config.Config(jobs=[job])
        args = argparse.Namespace(job="test", native_global=False, skip_build_global=False)
        mock_skeleParser.parseArgs.return_value = args

        sb.systems.execution.executor.execute(config, mock_skeleParser)

        mock_build.assert_called_once_with(config)
        mock_run.assert_called_once_with(config, "python -u test.py", "i", [], [], "test") 
Example 45
Project: skelebot   Author: carsdotcom   File: test_systems_execution_executor.py    MIT License 5 votes vote down vote up
def test_execute_job_native(self, mock_skeleParser, mock_system):
        job = sb.objects.job.Job(name="test", source="test.py")
        config = sb.objects.config.Config(jobs=[job])
        args = argparse.Namespace(job="test", native_global=True)
        mock_skeleParser.parseArgs.return_value = args

        sb.systems.execution.executor.execute(config, mock_skeleParser)

        mock_system.assert_called_once_with("python -u test.py") 
Example 46
Project: skelebot   Author: carsdotcom   File: test_systems_execution_executor.py    MIT License 5 votes vote down vote up
def test_execute_component(self, mock_skeleParser):
        mock_component = mock.MagicMock()
        mock_component.commands = ["test"]
        config = sb.objects.config.Config(components=[mock_component])
        args = argparse.Namespace(job="test")
        mock_skeleParser.parseArgs.return_value = args

        sb.systems.execution.executor.execute(config, mock_skeleParser)

        mock_component.execute.assert_called_once_with(config, args) 
Example 47
Project: skelebot   Author: carsdotcom   File: test_components_jupyter.py    MIT License 5 votes vote down vote up
def test_execute_R(self, mock_docker):
        mock_docker.build.return_value = 0
        config = sb.objects.config.Config(language="R")
        args = argparse.Namespace()

        jupyter = sb.components.jupyter.Jupyter(port=1127, folder="notebooks/")
        jupyter.execute(config, args)

        expectedCommand = "jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root --notebook-dir=notebooks/"

        mock_docker.build.assert_called_with(config)
        mock_docker.run.assert_called_with(config, expectedCommand, "i", ["1127:8888"], ".", "jupyter") 
Example 48
Project: skelebot   Author: carsdotcom   File: test_components_jupyter.py    MIT License 5 votes vote down vote up
def test_execute_Python(self, mock_docker):
        mock_docker.build.return_value = 0
        config = sb.objects.config.Config(language="Python")
        args = argparse.Namespace()

        jupyter = sb.components.jupyter.Jupyter(port=1127, folder="notebooks/")
        jupyter.execute(config, args)

        expectedCommand = "jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root --notebook-dir=notebooks/"

        mock_docker.build.assert_called_with(config)
        mock_docker.run.assert_called_with(config, expectedCommand, "i", ["1127:8888"], ".", "jupyter") 
Example 49
Project: skelebot   Author: carsdotcom   File: test_components_artifactory.py    MIT License 5 votes vote down vote up
def test_execute_push_conflict(self, mock_artifactory, mock_rename):
        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.artifactory.execute(config, args)
            self.fail("Exception Not Thrown")
        except Exception as exc:
            self.assertEqual(str(exc), expectedException)
            mock_artifactory.assert_called_with("artifactory.test.com/ml/test/test_v1.0.0.pkl", auth=('sean', 'abc123')) 
Example 50
Project: skelebot   Author: carsdotcom   File: test_components_artifactory.py    MIT License 5 votes vote down vote up
def test_execute_push_error(self, mock_artifactory, mock_remove, mock_copy):
        mock_path = mock.MagicMock()
        mock_path.deploy_file = mock.MagicMock(side_effect=KeyError('foo'))
        mock_artifactory.return_value = mock_path

        config = sb.objects.config.Config(version="1.0.0")
        args = argparse.Namespace(job="push", force=True, artifact='test', user='sean', token='abc123')

        with self.assertRaises(KeyError):
            self.artifactory.execute(config, args)

        mock_artifactory.assert_called_with("artifactory.test.com/ml/test/test_v1.0.0.pkl", auth=('sean', 'abc123'))
        mock_copy.assert_called_with("test.pkl", "test_v1.0.0.pkl")
        mock_remove.assert_called_with("test_v1.0.0.pkl")