Skip to content

Commit

Permalink
test restructuring and cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
khoroshevskyi committed Jun 24, 2024
1 parent 41c6a95 commit 45e52f1
Show file tree
Hide file tree
Showing 18 changed files with 1,750 additions and 1,628 deletions.
18 changes: 6 additions & 12 deletions pepdbagent/db_utils.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
import datetime
import logging
from typing import Optional, List
from typing import List, Optional

from sqlalchemy import (
TIMESTAMP,
BigInteger,
FetchedValue,
ForeignKey,
Result,
Select,
String,
UniqueConstraint,
event,
select,
TIMESTAMP,
ForeignKey,
UniqueConstraint,
)
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.engine import URL, create_engine
from sqlalchemy.exc import ProgrammingError
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.orm import (
DeclarativeBase,
Mapped,
Session,
mapped_column,
relationship,
)
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column, relationship

from pepdbagent.const import POSTGRES_DIALECT, PKG_NAME
from pepdbagent.const import PKG_NAME, POSTGRES_DIALECT
from pepdbagent.exceptions import SchemaError

_LOGGER = logging.getLogger(PKG_NAME)
Expand Down
7 changes: 4 additions & 3 deletions pepdbagent/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# file with pydantic models
from typing import List, Optional, Union, Dict
from pydantic import BaseModel, Field, ConfigDict, field_validator
from peppy.const import CONFIG_KEY, SUBSAMPLE_RAW_LIST_KEY, SAMPLE_RAW_DICT_KEY
from typing import Dict, List, Optional, Union

from peppy.const import CONFIG_KEY, SAMPLE_RAW_DICT_KEY, SUBSAMPLE_RAW_LIST_KEY
from pydantic import BaseModel, ConfigDict, Field, field_validator

from pepdbagent.const import DEFAULT_TAG

Expand Down
4 changes: 2 additions & 2 deletions pepdbagent/modules/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
from typing import List, Literal, Optional, Union

from sqlalchemy import and_, func, or_, select
from sqlalchemy.sql.selectable import Select
from sqlalchemy.orm import Session
from sqlalchemy.sql.selectable import Select

from pepdbagent.const import (
DEFAULT_LIMIT,
DEFAULT_OFFSET,
DEFAULT_TAG,
LAST_UPDATE_DATE_KEY,
PKG_NAME,
SUBMISSION_DATE_KEY,
LAST_UPDATE_DATE_KEY,
)
from pepdbagent.db_utils import BaseEngine, Projects
from pepdbagent.exceptions import FilterError, ProjectNotFoundError, RegistryPathError
Expand Down
12 changes: 6 additions & 6 deletions pepdbagent/modules/namespace.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import logging
from typing import List, Union, Tuple
from collections import Counter
from datetime import datetime, timedelta
from typing import List, Tuple, Union

from sqlalchemy import distinct, func, or_, select, text
from sqlalchemy.sql.selectable import Select
from sqlalchemy.orm import Session
from sqlalchemy.sql.selectable import Select

from pepdbagent.const import DEFAULT_LIMIT, DEFAULT_OFFSET, PKG_NAME, DEFAULT_LIMIT_INFO
from pepdbagent.const import DEFAULT_LIMIT, DEFAULT_LIMIT_INFO, DEFAULT_OFFSET, PKG_NAME
from pepdbagent.db_utils import BaseEngine, Projects
from pepdbagent.exceptions import NamespaceNotFoundError
from pepdbagent.db_utils import Projects, BaseEngine
from pepdbagent.models import (
ListOfNamespaceInfo,
Namespace,
NamespaceList,
NamespaceInfo,
ListOfNamespaceInfo,
NamespaceList,
NamespaceStats,
)
from pepdbagent.utils import tuple_converter
Expand Down
40 changes: 15 additions & 25 deletions pepdbagent/modules/project.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
import datetime
import json
import logging
from typing import Union, List, NoReturn, Dict
from typing import Dict, List, NoReturn, Union

import peppy
from sqlalchemy import and_, delete, select
from sqlalchemy.exc import IntegrityError, NoResultFound
from sqlalchemy.orm import Session
from sqlalchemy import Select
from sqlalchemy.orm.attributes import flag_modified
import numpy as np

import peppy
from peppy.const import (
SAMPLE_RAW_DICT_KEY,
SUBSAMPLE_RAW_LIST_KEY,
CONFIG_KEY,
SAMPLE_TABLE_INDEX_KEY,
SAMPLE_NAME_ATTR,
SAMPLE_RAW_DICT_KEY,
SAMPLE_TABLE_INDEX_KEY,
SUBSAMPLE_RAW_LIST_KEY,
)
from sqlalchemy import Select, and_, delete, select
from sqlalchemy.exc import IntegrityError, NoResultFound
from sqlalchemy.orm import Session
from sqlalchemy.orm.attributes import flag_modified

from pepdbagent.const import (
DEFAULT_TAG,
DESCRIPTION_KEY,
NAME_KEY,
PKG_NAME,
PEPHUB_SAMPLE_ID_KEY,
)

from pepdbagent.db_utils import Projects, Samples, Subsamples, BaseEngine
from pepdbagent.const import DEFAULT_TAG, DESCRIPTION_KEY, NAME_KEY, PEPHUB_SAMPLE_ID_KEY, PKG_NAME
from pepdbagent.db_utils import BaseEngine, Projects, Samples, Subsamples
from pepdbagent.exceptions import (
PEPDatabaseAgentError,
ProjectDuplicatedSampleGUIDsError,
ProjectNotFoundError,
ProjectUniqueNameError,
PEPDatabaseAgentError,
SampleTableUpdateError,
ProjectDuplicatedSampleGUIDsError,
)
from pepdbagent.models import UpdateItems, UpdateModel, ProjectDict
from pepdbagent.utils import create_digest, registry_path_converter, order_samples, generate_guid

from pepdbagent.models import ProjectDict, UpdateItems, UpdateModel
from pepdbagent.utils import create_digest, generate_guid, order_samples, registry_path_converter

_LOGGER = logging.getLogger(PKG_NAME)

Expand Down
14 changes: 5 additions & 9 deletions pepdbagent/modules/sample.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import datetime
import logging
from typing import Union
import datetime

import peppy
from peppy.const import SAMPLE_TABLE_INDEX_KEY
from sqlalchemy import select, and_
from sqlalchemy import and_, select
from sqlalchemy.orm import Session
from sqlalchemy.orm.attributes import flag_modified

from pepdbagent.const import (
DEFAULT_TAG,
PKG_NAME,
)
from pepdbagent.exceptions import SampleNotFoundError, SampleAlreadyExistsError

from pepdbagent.db_utils import BaseEngine, Samples, Projects
from pepdbagent.const import DEFAULT_TAG, PKG_NAME
from pepdbagent.db_utils import BaseEngine, Projects, Samples
from pepdbagent.exceptions import SampleAlreadyExistsError, SampleNotFoundError
from pepdbagent.utils import generate_guid, order_samples

_LOGGER = logging.getLogger(PKG_NAME)
Expand Down
12 changes: 4 additions & 8 deletions pepdbagent/modules/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
from typing import Union

from sqlalchemy import and_, delete, select
from sqlalchemy.orm import Session
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import Session

from pepdbagent.const import (
PKG_NAME,
)

from pepdbagent.db_utils import BaseEngine, User, Stars, Projects
from pepdbagent.const import PKG_NAME
from pepdbagent.db_utils import BaseEngine, Projects, Stars, User
from pepdbagent.exceptions import ProjectAlreadyInFavorites, ProjectNotInFavorites
from pepdbagent.models import AnnotationList, AnnotationModel
from pepdbagent.exceptions import ProjectNotInFavorites, ProjectAlreadyInFavorites


_LOGGER = logging.getLogger(PKG_NAME)

Expand Down
23 changes: 9 additions & 14 deletions pepdbagent/modules/view.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
# View of the PEP. In other words, it is a part of the PEP, or subset of the samples in the PEP.

import logging
from typing import Union, List
from typing import List, Union

import peppy
from sqlalchemy import select, and_, delete
from sqlalchemy.orm import Session
from sqlalchemy import and_, delete, select
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import Session


from pepdbagent.const import (
DEFAULT_TAG,
PKG_NAME,
)
from pepdbagent.const import DEFAULT_TAG, PKG_NAME
from pepdbagent.db_utils import BaseEngine, Projects, Samples, Views, ViewSampleAssociation
from pepdbagent.exceptions import (
ViewNotFoundError,
SampleAlreadyInView,
ProjectNotFoundError,
SampleAlreadyInView,
SampleNotFoundError,
ViewAlreadyExistsError,
SampleNotInViewError,
ViewAlreadyExistsError,
ViewNotFoundError,
)

from pepdbagent.db_utils import BaseEngine, Samples, Projects, Views, ViewSampleAssociation
from pepdbagent.models import ViewAnnotation, CreateViewDictModel, ProjectViews
from pepdbagent.models import CreateViewDictModel, ProjectViews, ViewAnnotation

_LOGGER = logging.getLogger(PKG_NAME)

Expand Down
2 changes: 1 addition & 1 deletion pepdbagent/pepdbagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from pepdbagent.modules.annotation import PEPDatabaseAnnotation
from pepdbagent.modules.namespace import PEPDatabaseNamespace
from pepdbagent.modules.project import PEPDatabaseProject
from pepdbagent.modules.user import PEPDatabaseUser
from pepdbagent.modules.sample import PEPDatabaseSample
from pepdbagent.modules.user import PEPDatabaseUser
from pepdbagent.modules.view import PEPDatabaseView


Expand Down
4 changes: 2 additions & 2 deletions pepdbagent/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import datetime
import json
import uuid
from collections.abc import Iterable
from hashlib import md5
from typing import Tuple, Union, List
import uuid
from typing import List, Tuple, Union

import ubiquerg
from peppy.const import SAMPLE_RAW_DICT_KEY
Expand Down
7 changes: 3 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import peppy
import pytest
import os

from sqlalchemy import create_engine
from sqlalchemy import text
import peppy
import pytest
from sqlalchemy import create_engine, text

from pepdbagent import PEPDatabaseAgent

Expand Down
Loading

0 comments on commit 45e52f1

Please sign in to comment.