示例#1
0
    def setUp(self):
        super().setUp()
        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        self.path = temp_cwd_fixture.path
        # Some tests will directly or indirectly change the plugindir, which
        # is a module variable. Make sure that it is returned to the original
        # value when a test ends.
        self.addCleanup(common.set_plugindir, common.get_plugindir())
        self.addCleanup(common.set_schemadir, common.get_schemadir())
        self.addCleanup(common.set_schemadir, common.get_schemadir())
        self.addCleanup(common.reset_env)
        common.set_schemadir(os.path.join(__file__,
                             '..', '..', '..', 'schema'))
        self.useFixture(fixtures.FakeLogger(level=logging.ERROR))

        patcher = mock.patch('multiprocessing.cpu_count')
        self.cpu_count = patcher.start()
        self.cpu_count.return_value = 2
        self.addCleanup(patcher.stop)

        # These are what we expect by default
        self.snap_dir = os.path.join(os.getcwd(), 'snap')
        self.stage_dir = os.path.join(os.getcwd(), 'stage')
        self.parts_dir = os.path.join(os.getcwd(), 'parts')
        self.local_plugins_dir = os.path.join(self.parts_dir, 'plugins')
示例#2
0
 def setUp(self):
     super().setUp()
     temp_cwd_fixture = fixture_setup.TempCWD()
     self.useFixture(temp_cwd_fixture)
     self.path = temp_cwd_fixture.path
     # Some tests will directly or indirectly change the plugindir, which
     # is a module variable. Make sure that it is returned to the original
     # value when a test ends.
     self.addCleanup(common.set_plugindir, common.get_plugindir())
     self.addCleanup(common.set_schemadir, common.get_schemadir())
     self.addCleanup(common.set_schemadir, common.get_schemadir())
     self.addCleanup(common.reset_env)
     common.set_schemadir(os.path.join(__file__,
                          '..', '..', '..', 'schema'))
示例#3
0
 def setUp(self):
     super().setUp()
     temp_cwd_fixture = fixture_setup.TempCWD()
     self.useFixture(temp_cwd_fixture)
     self.path = temp_cwd_fixture.path
     # Some tests will directly or indirectly change the plugindir, which
     # is a module variable. Make sure that it is returned to the original
     # value when a test ends.
     self.addCleanup(common.set_plugindir, common.get_plugindir())
     self.addCleanup(common.set_schemadir, common.get_schemadir())
     self.addCleanup(common.set_schemadir, common.get_schemadir())
     self.addCleanup(common.reset_env)
     common.set_schemadir(os.path.join(__file__,
                          '..', '..', '..', 'schema'))
示例#4
0
 def _load_schema(self):
     schema_file = os.path.abspath(os.path.join(
         common.get_schemadir(), 'snapcraft.yaml'))
     try:
         with open(schema_file) as fp:
             self._schema = yaml.load(fp)
     except FileNotFoundError:
         raise SnapcraftSchemaError(
             'snapcraft validation file is missing from installation path')
示例#5
0
def _validate_snapcraft_yaml(snapcraft_yaml):
    schema_file = os.path.abspath(os.path.join(common.get_schemadir(), "snapcraft.yaml"))

    try:
        with open(schema_file) as fp:
            schema = yaml.load(fp)
            format_check = jsonschema.FormatChecker()
            jsonschema.validate(snapcraft_yaml, schema, format_checker=format_check)
    except FileNotFoundError:
        raise SnapcraftSchemaError("snapcraft validation file is missing from installation path")
    except jsonschema.ValidationError as e:
        raise SnapcraftSchemaError(e.message)
示例#6
0
文件: yaml.py 项目: plars/snapcraft
def _validate_snapcraft_yaml(snapcraft_yaml):
    schema_file = os.path.abspath(os.path.join(common.get_schemadir(),
                                               'snapcraft.yaml'))

    try:
        with open(schema_file) as fp:
            schema = yaml.load(fp)
            format_check = jsonschema.FormatChecker()
            jsonschema.validate(snapcraft_yaml, schema,
                                format_checker=format_check)
    except FileNotFoundError:
        raise SnapcraftSchemaError(
            'snapcraft validation file is missing from installation path')
    except jsonschema.ValidationError as e:
        raise SnapcraftSchemaError(e.message)
示例#7
0
def _system_schema_part_props():
    schema_file = os.path.abspath(os.path.join(common.get_schemadir(),
                                               'snapcraft.yaml'))

    try:
        with open(schema_file) as fp:
            schema = yaml.load(fp)
    except FileNotFoundError:
        raise FileNotFoundError(
            'snapcraft validation file is missing from installation path')

    props = {'properties': {}}
    partpattern = schema['properties']['parts']['patternProperties']
    for pattern in partpattern:
        props['properties'].update(partpattern[pattern]['properties'])

    return props
示例#8
0
def _system_schema_part_props():
    schema_file = os.path.abspath(
        os.path.join(common.get_schemadir(), 'snapcraft.yaml'))

    try:
        with open(schema_file) as fp:
            schema = yaml.load(fp)
    except FileNotFoundError:
        raise FileNotFoundError(
            'snapcraft validation file is missing from installation path')

    props = {'properties': {}}
    partpattern = schema['properties']['parts']['patternProperties']
    for pattern in partpattern:
        props['properties'].update(partpattern[pattern]['properties'])

    return props
示例#9
0
def _validate_snapcraft_yaml(snapcraft_yaml):
    schema_file = os.path.abspath(os.path.join(common.get_schemadir(),
                                               'snapcraft.yaml'))

    try:
        with open(schema_file) as fp:
            schema = yaml.load(fp)
            format_check = jsonschema.FormatChecker()
            jsonschema.validate(snapcraft_yaml, schema,
                                format_checker=format_check)
    except FileNotFoundError:
        raise SnapcraftSchemaError(
            'snapcraft validation file is missing from installation path')
    except jsonschema.ValidationError as e:
        messages = [e.message]
        if e.path:
            messages.insert(0, "The '{}' property does not match the "
                               "required schema:".format(e.path.pop()))

        raise SnapcraftSchemaError(' '.join(messages))
示例#10
0
def _validate_snapcraft_yaml(snapcraft_yaml):
    schema_file = os.path.abspath(os.path.join(common.get_schemadir(),
                                               'snapcraft.yaml'))

    try:
        with open(schema_file) as fp:
            schema = yaml.load(fp)
            format_check = jsonschema.FormatChecker()
            jsonschema.validate(snapcraft_yaml, schema,
                                format_checker=format_check)
    except FileNotFoundError:
        raise SnapcraftSchemaError(
            'snapcraft validation file is missing from installation path')
    except jsonschema.ValidationError as e:
        messages = [e.message]
        if e.path:
            messages.insert(0, "The '{}' property does not match the "
                               "required schema:".format(e.path.pop()))

        raise SnapcraftSchemaError(' '.join(messages))