Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
khoroshevskyi committed Oct 30, 2023
1 parent 252e592 commit 02db1b0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
1 change: 0 additions & 1 deletion bbconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
from bbconf.const import *

__all__ = ["BedBaseConf", "get_bedbase_cfg"]

22 changes: 17 additions & 5 deletions bbconf/bbconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
DEFAULT_HF_MODEL,
DEFAULT_VEC2VEC_MODEL,
DEFAULT_REGION2_VEC_MODEL,
DRS_ACCESS_URL,
)
from bbconf.exceptions import MissingConfigDataError, BedBaseConfError
from bbconf.helpers import raise_missing_key, get_bedbase_cfg
Expand All @@ -52,8 +53,6 @@

_LOGGER = getLogger(__name__)

DRS_ACCESS_URL = "{server_url}/objects/{object_id}/access/{access_id}"


class BedBaseConf:
"""
Expand Down Expand Up @@ -596,7 +595,13 @@ def get_prefixed_uri(self, postfix: str, remote_class: str = "http") -> str:
"""
return os.path.join(self.prefix(remote_class), postfix)

def get_bed_drs_metadata(object_id: str) -> dict:
def get_bed_drs_metadata(self, object_id: str) -> dict:
"""
:param object_id:
:return:
"""
bed_metadata = self.bed.retrieve(object_id)
drs_dict = {
"id": object_id,
Expand All @@ -606,7 +611,7 @@ def get_bed_drs_metadata(object_id: str) -> dict:
"access_methods": [],
}
# add access method for each remote class
for access_id in keys(self.config[CFG_REMOTE_KEY]):
for access_id in self.config[CFG_REMOTE_KEY].keys():
access_dict = {
"type": "https",
"access_id": access_id,
Expand All @@ -622,7 +627,14 @@ def get_bed_drs_metadata(object_id: str) -> dict:
drs_dict["access_methods"].append(access_dict)
return drs_dict

def get_bed_url(object_id: str, access_id: str) -> str:
def get_bed_url(self, object_id: str, access_id: str) -> str:
"""
:param object_id:
:param access_id:
:return:
"""
access_url = DRS_ACCESS_URL.format(
server_url=self.config["access_methods"][access_id]["server_url"],
object_id=object_id,
Expand Down
2 changes: 2 additions & 0 deletions bbconf/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,5 @@
DEFAULT_HF_MODEL = "sentence-transformers/all-MiniLM-L12-v2"
DEFAULT_VEC2VEC_MODEL = "databio/v2v-ChIP-atlas-hg38-ATAC"
DEFAULT_REGION2_VEC_MODEL = "databio/r2v-ChIP-atlas-hg38"

DRS_ACCESS_URL = "{server_url}/objects/{object_id}/access/{access_id}"
6 changes: 5 additions & 1 deletion interactive_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
import logging
import sys


def set_up_interactive_logger(package=None) -> logging.Logger:
"""Set up a logger for interactive testing"""
_LOGGER = logging.getLogger(package)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
stream = logging.StreamHandler(sys.stdout)
stream.setFormatter(formatter)
stream.setLevel(logging.DEBUG)
_LOGGER.addHandler(stream)
_LOGGER.setLevel(logging.DEBUG)
return _LOGGER


_LOGGER = set_up_interactive_logger()
_LOGGER.debug("Test log message")

Expand Down
27 changes: 21 additions & 6 deletions tests/test_bbconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from bbconf import BedBaseConf, get_bedbase_cfg
from bbconf.exceptions import *
from sqlmodel import Session, SQLModel, create_engine
from sqlmodel import SQLModel, create_engine
from sqlmodel.main import default_registry


Expand Down Expand Up @@ -74,7 +74,9 @@ def test_reporting_relationships(self, cfg_pth, test_data_bed, test_data_bedset)
bbc = BedBaseConf(get_bedbase_cfg(cfg=cfg_pth))
bbc.bed.report(record_identifier="bed1", values=test_data_bed)
bbc.bedset.report(record_identifier="bedset1", values=test_data_bedset)
bbc.report_relationship(bedfile_record_id="bed1", bedset_record_id="bedset1")
bbc.report_relationship(
bedfile_record_id="bed1", bedset_record_id="bedset1"
)

def test_cant_remove_record_if_in_reltable(
self, cfg_pth, test_data_bed, test_data_bedset
Expand All @@ -83,7 +85,9 @@ def test_cant_remove_record_if_in_reltable(
bbc = BedBaseConf(get_bedbase_cfg(cfg=cfg_pth))
bbc.bed.report(record_identifier="bed1", values=test_data_bed)
bbc.bedset.report(record_identifier="bedset1", values=test_data_bedset)
bbc.report_relationship(bedfile_record_id="bed1", bedset_record_id="bedset1")
bbc.report_relationship(
bedfile_record_id="bed1", bedset_record_id="bedset1"
)
with pytest.raises(IntegrityError):
bbc.bed.remove(record_identifier="bed1")
with pytest.raises(IntegrityError):
Expand All @@ -94,7 +98,9 @@ def test_select(self, cfg_pth, test_data_bed, test_data_bedset):
bbc = BedBaseConf(get_bedbase_cfg(cfg=cfg_pth))
bbc.bed.report(record_identifier="bed1", values=test_data_bed)
bbc.bedset.report(record_identifier="bedset1", values=test_data_bedset)
bbc.report_relationship(bedfile_record_id="bed1", bedset_record_id="bedset1")
bbc.report_relationship(
bedfile_record_id="bed1", bedset_record_id="bedset1"
)

unique_bedfiles = bbc.select_unique(table_name="bedfile__sample")
assert unique_bedfiles[0].record_identifier == "bed1"
Expand All @@ -108,8 +114,13 @@ def test_removal(self, cfg_pth, test_data_bed, test_data_bedset):
bbc = BedBaseConf(get_bedbase_cfg(cfg=cfg_pth))
bbc.bed.report(record_identifier="bed1", values=test_data_bed)
bbc.bedset.report(record_identifier="bedset1", values=test_data_bedset)
bbc.report_relationship(bedfile_record_id="bed1", bedset_record_id="bedset1",)
bbc.remove_relationship(bedset_record_id="bedset1", bedfile_record_id=["bed1"])
bbc.report_relationship(
bedfile_record_id="bed1",
bedset_record_id="bedset1",
)
bbc.remove_relationship(
bedset_record_id="bedset1", bedfile_record_id=["bed1"]
)
ori_cnt = bbc.bed.record_count
bbc.bed.remove(record_identifier="bed1")
assert ori_cnt - 1 == bbc.bed.record_count
Expand All @@ -125,3 +136,7 @@ def test_config_variables_are_set(self, cfg_pth, test_data_bed, test_data_bedset
assert bbc.config["qdrant"]["host"] == "localhost"
assert bbc.config["path"]["region2vec"] is not None
assert bbc.config["database"]["host"] in ["localhost", "127.0.0.1"]

def test_get_bed_drs_metadata(self):
# TODO: add test
assert True

0 comments on commit 02db1b0

Please sign in to comment.