Skip to content

Commit

Permalink
Move testing to GitHub Actions (#110)
Browse files Browse the repository at this point in the history
* Move testing to GitHub Actions

* Flake8-fixes.

* Replace Travis CI with GitHub Actions.

* Add coveralls to tests.

* Try different action for coverage.

* Increase complexity.

* Add .coveragerc
  • Loading branch information
kipe committed Dec 28, 2020
1 parent 63f90f3 commit 697eda1
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 49 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
@@ -0,0 +1,2 @@
[run]
relative_files = True
3 changes: 3 additions & 0 deletions .flake8
@@ -0,0 +1,3 @@
[flake8]
exclude = __init__.py
max_line_length = 120
53 changes: 53 additions & 0 deletions .github/workflows/python-package.yml
@@ -0,0 +1,53 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.5', '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
python -m pip install flake8 nose coverage
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the test if there are Python syntax errors or undefined names
flake8 enocean --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 enocean --count --exit-zero --max-complexity=15 --max-line-length=127 --statistics
- name: Test with nose
run: |
nosetests -s -q --with-coverage --cover-package=enocean
- name: Coveralls
uses: AndreMiras/coveralls-python-action@develop
with:
parallel: true
flag-name: run-${{ matrix.test_number }}

finish:
needs: test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: AndreMiras/coveralls-python-action@develop
with:
parallel-finished: true
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion enocean/communicators/communicator.py
Expand Up @@ -97,7 +97,7 @@ def base_id(self):
try:
packet = self.receive.get(block=True, timeout=0.1)
# We're only interested in responses to the request in question.
if packet.packet_type == PACKET.RESPONSE and packet.response == RETURN_CODE.OK and len(packet.response_data) == 4:
if packet.packet_type == PACKET.RESPONSE and packet.response == RETURN_CODE.OK and len(packet.response_data) == 4: # noqa: E501
# Base ID is set in the response data.
self._base_id = packet.response_data
# Put packet back to the Queue, so the user can also react to it if required...
Expand Down
1 change: 1 addition & 0 deletions enocean/consolelogger.py
Expand Up @@ -3,6 +3,7 @@
import logging
import logging.handlers


def init_logging(level=logging.DEBUG, log_to_file=False, logsize=1024, logcount=5):
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

Expand Down
8 changes: 5 additions & 3 deletions enocean/protocol/eep.py
Expand Up @@ -7,7 +7,8 @@
from bs4 import BeautifulSoup

import enocean.utils
from enocean.protocol.constants import RORG
# Left as a helper
from enocean.protocol.constants import RORG # noqa: F401


class EEP(object):
Expand All @@ -17,12 +18,13 @@ def __init__(self):
self.init_ok = False
self.telegrams = {}

eep_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'EEP.xml')
try:
if version_info[0] > 2:
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'EEP.xml'), 'r', encoding='UTF-8') as xml_file:
with open(eep_path, 'r', encoding='UTF-8') as xml_file:
self.soup = BeautifulSoup(xml_file.read(), "html.parser")
else:
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'EEP.xml'), 'r') as xml_file:
with open(eep_path, 'r') as xml_file:
self.soup = BeautifulSoup(xml_file.read(), "html.parser")
self.init_ok = True
self.__load_xml()
Expand Down
19 changes: 13 additions & 6 deletions enocean/protocol/packet.py
Expand Up @@ -48,20 +48,26 @@ def __init__(self, packet_type, data=None, optional=None):
self.parse()

def __str__(self):
return '0x%02X %s %s %s' % (self.packet_type, [hex(o) for o in self.data], [hex(o) for o in self.optional], self.parsed)
return '0x%02X %s %s %s' % (
self.packet_type,
[hex(o) for o in self.data],
[hex(o) for o in self.optional],
self.parsed)

def __unicode__(self):
return self.__str__()

def __eq__(self, other):
return self.packet_type == other.packet_type and self.rorg == other.rorg and self.data == other.data and self.optional == other.optional
return self.packet_type == other.packet_type and self.rorg == other.rorg \
and self.data == other.data and self.optional == other.optional

@property
def _bit_data(self):
# First and last 5 bits are always defined, so the data we're modifying is between them...
# TODO: This is valid for the packets we're currently manipulating.
# Needs the redefinition of Packet.data -> Packet.message.
# Packet.data would then only have the actual, documented data-bytes. Packet.message would contain the whole message.
# Packet.data would then only have the actual, documented data-bytes.
# Packet.message would contain the whole message.
# See discussion in issue #14
return enocean.utils.to_bitarray(self.data[1:len(self.data) - 5], (len(self.data) - 6) * 8)

Expand Down Expand Up @@ -300,7 +306,8 @@ def __str__(self):
@staticmethod
def create(rorg, rorg_func, rorg_type, direction=None, command=None,
destination=None, sender=None, learn=False, **kwargs):
return Packet.create(PACKET.RADIO_ERP1, rorg, rorg_func, rorg_type, direction, command, destination, sender, learn, **kwargs)
return Packet.create(PACKET.RADIO_ERP1, rorg, rorg_func, rorg_type,
direction, command, destination, sender, learn, **kwargs)

@property
def sender_int(self):
Expand Down Expand Up @@ -339,7 +346,7 @@ def parse(self):
self.rorg_func = enocean.utils.from_bitarray(self._bit_data[DB3.BIT_7:DB3.BIT_1])
self.rorg_type = enocean.utils.from_bitarray(self._bit_data[DB3.BIT_1:DB2.BIT_2])
self.rorg_manufacturer = enocean.utils.from_bitarray(self._bit_data[DB2.BIT_2:DB0.BIT_7])
self.logger.debug('learn received, EEP detected, RORG: 0x%02X, FUNC: 0x%02X, TYPE: 0x%02X, Manufacturer: 0x%02X' % (self.rorg, self.rorg_func, self.rorg_type, self.rorg_manufacturer))
self.logger.debug('learn received, EEP detected, RORG: 0x%02X, FUNC: 0x%02X, TYPE: 0x%02X, Manufacturer: 0x%02X' % (self.rorg, self.rorg_func, self.rorg_type, self.rorg_manufacturer)) # noqa: E501

return super(RadioPacket, self).parse()

Expand Down Expand Up @@ -382,7 +389,7 @@ def parse(self):
self.unidirectional = not self._bit_data[DB6.BIT_7]
self.response_expected = not self._bit_data[DB6.BIT_6]
self.request_type = enocean.utils.from_bitarray(self._bit_data[DB6.BIT_5:DB6.BIT_3])
self.rorg_manufacturer = enocean.utils.from_bitarray(self._bit_data[DB3.BIT_2:DB2.BIT_7] + self._bit_data[DB4.BIT_7:DB3.BIT_7])
self.rorg_manufacturer = enocean.utils.from_bitarray(self._bit_data[DB3.BIT_2:DB2.BIT_7] + self._bit_data[DB4.BIT_7:DB3.BIT_7]) # noqa: E501
self.channel = self.data[2]
self.rorg_type = self.data[5]
self.rorg_func = self.data[6]
Expand Down
8 changes: 4 additions & 4 deletions enocean/protocol/tests/test_eep.py
Expand Up @@ -23,10 +23,10 @@ def test_temperature():
assert packet.parsed['TMP']['raw_value'] == 85
assert packet.learn is False
assert packet.contains_eep is False
assert packet.rorg is 0xA5
assert packet.rorg is int(RORG.BS4)
assert packet.rorg_func is 0x02
assert packet.rorg_type is 0x05
assert packet.rorg == 0xA5
assert packet.rorg == int(RORG.BS4)
assert packet.rorg_func == 0x02
assert packet.rorg_type == 0x05
assert packet.status == 0x00
assert packet.repeater_count == 0
assert packet.sender == [0x01, 0x81, 0xB7, 0x44]
Expand Down
5 changes: 4 additions & 1 deletion enocean/protocol/tests/test_packet.py
Expand Up @@ -182,7 +182,10 @@ def test_packet_equals():
_, _, packet_1 = Packet.parse_msg(data_1)
_, _, packet_2 = Packet.parse_msg(data_2)

assert str(packet_1) == '0x%02X %s %s %s' % (packet_1.packet_type, [hex(o) for o in packet_1.data], [hex(o) for o in packet_1.optional], packet_1.parsed)
assert str(packet_1) == '0x%02X %s %s %s' % (packet_1.packet_type,
[hex(o) for o in packet_1.data],
[hex(o) for o in packet_1.optional],
packet_1.parsed)
assert str(packet_1) == str(packet_2)
assert packet_1 == packet_2

Expand Down
28 changes: 19 additions & 9 deletions enocean/protocol/tests/test_packet_creation.py
Expand Up @@ -82,7 +82,8 @@ def test_packet_assembly():
assert packet.rorg_type == 0x01

# Test the easier method of sending packets.
packet = Packet.create(PACKET.RADIO_ERP1, rorg=RORG.BS4, rorg_func=0x20, rorg_type=0x01, learn=True, direction=1, **prop)
packet = Packet.create(PACKET.RADIO_ERP1, rorg=RORG.BS4, rorg_func=0x20, rorg_type=0x01,
learn=True, direction=1, **prop)
packet_serialized = packet.build()
assert len(packet_serialized) == len(PACKET_CONTENT_3)
assert list(packet_serialized) == list(PACKET_CONTENT_3)
Expand All @@ -109,7 +110,8 @@ def test_temperature():
0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
0x5C
])
packet = RadioPacket.create(rorg=RORG.BS4, rorg_func=0x02, rorg_type=0x05, sender=[0x01, 0x81, 0xB7, 0x44], TMP=26.66666666666666666666666666666666666666666667)
packet = RadioPacket.create(rorg=RORG.BS4, rorg_func=0x02, rorg_type=0x05,
sender=[0x01, 0x81, 0xB7, 0x44], TMP=26.66666666666666666666666666666666666666666667)
packet_serialized = packet.build()
assert len(packet_serialized) == len(TEMPERATURE)
assert list(packet_serialized) == list(TEMPERATURE)
Expand All @@ -123,7 +125,8 @@ def test_temperature():
0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
0xE0
])
packet = RadioPacket.create(rorg=RORG.BS4, rorg_func=0x02, rorg_type=0x05, sender=[0x01, 0x81, 0xB7, 0x44], learn=True, TMP=26.66666666666666666666666666666666666666666667)
packet = RadioPacket.create(rorg=RORG.BS4, rorg_func=0x02, rorg_type=0x05, sender=[0x01, 0x81, 0xB7, 0x44],
learn=True, TMP=26.66666666666666666666666666666666666666666667)
packet_serialized = packet.build()
assert len(packet_serialized) == len(TEMPERATURE)
assert packet.learn is True
Expand All @@ -140,7 +143,8 @@ def test_magnetic_switch():
0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
0xBA
])
packet = RadioPacket.create(rorg=RORG.BS1, rorg_func=0x00, rorg_type=0x01, sender=[0x01, 0x82, 0x5D, 0xAB], CO='open')
packet = RadioPacket.create(rorg=RORG.BS1, rorg_func=0x00, rorg_type=0x01, sender=[0x01, 0x82, 0x5D, 0xAB],
CO='open')
packet_serialized = packet.build()
assert len(packet_serialized) == len(MAGNETIC_SWITCH)
assert list(packet_serialized) == list(MAGNETIC_SWITCH)
Expand All @@ -154,7 +158,8 @@ def test_magnetic_switch():
0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
0x06
])
packet = RadioPacket.create(rorg=RORG.BS1, rorg_func=0x00, rorg_type=0x01, sender=[0x01, 0x82, 0x5D, 0xAB], learn=True, CO='open')
packet = RadioPacket.create(rorg=RORG.BS1, rorg_func=0x00, rorg_type=0x01, sender=[0x01, 0x82, 0x5D, 0xAB],
learn=True, CO='open')
packet_serialized = packet.build()
assert len(packet_serialized) == len(MAGNETIC_SWITCH)
assert list(packet_serialized) == list(MAGNETIC_SWITCH)
Expand All @@ -169,7 +174,8 @@ def test_magnetic_switch():
0x2E
])

packet = RadioPacket.create(rorg=RORG.BS1, rorg_func=0x00, rorg_type=0x01, sender=[0x01, 0x82, 0x5D, 0xAB], CO='closed')
packet = RadioPacket.create(rorg=RORG.BS1, rorg_func=0x00, rorg_type=0x01, sender=[0x01, 0x82, 0x5D, 0xAB],
CO='closed')
packet_serialized = packet.build()
assert len(packet_serialized) == len(MAGNETIC_SWITCH)
assert list(packet_serialized) == list(MAGNETIC_SWITCH)
Expand All @@ -184,7 +190,8 @@ def test_magnetic_switch():
0x92
])

packet = RadioPacket.create(rorg=RORG.BS1, rorg_func=0x00, rorg_type=0x01, sender=[0x01, 0x82, 0x5D, 0xAB], learn=True, CO='closed')
packet = RadioPacket.create(rorg=RORG.BS1, rorg_func=0x00, rorg_type=0x01, sender=[0x01, 0x82, 0x5D, 0xAB],
learn=True, CO='closed')
packet_serialized = packet.build()
assert len(packet_serialized) == len(MAGNETIC_SWITCH)
assert list(packet_serialized) == list(MAGNETIC_SWITCH)
Expand Down Expand Up @@ -257,7 +264,9 @@ def test_packets_with_destination():
0x03, 0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0x00,
0x5F
])
packet = RadioPacket.create(rorg=RORG.BS4, rorg_func=0x02, rorg_type=0x05, sender=[0x01, 0x81, 0xB7, 0x44], destination=[0xDE, 0xAD, 0xBE, 0xEF], TMP=26.66666666666666666666666666666666666666666667)
packet = RadioPacket.create(rorg=RORG.BS4, rorg_func=0x02, rorg_type=0x05, sender=[0x01, 0x81, 0xB7, 0x44],
destination=[0xDE, 0xAD, 0xBE, 0xEF],
TMP=26.66666666666666666666666666666666666666666667)
packet_serialized = packet.build()
assert len(packet_serialized) == len(TEMPERATURE)
assert list(packet_serialized) == list(TEMPERATURE)
Expand All @@ -273,7 +282,8 @@ def test_packets_with_destination():
0x03, 0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0x00,
0xB9
])
packet = RadioPacket.create(rorg=RORG.BS1, rorg_func=0x00, rorg_type=0x01, sender=[0x01, 0x82, 0x5D, 0xAB], destination=[0xDE, 0xAD, 0xBE, 0xEF], CO='open')
packet = RadioPacket.create(rorg=RORG.BS1, rorg_func=0x00, rorg_type=0x01, sender=[0x01, 0x82, 0x5D, 0xAB],
destination=[0xDE, 0xAD, 0xBE, 0xEF], CO='open')
packet_serialized = packet.build()
assert len(packet_serialized) == len(MAGNETIC_SWITCH)
assert list(packet_serialized) == list(MAGNETIC_SWITCH)
Expand Down

0 comments on commit 697eda1

Please sign in to comment.