From e9c6d0128693ca85a37a575cc79bf0ba3c39a869 Mon Sep 17 00:00:00 2001 From: Ignacy Janiszewski Date: Thu, 27 Aug 2020 10:39:29 +0200 Subject: [PATCH] First tests done --- README.md | 12 +++---- src/run_from_file.py => run_from_file.py | 2 +- src/__init__.py | 0 src/main.py | 2 +- tests/__init__.py | 0 tests/test_concatenate_df.py | 12 +++++++ tests/test_get_info_from_df.py | 45 ++++++++++++++++++++++++ 7 files changed, 65 insertions(+), 8 deletions(-) rename src/run_from_file.py => run_from_file.py (96%) create mode 100644 src/__init__.py create mode 100644 tests/__init__.py create mode 100644 tests/test_concatenate_df.py create mode 100644 tests/test_get_info_from_df.py diff --git a/README.md b/README.md index ee17433..de7993b 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,18 @@ ## Example of usage: -` python src/run_from_file.py -m ` +`python run_from_file.py -m ` i.e. -` python src/run_from_file.py -m 1 ` +`python run_from_file.py -m 1` or via Docker (just change the last line in Dockerfile) -`RUN python src/run_from_file.py -m 1 ` - +`RUN python run_from_file.py -m 1 ` ### Python Version -` python -V ` -$ Python 3.7.6 +`python -V` + +\$ Python 3.7.6 diff --git a/src/run_from_file.py b/run_from_file.py similarity index 96% rename from src/run_from_file.py rename to run_from_file.py index 4d8b555..9d9c651 100644 --- a/src/run_from_file.py +++ b/run_from_file.py @@ -2,7 +2,7 @@ import argparse -from main import GetInfo +from src.main import GetInfo class GetArgument: diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/main.py b/src/main.py index 056f506..a775cb2 100644 --- a/src/main.py +++ b/src/main.py @@ -4,7 +4,7 @@ import pandas as pd from typing import List -from settings import comments_data, movies_data +from src.settings import comments_data, movies_data @dataclass diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_concatenate_df.py b/tests/test_concatenate_df.py new file mode 100644 index 0000000..40fd984 --- /dev/null +++ b/tests/test_concatenate_df.py @@ -0,0 +1,12 @@ +import pandas as pd + +from src.settings import comments_data, movies_data +from src.main import IngestData + + + +def test_comments_concatenate(): + com_id = IngestData(**comments_data) + comments_df = com_id.get_df() + assert comments_df.shape[0] > 1000 + assert comments_df.shape[1] == 4 diff --git a/tests/test_get_info_from_df.py b/tests/test_get_info_from_df.py new file mode 100644 index 0000000..b07f9a9 --- /dev/null +++ b/tests/test_get_info_from_df.py @@ -0,0 +1,45 @@ +import pandas as pd + +from src.main import GetInfo + + +def create_comments_example_df(): + data = { + "id_comment": [no for no in range(6)], + "user": [f"user{user_no}" for user_no in range(6)], + "id_movie": [1 for no in range(3)] + [2 for no in range(3)] + } + df = pd.DataFrame(data, columns = data.keys()).set_index("id_comment") + return df + + +def create_movies_example_df(): + data = { + "id_movie": [no for no in range(6)], + "title": [f"movie_{movie}" for movie in range(6)], + "ig_game": [1 for no in range(3)] + [2 for no in range(3)] + } + df = pd.DataFrame(data, columns = data.keys()).set_index("id_movie") + return df + + + +def test_get_movie_comments(): + example_df = create_comments_example_df() + gi = GetInfo() + comments_no = gi.get_movie_comments(1, example_df) + assert comments_no == 3 + + +def test_get_movie_title(): + example_df = create_movies_example_df() + gi = GetInfo() + movie_title = gi.get_movie_title(1, example_df) + assert movie_title == "movie_1" + + +def test_get_movie_title_no_movie_id(): + example_df = create_movies_example_df() + gi = GetInfo() + movie_title = gi.get_movie_title('X', example_df) + assert movie_title == None