Merge pull request #2 from andreped/test-ci
Browse filesImplemented CI workflow for unit tests and linting
- .github/workflows/tests.yml +27 -0
- postly/clients/postly_client.py +7 -7
- postly/common/models.py +2 -1
- shell/format.sh +4 -0
- shell/lint.sh +23 -0
.github/workflows/tests.yml
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Tests
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- '**'
|
7 |
+
|
8 |
+
jobs:
|
9 |
+
tests:
|
10 |
+
runs-on: ubuntu-20.04
|
11 |
+
steps:
|
12 |
+
- name: Checkout code
|
13 |
+
uses: actions/checkout@v2
|
14 |
+
|
15 |
+
- name: Set up Python 3.6
|
16 |
+
uses: actions/setup-python@v4
|
17 |
+
with:
|
18 |
+
python-version: "3.6"
|
19 |
+
|
20 |
+
- name: Install dependencies
|
21 |
+
run: pip install -r requirements.txt
|
22 |
+
|
23 |
+
- name: Check formatting
|
24 |
+
run: sh shell/lint.sh
|
25 |
+
|
26 |
+
- name: Run tests
|
27 |
+
run: pytest -v tests/
|
postly/clients/postly_client.py
CHANGED
@@ -54,13 +54,13 @@ class PostlyClient:
|
|
54 |
"""
|
55 |
if user_name not in self.userPosts:
|
56 |
raise KeyError(f"User {user_name} not found.")
|
57 |
-
|
58 |
if len(post_text) > self.post_max_length:
|
59 |
raise RuntimeError("Post is too long")
|
60 |
|
61 |
if not post_text.strip():
|
62 |
raise ValueError("Post cannot be empty.")
|
63 |
-
|
64 |
if not isinstance(timestamp, int) or timestamp < 0:
|
65 |
raise ValueError("Timestamp must be a non-negative integer.")
|
66 |
|
@@ -80,7 +80,7 @@ class PostlyClient:
|
|
80 |
"""
|
81 |
if user_name not in self.userPosts:
|
82 |
raise KeyError(f"User '{user_name}' not found.")
|
83 |
-
|
84 |
self.userPosts.pop(user_name, None)
|
85 |
|
86 |
def get_posts_for_user(self, user_name: str) -> List[str]:
|
@@ -94,7 +94,7 @@ class PostlyClient:
|
|
94 |
"""
|
95 |
if user_name not in self.userPosts:
|
96 |
raise KeyError(f"User '{user_name} not found.")
|
97 |
-
|
98 |
return [post_data.content for post_data in self.userPosts[user_name][::-1]]
|
99 |
|
100 |
def get_posts_for_topic(self, topic: str) -> List[str]:
|
@@ -126,13 +126,13 @@ class PostlyClient:
|
|
126 |
"""
|
127 |
if not isinstance(from_timestamp, int) or from_timestamp < 0:
|
128 |
raise ValueError("from_timestamp must be a non-negative integer.")
|
129 |
-
|
130 |
if not isinstance(to_timestamp, int) or to_timestamp < 0:
|
131 |
raise ValueError("to_timestamp must be a non-negative integer.")
|
132 |
-
|
133 |
if from_timestamp > to_timestamp:
|
134 |
raise ValueError("from_timestamp cannot be greater than to_timestamp.")
|
135 |
-
|
136 |
# construct topic histogram
|
137 |
topics_frequency = Counter()
|
138 |
for user in self.userPosts:
|
|
|
54 |
"""
|
55 |
if user_name not in self.userPosts:
|
56 |
raise KeyError(f"User {user_name} not found.")
|
57 |
+
|
58 |
if len(post_text) > self.post_max_length:
|
59 |
raise RuntimeError("Post is too long")
|
60 |
|
61 |
if not post_text.strip():
|
62 |
raise ValueError("Post cannot be empty.")
|
63 |
+
|
64 |
if not isinstance(timestamp, int) or timestamp < 0:
|
65 |
raise ValueError("Timestamp must be a non-negative integer.")
|
66 |
|
|
|
80 |
"""
|
81 |
if user_name not in self.userPosts:
|
82 |
raise KeyError(f"User '{user_name}' not found.")
|
83 |
+
|
84 |
self.userPosts.pop(user_name, None)
|
85 |
|
86 |
def get_posts_for_user(self, user_name: str) -> List[str]:
|
|
|
94 |
"""
|
95 |
if user_name not in self.userPosts:
|
96 |
raise KeyError(f"User '{user_name} not found.")
|
97 |
+
|
98 |
return [post_data.content for post_data in self.userPosts[user_name][::-1]]
|
99 |
|
100 |
def get_posts_for_topic(self, topic: str) -> List[str]:
|
|
|
126 |
"""
|
127 |
if not isinstance(from_timestamp, int) or from_timestamp < 0:
|
128 |
raise ValueError("from_timestamp must be a non-negative integer.")
|
129 |
+
|
130 |
if not isinstance(to_timestamp, int) or to_timestamp < 0:
|
131 |
raise ValueError("to_timestamp must be a non-negative integer.")
|
132 |
+
|
133 |
if from_timestamp > to_timestamp:
|
134 |
raise ValueError("from_timestamp cannot be greater than to_timestamp.")
|
135 |
+
|
136 |
# construct topic histogram
|
137 |
topics_frequency = Counter()
|
138 |
for user in self.userPosts:
|
postly/common/models.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
from dataclasses import dataclass
|
2 |
-
from pydantic import BaseModel
|
3 |
from typing import List
|
4 |
|
|
|
|
|
5 |
|
6 |
class StrictPost(BaseModel):
|
7 |
content: str
|
|
|
1 |
from dataclasses import dataclass
|
|
|
2 |
from typing import List
|
3 |
|
4 |
+
from pydantic import BaseModel
|
5 |
+
|
6 |
|
7 |
class StrictPost(BaseModel):
|
8 |
content: str
|
shell/format.sh
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
isort --sl postly/
|
3 |
+
black --line-length 120 postly/
|
4 |
+
flake8 --max-line-length 120 postly/
|
shell/lint.sh
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
isort --check --sl -c postly/
|
3 |
+
if ! [ $? -eq 0 ]
|
4 |
+
then
|
5 |
+
echo "Please run \"sh shell/format.sh\" to format the code."
|
6 |
+
exit 1
|
7 |
+
fi
|
8 |
+
echo "no issues with isort"
|
9 |
+
flake8 --max-line-length 120 postly/
|
10 |
+
if ! [ $? -eq 0 ]
|
11 |
+
then
|
12 |
+
echo "Please fix the code style issue."
|
13 |
+
exit 1
|
14 |
+
fi
|
15 |
+
echo "no issues with flake8"
|
16 |
+
black --check --line-length 120 postly/
|
17 |
+
if ! [ $? -eq 0 ]
|
18 |
+
then
|
19 |
+
echo "Please run \"sh shell/format.sh\" to format the code."
|
20 |
+
exit 1
|
21 |
+
fi
|
22 |
+
echo "no issues with black"
|
23 |
+
echo "linting success!"
|