Beispiel #1
0
def test_failed_import():
    s = capnp.SchemaParser()
    s2 = capnp.SchemaParser()

    foo = s.load(os.path.join(this_dir, 'foo.capnp'))
    bar = s2.load(os.path.join(this_dir, 'bar.capnp'))

    m = capnp._MallocMessageBuilder()
    foo = m.init_root(foo.Foo)
    m2 = capnp._MallocMessageBuilder()
    bar = m2.init_root(bar.Bar)

    foo.name = 'foo'

    with pytest.raises(Exception):
        bar.foo = foo
Beispiel #2
0
    def _getSchemas(self, schemaInText):
        import capnp

        schemaInText = j.core.text.strip(schemaInText)
        schemaInText = schemaInText.strip() + "\n"
        schemaId = self.getId(schemaInText)
        if schemaId not in self._schema_cache:
            nameOnFS = "schema_%s.capnp" % (schemaId)
            path = j.sal.fs.joinPaths(self._capnpVarDir, nameOnFS)
            j.sal.fs.writeFile(filename=path,
                               contents=schemaInText,
                               append=False)
            parser = capnp.SchemaParser()
            try:
                schema = parser.load(path)
            except Exception as e:
                time.sleep(0.1)
                try:
                    schema = parser.load(path)
                except Exception as e:
                    msg = str(e)
                    raise j.exceptions.Base(
                        "%s\n\nERROR:Could not parse capnp schema:\n%s" %
                        (schemaInText, msg))
            self._schema_cache[schemaId] = schema
        return self._schema_cache[schemaId]
Beispiel #3
0
 def _getSchemas(self, schemaInText):
     schemaInText = j.data.text.strip(schemaInText)
     schemaInText = schemaInText.strip() + "\n"
     schemaId = self.getId(schemaInText)
     if schemaId not in self._schema_cache:
         nameOnFS = "schema_%s.capnp" % (schemaId)
         path = j.sal.fs.joinPaths(self._capnpVarDir, nameOnFS)
         j.sal.fs.writeFile(filename=path, contents=schemaInText, append=False)
         parser = capnp.SchemaParser()
         schema = parser.load(path)
         self._schema_cache[schemaId] = schema
     return self._schema_cache[schemaId]