Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
🐛 Simplify __repr__ and test for __repr__ (#405)
Browse files Browse the repository at this point in the history
* ✨ Simplify __repr__

Signed-off-by: zethson <[email protected]>

* ✨ Add test for __repr__

Signed-off-by: zethson <[email protected]>

* 🎨 Fix session

Signed-off-by: zethson <[email protected]>

* 🎨 Fix login

Signed-off-by: zethson <[email protected]>

* 🎨 Don't need a session maybe?

Signed-off-by: zethson <[email protected]>

* 🎨 Install lamindb in nox session

Signed-off-by: zethson <[email protected]>

* 🎨 System

Signed-off-by: zethson <[email protected]>

* 🎨 Tests

Signed-off-by: zethson <[email protected]>

* 🎨 Strip ansi

Signed-off-by: zethson <[email protected]>

* 🎨 Test bionty in __repr__

Signed-off-by: zethson <[email protected]>

* 🎨 Test bionty in __repr__

Signed-off-by: zethson <[email protected]>

* 🎨 Rename to bionty instance

Signed-off-by: zethson <[email protected]>

* 🎨 Scope instances

Signed-off-by: zethson <[email protected]>

* 🎨 Test function scope

Signed-off-by: zethson <[email protected]>

* 🎨 Only integrity instance

Signed-off-by: zethson <[email protected]>

* 🎨 Only integrity instance

Signed-off-by: zethson <[email protected]>

* 🎨 Add comment

Signed-off-by: zethson <[email protected]>

---------

Signed-off-by: zethson <[email protected]>
  • Loading branch information
Zethson authored Jul 31, 2024
1 parent 18f11bd commit adb13e1
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 19 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
python-version: ["3.11"]
timeout-minutes: 15

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: ".github/workflows/build.yml" # See dependencies below
- name: cache pre-commit
uses: actions/cache@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions lnschema_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,11 @@ def _get_related_field_type(field) -> str:
)

non_external_schema_fields_formatted = [
f" .{field.name.replace('_links', '')}: {_get_related_field_type(field)}\n"
f" .{field.name}: {_get_related_field_type(field)}\n"
for field in non_external_schema_fields
]
external_schema_fields_formatted = [
f" .{field.name.replace('_links', '')}: {_get_related_field_type(field)}\n"
f" .{field.name}: {_get_related_field_type(field)}\n"
for field in external_schema_fields
]

Expand Down
6 changes: 3 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import nox
from laminci.nox import login_testuser1, run, run_pre_commit, run_pytest
from laminci.nox import run, run_pre_commit, run_pytest

nox.options.default_venv_backend = "none"

Expand All @@ -11,9 +11,9 @@ def lint(session: nox.Session) -> None:

@nox.session
def test(session: nox.Session) -> None:
run(session, "pip install -e .[dev]")
run(session, "uv pip install --system -e .[dev]")
run(
session,
"pip install lamindb_setup@git+https://github.com/laminlabs/lamindb-setup",
"uv pip install --system lamindb[bionty]@git+https://github.com/laminlabs/lamindb",
)
run_pytest(session, coverage=False)
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
# mandate zero dependencies
dependencies = [
Expand Down Expand Up @@ -44,7 +45,7 @@ omit = [
[tool.ruff]
src = ["src"]
line-length = 88
select = [
lint.select = [
"F", # Errors detected by Pyflakes
"E", # Error detected by Pycodestyle
"W", # Warning detected by Pycodestyle
Expand All @@ -60,7 +61,7 @@ select = [
"NPY", # Numpy specific rules
"PTH" # Use pathlib
]
ignore = [
lint.ignore = [
# Do not catch blind exception: `Exception`
"BLE001",
# Errors from function calls in argument defaults. These are fine when the result is immutable.
Expand Down Expand Up @@ -129,10 +130,10 @@ ignore = [
"PTH123",
]

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"docs/*" = ["I"]
"tests/*" = ["D"]
"*/__init__.py" = ["F401"]
10 changes: 5 additions & 5 deletions tests/test_integrity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@


@pytest.fixture(scope="module")
def setup_instance():
ln_setup.init(storage="./testdb")
def setup_bionty_instance():
ln_setup.init(storage="./test-bionty-db", schema="bionty")
yield
ln_setup.delete("testdb", force=True)
ln_setup.delete("test-bionty-db", force=True)


def test_migrate_check(setup_instance):
def test_migrate_check(setup_bionty_instance):
assert ln_setup.migrate.check()


def test_system_check(setup_instance):
def test_system_check(setup_bionty_instance):
ln_setup.django("check")
94 changes: 94 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import re
import textwrap

import lamindb as ln

# The tests defined in this script use the lamindb instance defined in test_integrity


def _strip_ansi(text: str) -> str:
"""Remove ANSI escape sequences from a string."""
ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
return ansi_escape.sub("", text)


def test_registry__repr__param():
param = ln.Param
expected_repr = textwrap.dedent("""\
Param
Basic fields
.id: BigAutoField
.name: CharField
.dtype: CharField
.created_at: DateTimeField
.updated_at: DateTimeField
Relational fields
.created_by: User
.run: Run
.previous_runs: Run
.paramvalue: ParamValue
""").strip()

actual_repr = _strip_ansi(repr(param))
assert actual_repr.strip() == expected_repr.strip()


def test_registry__repr__artifact():
artifact = ln.Artifact
expected_repr = textwrap.dedent("""\
Artifact
Basic fields
.id: AutoField
.uid: CharField
.description: CharField
.key: CharField
.suffix: CharField
.type: CharField
.accessor: CharField
.size: BigIntegerField
.hash: CharField
.hash_type: CharField
.n_objects: BigIntegerField
.n_observations: BigIntegerField
.visibility: SmallIntegerField
.key_is_virtual: BooleanField
.version: CharField
.created_at: DateTimeField
.updated_at: DateTimeField
Relational fields
.created_by: User
.storage: Storage
.transform: Transform
.run: Run
.ulabels: ULabel
.input_of: Run
.previous_runs: Run
.feature_sets: FeatureSet
.feature_values: FeatureValue
.param_values: ParamValue
.latest_report_of: Transform
.source_code_of: Transform
.report_of: Run
.environment_of: Run
.collection: Collection
.collections: Collection
Bionty fields
.organisms: bionty.Organism
.genes: bionty.Gene
.proteins: bionty.Protein
.cell_markers: bionty.CellMarker
.tissues: bionty.Tissue
.cell_types: bionty.CellType
.diseases: bionty.Disease
.cell_lines: bionty.CellLine
.phenotypes: bionty.Phenotype
.pathways: bionty.Pathway
.experimental_factors: bionty.ExperimentalFactor
.developmental_stages: bionty.DevelopmentalStage
.ethnicities: bionty.Ethnicity
.reference_of_source: bionty.Source
.reference_of_sources: bionty.Source
""").strip()

actual_repr = _strip_ansi(repr(artifact))
assert actual_repr.strip() == expected_repr.strip()

0 comments on commit adb13e1

Please sign in to comment.