Skip to content

Commit

Permalink
Merge pull request #4 from TheJacksonLaboratory/G3-134-the-geneweaver…
Browse files Browse the repository at this point in the history
…-core-enumerations-should-use-builtin-int-enum-and-str-enum

G3 134: The geneweaver.core enumerations should use builtin IntEnum and StrEnum
  • Loading branch information
bergsalex committed Jan 19, 2024
2 parents 6426f87 + ab89526 commit f0ecad9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "geneweaver-core"
version = "0.8.0a1"
version = "0.8.0a2"
description = "The core of the Jax-Geneweaver Python library"
authors = ["Jax Computational Sciences <cssc@jax.org>"]
readme = "README.md"
Expand Down
14 changes: 7 additions & 7 deletions src/geneweaver/core/enum.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Enum classes for the GeneWeaver project."""
from enum import Enum
from enum import Enum, IntEnum


class CurationAssignment(int, Enum):
class CurationAssignment(IntEnum):
"""Enum for the different types of curation assignments."""

UNASSIGNED = 1
Expand All @@ -26,7 +26,7 @@ def __str__(self) -> str:
return "-".join(part.capitalize() for part in self.name.split("_"))


class ScoreType(int, Enum):
class ScoreType(IntEnum):
"""Integer based Enum for the different types of geneset scores."""

P_VALUE = 1
Expand Down Expand Up @@ -54,7 +54,7 @@ class AnnotationType(str, Enum):
NCBO = "ncbo"


class AdminLevel(int, Enum):
class AdminLevel(IntEnum):
"""Enum for the different levels of admin access."""

NORMAL_USER = 0
Expand All @@ -63,7 +63,7 @@ class AdminLevel(int, Enum):
ADMIN_WITH_DEBUG = 3


class Species(int, Enum):
class Species(IntEnum):
"""Species enum to match Geneweaver database."""

ALL = 0
Expand All @@ -83,7 +83,7 @@ def __str__(self) -> str:
return self.name.replace("_", " ").capitalize()


class GeneIdentifier(int, Enum):
class GeneIdentifier(IntEnum):
"""Gene Identifier types to match Geneweaver database."""

ENTREZ = 1
Expand All @@ -110,7 +110,7 @@ def __str__(self) -> str:
return self.name


class Microarray(int, Enum):
class Microarray(IntEnum):
"""Microarray types (does not match geneweaver database)."""

AFFYMETRIX_C_ELEGANS_GENOME_ARRAY = 100
Expand Down
19 changes: 18 additions & 1 deletion tests/unit/test_enum.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
"""Test the enum module."""
from enum import Enum, IntEnum

import pytest
from geneweaver.core.enum import (
AdminLevel,
CurationAssignment,
GeneIdentifier,
GenesetAccess,
GenesetScoreTypeStr,
Microarray,
ScoreType,
Species,
)


Expand Down Expand Up @@ -45,7 +51,7 @@ def test_curation_assignment_from_int(
)
def test_geneset_access(attribute: str, expected: str) -> None:
"""Test the GenesetAccess enum."""
assert getattr(GenesetAccess, attribute) == expected
assert getattr(GenesetAccess, attribute).value == expected


def test_geneset_access_from_string() -> None:
Expand Down Expand Up @@ -88,3 +94,14 @@ def test_geneset_score_type_str_from_string() -> None:
assert GenesetScoreTypeStr("binary") == GenesetScoreTypeStr.BINARY
assert GenesetScoreTypeStr("correlation") == GenesetScoreTypeStr.CORRELATION
assert GenesetScoreTypeStr("effect") == GenesetScoreTypeStr.EFFECT


@pytest.mark.parametrize(
"enum_class",
[CurationAssignment, ScoreType, AdminLevel, Species, GeneIdentifier, Microarray],
)
def test_is_int_enum(enum_class):
"""Test that Integer Enums are defined as IntEnum."""
assert issubclass(enum_class, int)
assert issubclass(enum_class, Enum)
assert issubclass(enum_class, IntEnum)

0 comments on commit f0ecad9

Please sign in to comment.