Exemplo n.º 1
0
    def load(self):
        try:
            self.load_settings()
        except FileNotFoundError as e:
            self._raise_invalid_project(
                "Project file not found. Have you run 'init'?", e
            )

        if self.artifact_type == ARTIFACT_TYPE_MODULE:
            LOG.info("Validating your module fragments...")
            template_fragment = TemplateFragment(self.type_name)
            try:
                self._validate_fragments(template_fragment)
            except FragmentValidationError as e:
                msg = "Invalid template fragment: " + str(e)
                self._raise_invalid_project(msg, e)
            self.schema = template_fragment.generate_schema()
            self.fragment_dir = template_fragment.fragment_dir
        else:
            LOG.info("Validating your resource specification...")
            try:
                self.load_schema()
                LOG.warning("Resource schema is valid.")
            except FileNotFoundError as e:
                self._raise_invalid_project("Resource specification not found.", e)
            except SpecValidationError as e:
                msg = "Resource specification is invalid: " + str(e)
                self._raise_invalid_project(msg, e)
Exemplo n.º 2
0
def test_template_folder_with_multiple_fragment_files():
    template_fragment = TemplateFragment(
        type_name,
        os.path.join(directory, "../data/sample_fragments/test_multiple_files"),
    )
    with pytest.raises(FragmentValidationError) as validation_error:
        template_fragment.validate_fragments()
    assert "can only consist of a single template file" in str(validation_error.value)
Exemplo n.º 3
0
 def _load_modules_project(self):
     LOG.info("Validating your module fragments...")
     template_fragment = TemplateFragment(self.type_name, self.root)
     try:
         self._validate_fragments(template_fragment)
     except FragmentValidationError as e:
         msg = "Invalid template fragment: " + str(e)
         self._raise_invalid_project(msg, e)
     self.schema = template_fragment.generate_schema()
     self.fragment_dir = template_fragment.fragment_dir
Exemplo n.º 4
0
def init_module(args, project):
    if args.type_name:
        try:
            type_name = validate_type_name(args.type_name)
        except WizardValidationError as error:
            print_error(error)
            type_name = input_typename()
    else:
        type_name = input_typename()

    project.init_module(type_name)
    template_fragment = TemplateFragment(type_name)
    template_fragment.generate_sample_fragment()
Exemplo n.º 5
0
def test_merge_fragments_ignores_unrelated_files():
    template_fragment = TemplateFragment(
        type_name, os.path.join(directory, "../data/sample_fragments/")
    )
    template_fragment.validate_fragments()
Exemplo n.º 6
0
def template_fragment(tmpdir):
    return TemplateFragment(type_name, tmpdir)
Exemplo n.º 7
0
def template_fragment():
    return TemplateFragment(type_name, test_root)