-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add unit tests for python pkg #99
Conversation
@sehilyi - on the python side, it might be worth looking at https://pydantic.dev/ to validate the config objects passed in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I will merge this.
Would publishing this to PyPI requires adding API tokens to the GH repo?
Yup, maybe have a look at |
Oh, the other thing to mention about from typing import Literal, Union
from pydantic import BaseModel, Field, HttpUrl
class Config(BaseModel):
id: str
cancer: str
assembly: Literal["hg38", "hg19"]
sv: HttpUrl
cnv: HttpUrl = Field(title="CNV", description="An URL of the CNV text file (.txt).")
drivers: Union[HttpUrl, None] = Field(
default=None,
title="Drivers",
description="An URL of a file that contains drivers (.txt).",
)
vcf: Union[HttpUrl, None] = Field(
default=None,
title="VCF",
description="An URL of the point mutation file (.vcf).",
)
vcfIndex: Union[HttpUrl, None] = Field(
default=None,
title="VCF Index",
description="An URL of the point mutation index file (.tbi).",
)
vcf2: Union[HttpUrl, None] = Field(
default=None,
title="VCF2",
description="An URL of the the indel file (.vcf).",
)
vcf2Index: Union[HttpUrl, None] = Field(
default=None,
title="VCF2 Index",
description="An URL of the indel index file (.tbi).",
)
bam: Union[HttpUrl, None] = Field(
default=None,
title="BAM",
description="An URL of the BAM file (.bam)."
)
bamIndex: Union[HttpUrl, None] = Field(
default=None,
title="BAM Index",
description="An URL of the BAM index file (.bai)."
)
note: Union[str, None] = Field(
default=None,
title="Note",
description="A textual annotation.",
)
if __name__ == "__main__":
print(Config.schema_json(indent=2)) {
"title": "Config",
"type": "object",
"properties": {
"id": {
"title": "Id",
"type": "string"
},
"cancer": {
"title": "Cancer",
"type": "string"
},
"assembly": {
"title": "Assembly",
"enum": [
"hg38",
"hg19"
],
"type": "string"
},
"sv": {
"title": "Sv",
"minLength": 1,
"maxLength": 2083,
"format": "uri",
"type": "string"
},
"cnv": {
"title": "CNV",
"description": "An URL of the CNV text file (.txt).",
"minLength": 1,
"maxLength": 2083,
"format": "uri",
"type": "string"
},
"drivers": {
"title": "Drivers",
"description": "An URL of a file that contains drivers (.txt).",
"minLength": 1,
"maxLength": 2083,
"format": "uri",
"type": "string"
},
"vcf": {
"title": "VCF",
"description": "An URL of the point mutation file (.vcf).",
"minLength": 1,
"maxLength": 2083,
"format": "uri",
"type": "string"
},
"vcfIndex": {
"title": "VCF Index",
"description": "An URL of the point mutation index file (.tbi).",
"minLength": 1,
"maxLength": 2083,
"format": "uri",
"type": "string"
},
"vcf2": {
"title": "VCF2",
"description": "An URL of the the indel file (.vcf).",
"minLength": 1,
"maxLength": 2083,
"format": "uri",
"type": "string"
},
"vcf2Index": {
"title": "VCF2 Index",
"description": "An URL of the indel index file (.tbi).",
"minLength": 1,
"maxLength": 2083,
"format": "uri",
"type": "string"
},
"bam": {
"title": "BAM",
"description": "An URL of the BAM file (.bam).",
"minLength": 1,
"maxLength": 2083,
"format": "uri",
"type": "string"
},
"bamIndex": {
"title": "BAM Index",
"description": "An URL of the BAM index file (.bai).",
"minLength": 1,
"maxLength": 2083,
"format": "uri",
"type": "string"
},
"note": {
"title": "Note",
"description": "A textual annotation.",
"type": "string"
}
},
"required": [
"id",
"cancer",
"assembly",
"sv",
"cnv"
]
} This means you get auto-validation/parsing on the python side: from chromosope import Config
unknown_config = [ ... ]
parsed = [Config(**item) for item in unknown_config]
parsed # now know the config is parsed correctly and could equally generate validators for the JS side from the JSON schema. |
src/chromoscope/_viewer.py