Skip to content

Commit

Permalink
Merge pull request #46 from djotaku/devel
Browse files Browse the repository at this point in the history
Unit Tests, Linters, and User Requests, Oh My!
  • Loading branch information
djotaku authored Nov 9, 2019
2 parents b6a5633 + 82e8469 commit cb7489d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/linttest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 extralifedonations.py IPC.py readparticipantconf.py --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 extralifedonations.py IPC.py readparticipantconf.py team.py --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 extralifedonations.py IPC.py readparticipantconf.py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 extralifedonations.py IPC.py readparticipantconf.py team.py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
shell: bash
- name: Test with pytest
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linuxbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 extralifedonations.py --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 extralifedonations.py IPC.py readparticipantconf.py team.py --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 extralifedonations.py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 extralifedonations.py IPC.py readparticipantconf.py team.py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windowsbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 extralifedonations.py --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 extralifedonations.py IPC.py readparticipantconf.py team.py --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 extralifedonations.py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 extralifedonations.py IPC.py readparticipantconf.py team.py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
Expand Down
1 change: 0 additions & 1 deletion IPC.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
in because a new donation has ocurred.
"""

import sys
import readparticipantconf


Expand Down
20 changes: 15 additions & 5 deletions extralifedonations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import urllib.request
import time
import unicodedata

import readparticipantconf
import IPC
Expand Down Expand Up @@ -61,8 +60,9 @@ def __init__(self):
self.donorcalcs['last5DonorNameAmts'] = "No Donors Yet"
self.donorcalcs['last5DonorNameAmtsMessage'] = "No Donors Yet"
self.donorcalcs['last5DonorNameAmtsMessageHorizontal'] = "No Donors Yet"
self.donorcalcs['last5DonorNameAmtsHorizontal'] = "No Donors Yet"
self.participantinfo = {}

# misc
self.loop = True
IPC.writeIPC("0")
Expand All @@ -84,9 +84,12 @@ def get_participant_JSON(self):
headers=self.header)
self.participantJSON = json.load(urllib.request.urlopen(request))
except urllib.error.HTTPError:
print("""Couldn't get to participant URL.
print(f"""Couldn't get to {self.participantURL}.
Check ExtraLifeID.
Or server may be unavailable.""")
Or server may be unavailable.
If you can reach that URL from your browser
please open an issue at:
https://github.com/djotaku/ELDonationTracker""")

self.ParticipantTotalRaised = self.participantJSON['sumDonations']
self.ParticipantNumDonations = self.participantJSON['numDonations']
Expand All @@ -110,7 +113,7 @@ def get_donors(self):
headers=self.header)
self.donorJSON = json.load(urllib.request.urlopen(request))
except urllib.error.HTTPError:
print("""Couldn't get to donor URL.
print(f"""Couldn't get to {self.donorURL}.
Check ExtraLifeID.
Or server may be unavailable.""")
if not self.donorJSON:
Expand Down Expand Up @@ -138,6 +141,12 @@ def _last5donors(self, donors, message, horizontal):
if donor == 4:
break
return text
elif not message and horizontal:
for donor in range(0, len(donors)):
text = text+self._donor_formatting(donors[donor], message)+" | "
if donor == 4:
break
return text
elif not message:
for donor in range(0, len(donors)):
text = text+self._donor_formatting(donors[donor], message)+"\n"
Expand All @@ -163,6 +172,7 @@ def _donor_calculations(self):
self.donorcalcs['last5DonorNameAmts'] = self._last5donors(self.donorlist, False, False)
self.donorcalcs['last5DonorNameAmtsMessage'] = self._last5donors(self.donorlist, True, False)
self.donorcalcs['last5DonorNameAmtsMessageHorizontal'] = self._last5donors(self.donorlist, True, True)
self.donorcalcs['last5DonorNameAmtsHorizontal'] = self._last5donors(self.donorlist, False, True)

def write_text_files(self, dictionary):
"""Write info to text files."""
Expand Down
34 changes: 29 additions & 5 deletions extralifeunittests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
import extralifedonations

#run with command: py.test-3 extralifeunittests.py
# run with command: py.test-3 extralifeunittests.py
# or if in venv, just pytest extralifeunittests.py (works better)

#Tests for class Donor

# Tests for class Donor
def test_Donor_lt():
donor1 = extralifedonations.Donor("donor1","message",45)
donor2 = extralifedonations.Donor("donor2","message",30)
""" Test to make sure comparison works. """
donor1 = extralifedonations.Donor("donor1", "message", 45)
donor2 = extralifedonations.Donor("donor2", "message", 30)
assert donor2 < donor1

#Tests for class Participant

# Tests for class Participant
# Come back and develop tests for get_participant_JSON and
# get_donors after changing the methods to take input
# and return a value. That will be in prep for refactoring.
def test_donor_formatting_message_true():
""" Make sure the formatting works correctly. """
p = extralifedonations.Participant()
donor1 = extralifedonations.Donor("donor1", "message", 45)
formatted_message = p._donor_formatting(donor1, True)
assert formatted_message == "donor1 - $45.00 - message"


def test_donor_formatting_message_false():
""" Make sure the formatting works correctly. """
p = extralifedonations.Participant()
donor1 = extralifedonations.Donor("donor1", "message", 45)
formatted_message = p._donor_formatting(donor1, False)
assert formatted_message == "donor1 - $45.00"

# for the file writing don't forget to test donor names and messages with
# characters like ñ and ô and emojis.
1 change: 0 additions & 1 deletion readparticipantconf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Provide various files with the ability to load in the config file."""

import json
import unicodedata


def loadJSON():
Expand Down

0 comments on commit cb7489d

Please sign in to comment.