Skip to content

Commit

Permalink
tests fix
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeKontsevik committed Feb 12, 2024
1 parent 5b34a07 commit 6051fca
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 276 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
# run: black . --check --diff
# - name: flake8
# run: |
# flake8 factfinder
# flake8 sloyka
# flake8 tests
# - name: isort
# run: |
# isort factfinder --check --diff
# isort sloyka --check --diff
# isort tests --check --diff
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FILES = ./factfinder/src/*
FILES = ./sloyka/src/*

lint:
@echo "Running pylint check..."
Expand Down
4 changes: 2 additions & 2 deletions examples/data_getter_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@
"\n",
"sys.path.append(project_root)\n",
"\n",
"from factfinder.src.data_getter import GeoDataGetter\n",
"from factfinder.src.constants import OSM_TAGS\n",
"from sloyka import GeoDataGetter\n",
"from sloyka import OSM_TAGS\n",
"\n",
"geo_data_getter = GeoDataGetter()\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/geocoder_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"folder = os.getcwd().split(\"\\\\examples\")[0]\n",
"sys.path.append(folder)\n",
"\n",
"from factfinder import Geocoder"
"from sloyka import Geocoder"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/pipeline_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source": [
"import torch\n",
"import pandas as pd\n",
"from factfinder import (\n",
"from sloyka import (\n",
" EventDetection,\n",
" Geocoder,\n",
" TextClassifier,\n",
Expand Down
82 changes: 0 additions & 82 deletions tests/test_classifier.py

This file was deleted.

65 changes: 0 additions & 65 deletions tests/test_classifier_topic.py

This file was deleted.

96 changes: 3 additions & 93 deletions tests/test_classifiers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest
import torch
import pandas as pd
from sloyka.src.text_classifiers import TextClassifiers
from sloyka import TextClassifiers

path_to_file = "C:/Users/trolo/CodeNIRMA/sloyka/data/raw/Адмиралтейский.csv"
path_to_file = "data/raw/Адмиралтейский.csv"

@pytest.fixture
def test_data():
Expand All @@ -21,26 +21,6 @@ def model():
device_type=torch.device("cpu"),
)

def test_init():
# Arrange
repository_id = "Sandrro/text_to_subfunction_v10"
number_of_categories = 1
device_type = torch.device("cpu")

# Act
classifier = TextClassifiers(
repository_id, number_of_categories, device_type
)

# Assert
assert classifier.REP_ID == repository_id
assert classifier.CATS_NUM == number_of_categories
assert classifier.classifier.model.name_or_path == repository_id
assert (
classifier.classifier.tokenizer.name_or_path
== "cointegrated/rubert-tiny2"
)

def test_cats_probs(model, test_data):
expected_df = pd.DataFrame(
{
Expand All @@ -57,74 +37,4 @@ def test_cats_probs(model, test_data):
test_data["Текст"].progress_map(lambda x: model.run_text_classifier_topics(x)).to_list()
)
assert test_data["cats"].equals(expected_df["cats"])
assert test_data["probs"].equals(expected_df["probs"])

@pytest.fixture
def test_data():
df_predict = pd.read_csv(path_to_file, sep=";")
df_predict.rename(columns={"Текст комментария": "Текст"}, inplace=True)
df_predict = df_predict.dropna(subset=["Текст"])
df_predict = df_predict.head(3)
return df_predict

@pytest.fixture
def model():
return TextClassifiers(
repository_id="Sandrro/text_to_function_v2",
number_of_categories=1,
device_type=torch.device("cpu"),
)

def test_init():
# Arrange
repository_id = "Sandrro/text_to_function_v2"
number_of_categories = 1
device_type = torch.device("cpu")

# Act
classifier = TextClassifiers(
repository_id, number_of_categories, device_type
)

# Assert
assert classifier.REP_ID == repository_id
assert classifier.CATS_NUM == number_of_categories
assert classifier.classifier.model.name_or_path == repository_id
assert (
classifier.classifier.tokenizer.name_or_path
== "cointegrated/rubert-tiny2"
)


@pytest.mark.parametrize(
"text, expected_cats, expected_probs",
[
# Первый тестовый текст с одной категорией
("Хочу окунуться в это пространство.", "Благоустройство", "0.874")
],
)

# Определяем тестовую функцию
# Создаем объект класса TextClassifier с параметрами по умолчанию
def test_run(text, expected_cats, expected_probs, model):
# Вызываем метод run с входным текстом и получаем список с категориями и вероятностями
cats, probs = model.run_text_classifier(text)

# Проверяем, что категории и вероятности равны ожидаемым
assert cats == expected_cats
assert probs == expected_probs


def test_cats_probs(model, test_data):
expected_df = pd.DataFrame(
{
"cats": ["Благоустройство", "Другое", "Транспорт"],
"probs": ["0.874", "0.538", "0.789"],
}
)

test_data[["cats", "probs"]] = pd.DataFrame(
test_data["Текст"].progress_map(lambda x: model.run_text_classifier(x)).to_list()
)
assert test_data["cats"].equals(expected_df["cats"])
assert test_data["probs"].equals(expected_df["probs"])
assert test_data["probs"].equals(expected_df["probs"])
2 changes: 1 addition & 1 deletion tests/test_data_getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def geo_data_getter():
@pytest.mark.parametrize(
"osm_id, tags, result_len",
[
(421007, {tdict[0][0]: tdict[0][1]}, 294),
(421007, {tdict[0][0]: tdict[0][1]}, 305),
],
)
def test_process_data_and_assert(geo_data_getter, osm_id, tags, result_len):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_events_modelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_event_detection(gdf):
expected_risk = 0.405
expected_messages = [4, 5, 3, 2]
event_model = EventDetection()
messages, events, connections = event_model.run(
_, events, _ = event_model.run(
gdf, path_to_population, "Санкт-Петербург", 32636, min_event_size=3
)
event_name = events.iloc[0]["name"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_geocoder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pandas as pd
import pytest
from factfinder.src.geocoder import Geocoder
from sloyka import Geocoder

osm_city_level: int = 5
osm_city_name: str = "Санкт-Петербург"
Expand Down
18 changes: 2 additions & 16 deletions tests/test_location.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@

from sloyka.src.geocoder import Geocoder

# def test_geocode_with_retry(input_address, geocode_result):
# result = Location().geocode_with_retry(input_address)
# assert result.address == geocode_result


# def test_geocode_with_retry_empty_address():
# result = Location().geocode_with_retry("")
# assert result is None


# def test_query(input_address, geocode_result):
# result = Location().query(input_address)
# assert result.address == geocode_result

from sloyka import Geocoder
import pytest

@pytest.mark.parametrize(
"input_address,geocode_result",
Expand Down
10 changes: 0 additions & 10 deletions tests/test_streets.py

This file was deleted.

0 comments on commit 6051fca

Please sign in to comment.