diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6f64a57 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,45 @@ +name: Tests + +on: + push: + branches: + - master + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.7, 3.8, 3.9, 3.11] # List of Python versions to test against + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + update-environment: false + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox + + - name: Run Tox + run: tox + + test_python_2: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Build + run: docker build -t backtrace-python . + + - name: Run Docker Container + run: docker run --rm backtrace-python diff --git a/.gitignore b/.gitignore index 76c0509..b28b756 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,61 @@ -*.egg-info test_all -build/ +# Byte-compiled files +*.pyc +*.pyo +*.pyd +__pycache__/ + +# Distribution / packaging +*.egg +*.egg-info/ dist/ +build/ +.eggs/ +*.egg-info/ +*.manifest +*.spec + +# Installation directories +pip-log.txt +pip-delete-this-directory.txt + +# pytest +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# pyenv +.python-version + +# virtualenv +venv/ +ENV/ +env/ +.venv/ +env.bak/ +venv.bak/ + +# tox +.tox/ +nox/ +coverage-report/ + +# IDEs and editors +.vscode/ +.idea/ +*.swp +*.swo + +# macOS +.DS_Store + +# Windows +Thumbs.db +Desktop.ini diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7421f06 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:2.7-slim + +WORKDIR /sdk +COPY ./requirements.txt /sdk + +RUN pip install --upgrade pip \ + && pip install pytest -r requirements.txt + +COPY . /sdk + +CMD ["pytest"] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3d43198 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +six +simplejson==3.19.3 diff --git a/setup.py b/setup.py index 762a663..20f87f3 100644 --- a/setup.py +++ b/setup.py @@ -1,19 +1,31 @@ #!/usr/bin/env python -from setuptools import setup +from setuptools import find_packages, setup import backtracepython setup( name='backtracepython', version=backtracepython.version_string, - description='Backtrace error reporting tool for Python', - author='Andrew Kelley', - author_email='akelley@backtrace.io', - packages=['backtracepython'], + description='Backtrace.io error reporting tool for Python', + author='Backtrace.io', + author_email='team@backtrace.io', + packages=find_packages(), test_suite="tests", url='https://github.com/backtrace-labs/backtrace-python', install_requires=[ + 'six', 'simplejson', - ] + ], + extras_require={ + 'test': ['pytest'], + }, + python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4', + classifiers=[ + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + ], ) diff --git a/tests/__init__.py b/tests/test_basic_flow.py similarity index 78% rename from tests/__init__.py rename to tests/test_basic_flow.py index 14133fe..540f751 100644 --- a/tests/__init__.py +++ b/tests/test_basic_flow.py @@ -1,15 +1,13 @@ -import simplejson as json import os import subprocess import sys -import unittest + +import simplejson as json if sys.version_info.major >= 3: - from http.server import HTTPServer - from http.server import BaseHTTPRequestHandler + from http.server import BaseHTTPRequestHandler, HTTPServer else: - from BaseHTTPServer import HTTPServer - from BaseHTTPServer import BaseHTTPRequestHandler + from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer tests_dir = os.path.dirname(os.path.realpath(__file__)) exe_dir = os.path.join(tests_dir, "exe") @@ -32,16 +30,13 @@ def check_basic_report(obj): assert obj['attributes']['a'] == 1 assert obj['attributes']['b'] == "bar" -def check_multi_file(obj): - if sys.version_info.major >= 3: - assert obj['classifiers'][0] == "JSONDecodeError" - assert obj['attributes']['error.message'] == "Expecting value: line 1 column 1 (char 0)" - elif obj['langVersion'].startswith("PyPy"): +def check_multi_file(obj): + if obj['langVersion'].startswith("PyPy"): assert obj['classifiers'][0] == "ValueError" assert obj['attributes']['error.message'] == "Error when decoding true at char 1" else: - assert obj['classifiers'][0] == "ValueError" - assert obj['attributes']['error.message'] == "No JSON object could be decoded" + assert obj['classifiers'][0] == "JSONDecodeError" + assert obj['attributes']['error.message'] == "Expecting value: line 1 column 1 (char 0)" fault_stack = obj['threads'][obj['mainThread']]['stack'] source_code_id = fault_stack[-1]['sourceCode'] @@ -97,15 +92,14 @@ def log_message(self, format, *args): httpd.server_close() -class TestErrorReports(unittest.TestCase): - def test_basic_report(self): - run_one_test(check_basic_report, "simple_report.py") +def test_basic_report(): + run_one_test(check_basic_report, "simple_report.py") - def test_multi_file(self): - run_one_test(check_multi_file, "multi_file.py") +def test_multi_file(): + run_one_test(check_multi_file, "multi_file.py") - def test_send_report(self): - run_one_test(check_send_report, "send_report.py") +def test_send_report(): + run_one_test(check_send_report, "send_report.py") - def test_threads(self): - run_one_test(check_threads, "threads.py") +def test_threads(): + run_one_test(check_threads, "threads.py") diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..4dd7c9f --- /dev/null +++ b/tox.ini @@ -0,0 +1,11 @@ +[tox] +envlist = py27, py37, py38, py39, py310 +skipsdist = True + +[testenv] +deps = + -rrequirements.txt + pytest + +commands = + pytest