harperreed / emfitapi-python

MIT License
0 stars 0 forks source link

sweep: add a github action for running python tests #2

Open harperreed opened 1 month ago

harperreed commented 1 month ago

Add GitHub Action for Python Tests

Description:

Create a GitHub Actions workflow to automatically run Python tests for the EmfitAPI Python Wrapper project.

Tasks:

Test:

Additional tasks:

sweep-ai[bot] commented 1 month ago
Sweeping

Search Results

Response

To address your request for adding a GitHub Action for running Python tests, we'll need to create two new files and update an existing one. Let's go through each task:

  1. Create a new GitHub Actions workflow file:

Let's create a new file named .github/workflows/python-tests.yml to set up the GitHub Actions workflow:

.github/workflows/python-tests.yml

--- 
+++ 
@@ -1 +1,28 @@
+name: Python Tests

+on:
+  push:
+    branches: [ main ]
+  pull_request:
+    branches: [ main ]
+
+jobs:
+  test:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        python-version: [3.6, 3.7, 3.8, 3.9]
+
+    steps:
+    - uses: actions/checkout@v2
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v2
+      with:
+        python-version: ${{ matrix.python-version }}
+    - name: Install dependencies
+      run: |
+        python -m pip install --upgrade pip
+        pip install -r requirements.txt
+    - name: Run tests
+      run: |
+        python -m unittest discover tests
  1. Add a simple test file:

Now, let's create a new test file tests/test_emfit_api.py with a basic test case:

tests/test_emfit_api.py

--- 
+++ 
@@ -1 +1,16 @@
+import unittest
+from emfit.api import EmfitAPI

+class TestEmfitAPI(unittest.TestCase):
+    def test_emfit_api_instance(self):
+        api = EmfitAPI()
+        self.assertIsInstance(api, EmfitAPI)
+        self.assertEqual(api.base_url, "https://qs-api.emfit.com/api/v1")
+
+    def test_emfit_api_with_token(self):
+        token = "test_token"
+        api = EmfitAPI(token=token)
+        self.assertEqual(api.token, token)
+
+if __name__ == '__main__':
+    unittest.main()
  1. Update README.md with a badge:

Let's update the README.md file to include a badge for the GitHub Actions workflow status:

README.md

--- 
+++ 
@@ -1,4 +1,6 @@
 # EmfitAPI Python Wrapper
+
+![Python Tests](https://github.com/harperreed/emfitapi-python/workflows/Python%20Tests/badge.svg)

 ## Overview

These changes will add a GitHub Action for running Python tests to your project. Here's a summary of what we've done:

  1. Created a new GitHub Actions workflow file (.github/workflows/python-tests.yml) that:

    • Runs on push and pull requests to the main branch
    • Sets up Python environments for versions 3.6, 3.7, 3.8, and 3.9
    • Installs project dependencies
    • Runs Python tests
  2. Added a simple test file (tests/test_emfit_api.py) with basic test cases:

    • Imports the EmfitAPI class
    • Creates a simple test to check if the EmfitAPI instance is created correctly
    • Adds an additional test to check if the token is set correctly when provided
  3. Updated the README.md file to include a badge for the GitHub Actions workflow status.

To make these changes effective:

  1. Commit the new files and changes to your repository.
  2. Push the changes to GitHub.
  3. GitHub Actions will automatically run the tests on push and pull requests to the main branch.

You can now see the test results and the status badge on your GitHub repository page. The badge will show the current status of your tests, providing quick visibility into the health of your project.

Continue the conversation with Sweep here: https://app.sweep.dev/c/584537ab-8072-4a59-87c7-44f53c941e93.

:book: For more information on how to use Sweep, please read our documentation.

Tracking ID: 5d09bcce4c