Skip to content
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

feat: pre commit #74

Merged
merged 5 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,6 @@ dmypy.json
# VScode
.vscode/

.local/
.local/

poetry.lock
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
default_install_hook_types: [pre-push]
default_stages: [pre-push]
repos:
- repo: local
hooks:
- id: pytest-check
name: pytest-check
entry: make
language: system
pass_filenames: false
always_run: true
args: ["pre-commit"]
stages: [pre-push]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ from hyperon_das_atomdb.adapters import InMemoryDB
in_memory_db = InMemoryDB()
```

## Pre-Commit Setup

Before pushing your changes, it's recommended to set up pre-commit to run automated tests locally. Run the following command (needs to be done once):

```bash
pre-commit install
```

## Tests

You can ran the command below to execute the unittests
Expand Down
12 changes: 6 additions & 6 deletions hyperon_das_atomdb/adapters/redis_mongo_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,16 @@ def get_all_nodes(self, node_type: str, names: bool = False) -> List[str]:
if names:
return [
document[MongoFieldNames.NODE_NAME]
for document in self.mongo_nodes_collection.find({
MongoFieldNames.TYPE_NAME: node_type
})
for document in self.mongo_nodes_collection.find(
{MongoFieldNames.TYPE_NAME: node_type}
)
]
else:
return [
document[MongoFieldNames.ID_HASH]
for document in self.mongo_nodes_collection.find({
MongoFieldNames.TYPE_NAME: node_type
})
for document in self.mongo_nodes_collection.find(
{MongoFieldNames.TYPE_NAME: node_type}
)
]

def get_link_handle(self, link_type: str, target_handles: List[str]) -> str:
Expand Down
729 changes: 0 additions & 729 deletions poetry.lock

This file was deleted.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ black = "^23.7.0"
pytest = "^7.4.2"
pytest-cov = "^4.1.0"
flake8-pyproject = "^1.2.3"
pre-commit = "^3.5.0"


[tool.isort]
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/adapters/test_ram_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def test_get_link_targets(self, database: InMemoryDB):

def test_get_link_targets_invalid(self, database: InMemoryDB):
with pytest.raises(LinkDoesNotExist) as exc_info:
database.get_link_targets(f'link_handle_Fake')
database.get_link_targets('link_handle_Fake')
assert exc_info.type is LinkDoesNotExist
assert exc_info.value.args[0] == "This link does not exist"

Expand All @@ -291,7 +291,8 @@ def test_is_ordered_true(self, database: InMemoryDB):

def test_is_ordered_false(self, database: InMemoryDB):
with pytest.raises(LinkDoesNotExist) as exc_info:
ret = database.is_ordered('handle_123')
database.is_ordered('handle_123')

assert exc_info.type is LinkDoesNotExist
assert exc_info.value.args[0] == "This link does not exist"

Expand Down
8 changes: 2 additions & 6 deletions tests/unit/adapters/test_redis_mongo_db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os
import pickle
import re
from typing import Any, Dict, List, Optional
from unittest import mock

Expand Down Expand Up @@ -1849,7 +1847,7 @@
),
)
],
"patterns:6e644e70a9fe3145c88b5b6261af5754": [
"patterns:6e644e70a9fe3145c88b5b6261af5755": [
(
"e4685d56969398253b6f77efd21dc347",
(
Expand Down Expand Up @@ -3377,7 +3375,7 @@ def test_get_node_name_value_error(self, database):
with pytest.raises(ValueError) as exc_info:
database.get_node_name('handle')
assert exc_info.type is ValueError
assert exc_info.value.args[0] == f"Invalid handle: handle"
assert exc_info.value.args[0] == "Invalid handle: handle"

def test_get_matched_node_name(self, database):
expected = sorted(
Expand Down Expand Up @@ -3459,7 +3457,6 @@ def test_add_link(self, database):
assert (14, 28) == database.count_atoms()

all_nodes_before = database.get_all_nodes('Concept')
all_links_before = database.get_matched_type('Similarity')
database.add_link(
{
'type': 'Similarity',
Expand All @@ -3471,7 +3468,6 @@ def test_add_link(self, database):
)
database.commit()
all_nodes_after = database.get_all_nodes('Concept')
all_links_after = database.get_matched_type('Similarity')

assert len(all_nodes_before) == 14
assert len(all_nodes_after) == 16
Expand Down
Loading