Skip to content

Commit a1e1d80

Browse files
authored
Add GitHub Action for testing (#1)
* Add GitHub Action for testing * Don't rely on as_integer_ratio - it doesn't exist for Fractions in Python < 3.8
1 parent cb52e33 commit a1e1d80

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Python package
5+
6+
on:
7+
pull_request:
8+
branches: [ main ]
9+
10+
jobs:
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
python-version: ['3.6', '3.7', '3.8', '3.9']
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
python -m pip install flake8 pytest
28+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
29+
- name: Lint with flake8
30+
run: |
31+
# stop the build if there are Python syntax errors or undefined names
32+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
33+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
34+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
35+
- name: Test with pytest
36+
run: |
37+
pytest

simplefractions/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ def _to_integer_ratio(x):
4949
"""
5050
if x == math.inf:
5151
return 1, 0
52-
elif x == -math.inf:
52+
if x == -math.inf:
5353
return -1, 0
54-
else:
55-
return x.as_integer_ratio()
54+
55+
# Best effort to get a numerator and denominator from x.
56+
fx = fractions.Fraction(x)
57+
return fx.numerator, fx.denominator
5658

5759

5860
def _esb_path(x, side):

0 commit comments

Comments
 (0)