Ejemplo n.º 1
0
    def test_default_data_with_cli_args(self):
        # pylint: disable=no-self-use,protected-access
        config = Configuration({})
        cli_args = self.cli_args_sentinals()
        merged_data = copy.deepcopy(config.data)
        config._merge_cli_args(merged_data, cli_args)

        # `cli_args_sentinals` instead of `cli_args` just for in case
        # `cli_args` was tampered with.
        cli_args_sentinals = self.cli_args_sentinals()
        assert merged_data['virtualenv']['python'] \
            == cli_args_sentinals['python']
        assert merged_data['virtualenv']['path'] \
            == cli_args_sentinals['virtualenv_dir']
        assert merged_data['virtualenv']['keep'] \
            == cli_args_sentinals['keep_virtualenv']
        assert merged_data['virtualenv']['pip']['requirements'] \
            == cli_args_sentinals['requirements']
        assert merged_data['virtualenv']['pip']['packages'] \
            == cli_args_sentinals['packages']
        assert merged_data['packager']['target'] \
            == cli_args_sentinals['output']
        assert merged_data['packager']['build_path'] \
            == cli_args_sentinals['archive_dir']
        assert merged_data['packager']['keep'] \
            == cli_args_sentinals['keep_archive']
        assert merged_data['packager']['followlinks'] \
            == cli_args_sentinals['followlinks']
        assert merged_data['packager']['includes'] \
            == cli_args_sentinals['includes']
        assert merged_data['packager']['excludes'] \
            == cli_args_sentinals['excludes']
Ejemplo n.º 2
0
 def test_bad_data(self, left, right, expected):
     # pylint: disable=no-self-use,protected-access
     config = Configuration({})
     with pytest.raises(ValueError) as info:
         config._merge_dicts(left, right)
     assert str(info.value) == \
         'Conflict at : {}'.format(expected)
Ejemplo n.º 3
0
    def test_nothing_found(self, load_file_mock, source_fs):
        # pylint: disable=no-self-use,protected-access,unused-argument
        load_file_mock.return_value = {}
        os.chdir('/home')
        config = Configuration({})

        path = config._find_config_file(None)
        assert path is None
Ejemplo n.º 4
0
    def test_returns_config_in_cwd(self, load_file_mock, source_fs):
        # pylint: disable=no-self-use,protected-access,unused-argument
        load_file_mock.return_value = {}
        os.chdir('/home/foo/src/bar-project')
        config = Configuration({})

        path = config._find_config_file(None)
        assert path == '/home/foo/src/bar-project/py-lambda-packer.yaml'
Ejemplo n.º 5
0
    def test_no_changes(self):
        # pylint: disable=no-self-use,protected-access
        config = Configuration({})
        default_data_ori = copy.deepcopy(config.data)
        default_data_in = copy.deepcopy(config.data)

        config._merge_cli_args(default_data_in, {})
        assert default_data_in == default_data_ori
Ejemplo n.º 6
0
    def test_everything_missing(self, merge_dicts_mock, merge_cli_args_mock):
        # pylint: disable=no-self-use,protected-access
        merge_cli_args_mock.return_value = sentinel.merge_cli_args

        config = Configuration({})
        config._merge(sentinel.work_data, None, None)

        merge_dicts_mock.assert_not_called()
        merge_cli_args_mock.assert_not_called()
Ejemplo n.º 7
0
    def test_calls_expand_path_on_valid(self, expand_path_mock):
        # pylint: disable=no-self-use,protected-access
        expand_path_mock.return_value = sentinel.expanded_path
        config = Configuration({})

        path = config._find_config_file(sentinel.config_file_path)

        assert path == sentinel.expanded_path
        expand_path_mock.assert_called_with(sentinel.config_file_path, True)
Ejemplo n.º 8
0
    def test_everything_provided(self, merge_dicts_mock, merge_cli_args_mock):
        # pylint: disable=no-self-use,protected-access
        merge_dicts_mock.return_value = sentinel.merge_dicts
        merge_cli_args_mock.return_value = sentinel.merge_cli_args

        config = Configuration({})
        config._merge(sentinel.work_data, sentinel.file_data,
                      sentinel.cli_args)

        merge_dicts_mock.assert_called_with(sentinel.work_data,
                                            sentinel.file_data)
        merge_cli_args_mock.assert_called_with(sentinel.work_data,
                                               sentinel.cli_args)
Ejemplo n.º 9
0
 def test_default_values(self):
     # pylint: disable=no-self-use
     config = Configuration({})
     assert config.data['virtualenv']['python'] == 'python2.7'
     assert config.data['virtualenv']['path'] is None
     assert not config.data['virtualenv']['keep']
     assert config.data['virtualenv']['pip']['requirements'] == []
     assert config.data['virtualenv']['pip']['packages'] == []
     assert config.data['virtualenv']['default_excludes'] == [
         'easy_install.*',
         'pip*/**',
         'py-lambda-packer.yaml',
         'setuptools*/**',
         'wheel*/**']
     assert config.data['packager']['target'] == 'py-lambda-package.zip'
     assert config.data['packager']['build_path'] is None
     assert not config.data['packager']['keep']
     assert not config.data['packager']['followlinks']
     assert config.data['packager']['includes'] == []
     assert config.data['packager']['excludes'] == []
     assert config.data['packager']['default_excludes'] == [
         '**/*~',
         '**/*.swp',
         '**/.*.swp',
         '**/.DS_Store',
         '**/.DS_Store?',
         '**/._*',
         '**/.Spotlight-V100',
         '**/.Trashes',
         '**/Icon?',
         '**/ehthumbs.db',
         '**/Thumbs.db']
Ejemplo n.º 10
0
def entry_point():
    # Only here to be quiet and dump out the config.  Have to do this before
    # activating logging.
    if '--generate-config' in sys.argv[1:]:
        Configuration.print_default_config()
        sys.exit(0)

    # General configuration
    setup_logging()
    cli_args = parse_args(sys.argv[1:])
    config = Configuration(vars(cli_args))
    cwd = os.getcwd()

    # Information for the VirtualEnv
    pip_requirements = config.data['virtualenv']['pip']['requirements']
    fileset_excludes = config.data['virtualenv']['default_excludes']

    # Information for the PyLambdaPacker
    filesets = []
    if config.data['packager']['includes']:
        filesets = [
            FileSet(cwd,
                    includes=config.data['packager']['includes'],
                    excludes=config.data['packager']['excludes'] +
                    config.data['packager']['default_excludes'])
        ]

    # Build!
    with VirtualEnv(python=config.data['virtualenv']['python'],
                    path=config.data['virtualenv']['path'],
                    keep=config.data['virtualenv']['keep'],
                    packages=config.data['virtualenv']['pip']['packages'],
                    requirements=pip_requirements,
                    fileset_excludes=fileset_excludes) as virtual_env, \
            Packager(
                zip_file=config.data['packager']['target'],
                build_path=config.data['packager']['build_path'],
                keep=config.data['packager']['keep']) as packager:

        packer = PyLambdaPacker(virtual_env, packager, filesets)
        packer.build()
Ejemplo n.º 11
0
 def test_validate_schema(self):
     # pylint: disable=no-self-use
     # Poor version of scheme validation.
     config = Configuration({})
     assert sorted(config.data.keys()) == ['packager', 'virtualenv']
     assert sorted(config.data['packager'].keys()) == [
         'build_path', 'default_excludes', 'excludes', 'followlinks',
         'includes', 'keep', 'target']
     assert sorted(config.data['virtualenv'].keys()) == [
         'default_excludes', 'keep', 'path', 'pip', 'python']
     assert sorted(config.data['virtualenv']['pip'].keys()) == [
         'packages', 'requirements']
Ejemplo n.º 12
0
    def test_default_call_flow(self, merge_mock, find_mock, load_mock):
        # pylint: disable=no-self-use
        cli_args = {'cli_args': '92VzQ'}
        find_mock.return_value = sentinel.conf_path
        load_mock.side_effect = (sentinel.work_data, sentinel.file_data)

        config = Configuration(cli_args)

        assert config.cli_args == cli_args
        assert config.defaults_file_path.endswith(
            'plpacker/conf/DEFAULT_CONFIG.yaml')
        assert config.config_file_path == sentinel.conf_path
        assert config.data == sentinel.work_data

        merge_mock.assert_called_with(sentinel.work_data,
                                      sentinel.file_data,
                                      cli_args)
Ejemplo n.º 13
0
 def test_calls_injector_map(self, map_mock):
     # pylint: disable=protected-access
     config = Configuration({})
     cli_args = self.cli_args_sentinals()
     config._merge_cli_args({}, cli_args)
     assert map_mock.call_count == 11
Ejemplo n.º 14
0
 def test_utilizes_injector(self, injector):
     # pylint: disable=no-self-use,protected-access
     config = Configuration({})
     config._merge_cli_args(sentinel.data, sentinel.args)
     injector.assert_called_with(sentinel.data, sentinel.args)
Ejemplo n.º 15
0
 def test_empty_stays_empty(self):
     # pylint: disable=no-self-use,protected-access
     config = Configuration({})
     data_in = {}
     config._merge_cli_args({}, {})
     assert data_in == {}
Ejemplo n.º 16
0
 def test_good_data(self, left, right, expected):
     # pylint: disable=no-self-use,protected-access
     config = Configuration({})
     config._merge_dicts(left, right)
     assert left == expected