Beispiel #1
0
 def test_listing_dir_recusively_with_error(self, reporter):
     test_dir = "/tmp/copy-a-directory"
     list(
         handle_template(
             "copier-directory-does-not-exist/**", test_dir, self.base_dir
         )
     )
     eq_(reporter.call_count, 1)
Beispiel #2
0
 def test_file_not_found(self, reporter):
     list(
         handle_template(
             "copier-test-not-found.csv", "/tmp/test", self.base_dir
         )
     )
     reporter.assert_called_with(
         "copier-test-not-found.csv cannot be found"
     )
Beispiel #3
0
def _handle_implicit_target(options, template_file, output):
    common_data_file = options[constants.LABEL_CONFIG]
    default_template_type = options[constants.LABEL_TEMPLATE_TYPE]
    for src, dest, t_type in handle_template(
            template_file, output, options[constants.LABEL_TMPL_DIRS]):
        if t_type:
            yield TemplateTarget(src, common_data_file, dest, t_type)
        else:
            yield TemplateTarget(src, common_data_file, dest,
                                 default_template_type)
Beispiel #4
0
def _handle_group_target(options, a_list_short_hand_targets,
                         group_template_type):
    # grouping by template type feature
    common_data_file = options[constants.LABEL_CONFIG]
    for _output, _template_file in _iterate_list_of_dicts(
            a_list_short_hand_targets):
        for src, dest, t_type in handle_template(
                _template_file, _output, options[constants.LABEL_TMPL_DIRS]):
            yield TemplateTarget(src, common_data_file, dest,
                                 group_template_type)
Beispiel #5
0
 def test_listing_dir(self):
     test_dir = "/tmp/copy-a-directory"
     results = list(
         handle_template("copier-directory", test_dir, self.base_dir))
     expected = [(
         "copier-directory/level1-file1",
         "/tmp/copy-a-directory/level1-file1",
         None,
     )]
     eq_(expected, results)
Beispiel #6
0
 def test_listing_dir_recusively(self):
     test_dir = "/tmp/copy-a-directory"
     results = list(
         handle_template("copier-directory/**", test_dir, self.base_dir))
     expected = [
         (
             "copier-directory/copier-sample-dir/file1",
             "/tmp/copy-a-directory/copier-sample-dir/file1",
             None,
         ),
         (
             "copier-directory/level1-file1",
             "/tmp/copy-a-directory/level1-file1",
             None,
         ),
     ]
     eq_(expected, results)
Beispiel #7
0
def _handle_explicit_target(options, target):
    common_data_file = options[constants.LABEL_CONFIG]
    default_template_type = options[constants.LABEL_TEMPLATE_TYPE]
    template_file = target.get(constants.LABEL_TEMPLATE,
                               options.get(constants.LABEL_TEMPLATE, None))
    data_file = target.get(constants.LABEL_CONFIG, common_data_file)
    output = target[constants.LABEL_OUTPUT]
    template_type = target.get(constants.LABEL_TEMPLATE_TYPE)
    for src, dest, t_type in handle_template(
            template_file, output, options[constants.LABEL_TMPL_DIRS]):
        if template_type:
            yield TemplateTarget(src, data_file, dest, template_type)
        else:
            if t_type:
                yield TemplateTarget(src, data_file, dest, t_type)
            else:
                yield TemplateTarget(src, data_file, dest,
                                     default_template_type)
Beispiel #8
0
 def test_listing_dir_recusively(self):
     test_dir = "/tmp/copy-a-directory"
     results = list(
         handle_template("copier-directory/**", test_dir, self.base_dir)
     )
     expected = [
         (
             os.path.join("copier-directory", "copier-sample-dir", "file1"),
             os.path.join(
                 "/tmp/copy-a-directory", "copier-sample-dir", "file1"
             ),
             None,
         ),
         (
             os.path.join("copier-directory", "level1-file1"),
             os.path.join("/tmp/copy-a-directory", "level1-file1"),
             None,
         ),
     ]
     eq_(
         sorted(expected, key=lambda x: x[0]),
         sorted(results, key=lambda x: x[0]),
     )
Beispiel #9
0
def _handle_explicit_target(options, target):
    common_data_file = options[constants.LABEL_CONFIG]
    default_template_type = options[constants.LABEL_TEMPLATE_TYPE]
    template_file = target.get(constants.LABEL_TEMPLATE,
                               options.get(constants.LABEL_TEMPLATE, None))
    data_file = target.get(constants.LABEL_CONFIG, common_data_file)
    output = target[constants.LABEL_OUTPUT]
    template_type = target.get(constants.LABEL_TEMPLATE_TYPE)
    if template_type and len(template_type) > 0:
        if constants.TEMPLATE_TYPES_FILE_EXTENSIONS in template_type:
            reporter.report_file_extension_not_needed()
        if constants.TEMPLATE_TYPES_BASE_TYPE in template_type:
            adhoc_type = uuid.uuid4().hex
            file_extension = uuid.uuid4().hex
            base_type = template_type[constants.TEMPLATE_TYPES_BASE_TYPE]
            template_types_options = template_type[
                constants.TEMPLATE_TYPES_OPTIONS]
            the_adhoc_type = {
                adhoc_type: {
                    constants.TEMPLATE_TYPES_FILE_EXTENSIONS: [file_extension],
                    constants.TEMPLATE_TYPES_BASE_TYPE: base_type,
                    constants.TEMPLATE_TYPES_OPTIONS: template_types_options,
                }
            }
            plugins.ENGINES.register_options(the_adhoc_type)
            template_type = file_extension
    for src, dest, t_type in handle_template(
            template_file, output, options[constants.LABEL_TMPL_DIRS]):
        if template_type:
            yield TemplateTarget(src, data_file, dest, template_type)
        else:
            if t_type:
                yield TemplateTarget(src, data_file, dest, t_type)
            else:
                yield TemplateTarget(src, data_file, dest,
                                     default_template_type)
Beispiel #10
0
 def test_copy_files(self):
     results = list(
         handle_template("copier-test01.csv", "/tmp/test", self.base_dir))
     expected = [("copier-test01.csv", "/tmp/test", "csv")]
     eq_(expected, results)