Repository: JohnnyIrvin/shell-craft (language: python)

Issue:
Add Pytest and GitHub Actions for Unit Testing
Enable unit testing with Pytest and automate testing with GitHub Actions

**Is your feature request related to a problem? Please describe.**

Our project currently lacks a unit testing framework, which makes it difficult to ensure code quality and identify potential bugs. Manually testing every feature is time-consuming and error-prone. Additionally, coordinating and sharing testing efforts among team members can be challenging.

**Describe the solution you'd like**

We would like to incorporate Pytest as our unit testing framework. Pytest has a user-friendly syntax, runs quickly, and provides easy-to-read results. We would also like to set up GitHub Actions to automatically run our unit tests on every pull request, to ensure that our codebase remains stable and functional. 

**Describe alternatives you've considered**

We have considered other unit testing frameworks, such as unittest and nose, but have settled on Pytest due to its simplicity and ease of use. GitHub Actions would best meet our needs due to its seamless integration with GitHub.

**Additional context**

Without unit testing, our development process could be slowed down by manually testing each feature. Implementing Pytest and GitHub Actions would streamline our testing process, allowing team members to focus on development rather than testing.


Discussion / hints:

Fix patch:
diff --git a/pyproject.toml b/pyproject.toml
index 2ee821f..5e2484f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -10,7 +10,7 @@ authors = [
 ]
 description = "Generate shell commands using OpenAI models."
 readme = "README.md"
-requires-python = ">=3.7"
+requires-python = ">=3.9"
 classifiers = [
     "Programming Language :: Python :: 3",
     "License :: OSI Approved :: MIT License",
diff --git a/shell_craft/prompts/prompt.py b/shell_craft/prompts/prompt.py
index 74db4e6..98c563a 100644
--- a/shell_craft/prompts/prompt.py
+++ b/shell_craft/prompts/prompt.py
@@ -19,9 +19,8 @@
 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 from dataclasses import dataclass, field
-from typing import TypeAlias
 
-MODEL_MESSAGE: TypeAlias = list[dict[str, str]]
+MODEL_MESSAGE = list[dict[str, str]]
 
 @dataclass(frozen=True)
 class Prompt:


Test patch:
diff --git a/.github/workflows/unit-tests-run.yml b/.github/workflows/unit-tests-run.yml
new file mode 100644
index 0000000..aa107aa
--- /dev/null
+++ b/.github/workflows/unit-tests-run.yml
@@ -0,0 +1,26 @@
+name: Python package
+
+on: [push]
+
+jobs:
+  build:
+
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        python-version: ["3.9", "3.10", "3.11"]
+
+    steps:
+      - uses: actions/checkout@v3
+      - name: Set up Python ${{ matrix.python-version }}
+        uses: actions/setup-python@v4
+        with:
+          python-version: ${{ matrix.python-version }}
+      - name: Install dependencies
+        run: |
+          python -m pip install --upgrade pip
+          pip install pytest
+          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
+      - name: Test with pytest
+        run: |
+          python -m pytest
diff --git a/tests/test_factories.py b/tests/test_factories.py
new file mode 100644
index 0000000..2770fe3
--- /dev/null
+++ b/tests/test_factories.py
@@ -0,0 +1,41 @@
+# Copyright (c) 2023 Johnathan P. Irvin
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+import pytest
+
+import shell_craft.prompts as prompts
+from shell_craft.factories import PromptFactory
+
+PROMPTS = [
+    prompt
+    for prompt in dir(prompts)
+    if prompt.endswith("_PROMPT")
+    and not prompt.startswith("_")
+]
+
+@pytest.mark.parametrize("prompt", PROMPTS)
+def test_prompt_factory(prompt: str):
+    """
+    Test that the prompt factory returns the correct prompt.
+
+    Args:
+        prompt (str): The prompt to test.
+    """    
+    assert PromptFactory.get_prompt(prompt.removesuffix("_PROMPT")) == getattr(prompts, prompt)