def find_source_root(self, src): if self.manifest_uri: mp = (ManifestParserFactory.new_from_file(self.manifest_uri[5:]) if self.manifest_uri.startswith("file:") else ManifestParserFactory.new_from_url(self.manifest_uri)) manifest = ManifestSchema().load_manifest(mp.as_dict()) include = manifest.get("export", {}).get("include", []) if len(include) == 1: if not os.path.isdir(os.path.join(src, include[0])): raise PackageException( "Non existing `include` directory `%s` in a package" % include[0]) return os.path.join(src, include[0]) for root, _, __ in os.walk(src): if ManifestFileType.from_dir(root): return root return src
def test_broken_schemas(): # non-strict mode data, errors = ManifestSchema(strict=False).load(dict(name="MyPackage")) assert set(errors.keys()) == set(["version"]) assert data.get("version") is None # invalid keywords data, errors = ManifestSchema(strict=False).load(dict(keywords=["kw1", "*^[]"])) assert errors assert data["keywords"] == ["kw1"] # strict mode with pytest.raises( ManifestValidationError, match="Missing data for required field" ): ManifestSchema(strict=True).load(dict(name="MyPackage")) # broken SemVer with pytest.raises( ManifestValidationError, match=("Invalid semantic versioning format") ): ManifestSchema(strict=True).load( dict(name="MyPackage", version="broken_version") ) # broken value for Nested with pytest.raises(ManifestValidationError, match=r"authors.*Invalid input type"): ManifestSchema(strict=True).load( dict( name="MyPackage", description="MyDescription", keywords=["a", "b"], authors=["should be dict here"], version="1.2.3", ) )