gate: start reorder
Signed-off-by: Thomas Klaehn <thomas.klaehn@u-blox.com>
This commit is contained in:
parent
0870736845
commit
c1012382f2
29
.gitlab-ci.yml
Normal file
29
.gitlab-ci.yml
Normal file
@ -0,0 +1,29 @@
|
||||
before_script:
|
||||
- "echo $CI_BUILD_ID"
|
||||
- "echo $CI_BUILD_REF_NAME"
|
||||
|
||||
stages:
|
||||
- test
|
||||
# - release
|
||||
|
||||
tests:
|
||||
stage: test
|
||||
script:
|
||||
- "python scripts/pylint_wrapper.py -s source -s tests"
|
||||
- "nosetests --with-coverage --cover-package=data_buffer --cover-package=engine --cover-package=gate --cover-package=light_sensor --cover-package=power_sensor --cover-xml"
|
||||
- "nosetests --with-xunit tests/unittests/"
|
||||
- "sonar-runner"
|
||||
|
||||
#releases:
|
||||
# stage: release
|
||||
# script:
|
||||
# - "python scripts/create_release_script.py"
|
||||
# - "cd source"
|
||||
# - "python release.py sdist"
|
||||
# - "cd .."
|
||||
# - "scripts/deploy_release.sh"
|
||||
# only:
|
||||
# - /^[0-9]{1,}.[0-9]{1,}.[0-9]{1,}$/
|
||||
# except:
|
||||
# - branches
|
||||
|
@ -1,7 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?eclipse-pydev version="1.0"?><pydev_project>
|
||||
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
|
||||
<path>/${PROJECT_DIR_NAME}/src</path>
|
||||
<path>/${PROJECT_DIR_NAME}/source</path>
|
||||
<path>/${PROJECT_DIR_NAME}/scripts</path>
|
||||
<path>/${PROJECT_DIR_NAME}/tests</path>
|
||||
</pydev_pathproperty>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
|
||||
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
|
||||
|
25
scripts/pylint_wrapper.py
Normal file
25
scripts/pylint_wrapper.py
Normal file
@ -0,0 +1,25 @@
|
||||
'''
|
||||
Created on Feb 11, 2017
|
||||
|
||||
@author: tkl
|
||||
'''
|
||||
import os
|
||||
import sys
|
||||
import getopt
|
||||
|
||||
def main(argv):
|
||||
options, _ = getopt.getopt(argv, "s:", ["source="])
|
||||
source_list = []
|
||||
for opt, args in options:
|
||||
if opt in ("-s", "--source"):
|
||||
source_list.append(args)
|
||||
|
||||
source_str = ""
|
||||
for source in source_list:
|
||||
source_str += source + " "
|
||||
|
||||
os.system("pylint " + source_str + " -r n --msg-template=\"{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}\" > pylint.txt")
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
11
sonar-project.properties
Normal file
11
sonar-project.properties
Normal file
@ -0,0 +1,11 @@
|
||||
sonar.projectKey=chickenhouse:python
|
||||
sonar.projectName=chickenhouse:python
|
||||
sonar.projectVersion=1.0
|
||||
sonar.host.url=http://sonarqube:9000
|
||||
sonar.sources=source
|
||||
sonar.tests=tests/unittests
|
||||
sonar.language=py
|
||||
sonar.sourceEncoding=UTF-8
|
||||
sonar.python.xunit.reportPath=nosetests.xml
|
||||
sonar.python.coverage.reportPath=coverage.xml
|
||||
sonar.python.pylint.reportPath=pylint.txt
|
@ -1,4 +1,3 @@
|
||||
import mymath
|
||||
|
||||
class DataBuffer(object):
|
||||
def __init__(self, length):
|
||||
@ -16,7 +15,7 @@ class DataBuffer(object):
|
||||
def average(self):
|
||||
if len(self.__data) != self.__max:
|
||||
return None
|
||||
return mymath.mean(self.__data)
|
||||
return sum(self.__data) / len(self.__data)
|
||||
|
||||
def length(self):
|
||||
return len(self.__data)
|
@ -1,54 +0,0 @@
|
||||
'''
|
||||
Created on Dec 19, 2016
|
||||
|
||||
@author: klaehn
|
||||
'''
|
||||
import paho.mqtt.client as mqtt_client
|
||||
|
||||
class Mqtt(object):
|
||||
''' Wrapper class for mqtt communication '''
|
||||
def __init__(self, hostname, port=1883, keepalive=60, qos=2, retain=True):
|
||||
#pylint: disable=too-many-arguments
|
||||
self.__hostname = hostname
|
||||
self.__port = port
|
||||
self.__keepalive = keepalive
|
||||
self.__client = mqtt_client.Client()
|
||||
self.__is_connected = False
|
||||
self.__qos = qos
|
||||
self.__retain = retain
|
||||
|
||||
def connect(self):
|
||||
''' Connect to mqtt broker '''
|
||||
if not self.__is_connected:
|
||||
res = self.__client.connect(self.__hostname, self.__port, \
|
||||
self.__keepalive)
|
||||
if res != mqtt_client.MQTT_ERR_SUCCESS:
|
||||
return False
|
||||
res = self.__client.loop_start()
|
||||
if res != mqtt_client.MQTT_ERR_SUCCESS:
|
||||
return False
|
||||
self.__is_connected = True
|
||||
return True
|
||||
return False
|
||||
|
||||
def disconnect(self):
|
||||
''' Disconnect from mqtt broker '''
|
||||
if self.__is_connected:
|
||||
self.__client.loop_stop()
|
||||
self.__client.disconnect()
|
||||
self.__is_connected = False
|
||||
return True
|
||||
return False
|
||||
|
||||
def transmit(self, topic, payload):
|
||||
''' Transmit to subscriber via broker'''
|
||||
was_connected = True
|
||||
if not self.__is_connected:
|
||||
was_connected = False
|
||||
self.connect()
|
||||
result = self.__client.publish(topic, payload, self.__qos, self.__retain)
|
||||
if not was_connected:
|
||||
self.disconnect()
|
||||
if result == 0:
|
||||
return True
|
||||
return False
|
@ -1,32 +0,0 @@
|
||||
from os.path import islink, isfile
|
||||
|
||||
class Gpio:
|
||||
DIRECTION_OUT = "out"
|
||||
DIRECTION_IN = "in"
|
||||
|
||||
def __init__(self, pin):
|
||||
self.pin = pin
|
||||
|
||||
def export(self):
|
||||
if not islink("/sys/class/gpio/gpio" + str(self.pin)):
|
||||
f = open("/sys/class/gpio/export", "w")
|
||||
f.write(str(self.pin))
|
||||
f.close()
|
||||
|
||||
def unexport(self):
|
||||
if islink("/sys/class/gpio/gpio" + str(self.pin)):
|
||||
f = open("/sys/class/gpio/unexport", "w")
|
||||
f.write(str(self.pin))
|
||||
f.close()
|
||||
|
||||
def direction(self, direction = DIRECTION_OUT):
|
||||
if isfile("/sys/class/gpio/gpio" + str(self.pin) + "/direction"):
|
||||
f = open("/sys/class/gpio/gpio" + str(self.pin) + "/direction", "w")
|
||||
f.write(direction)
|
||||
f.close()
|
||||
|
||||
def set(self, value = 0):
|
||||
if isfile("/sys/class/gpio/gpio" + str(self.pin) + "/value"):
|
||||
f = open("/sys/class/gpio/gpio" + str(self.pin) + "/value", "w")
|
||||
f.write(str(value))
|
||||
f.close()
|
@ -1,13 +0,0 @@
|
||||
"""
|
||||
Math helper functions
|
||||
"""
|
||||
|
||||
def mean(x_array):
|
||||
"""
|
||||
Calculate the mean.
|
||||
Input: x: array of x-values
|
||||
Return: mean
|
||||
"""
|
||||
if len(x_array) > 0:
|
||||
return sum(x_array) / len(x_array)
|
||||
return None
|
@ -1,29 +0,0 @@
|
||||
""" Unit tests for mymath module """
|
||||
import unittest
|
||||
import mymath
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
""" Test class for untit tests """
|
||||
def test_mean_even(self):
|
||||
""" Unit test for mean function """
|
||||
test_arr = [1,2,3,4,5]
|
||||
result = mymath.mean(test_arr)
|
||||
self.assertEqual(result, 3, "test_mean_even - exp: 3, res: " + str(result))
|
||||
|
||||
def test_mean_odd(self):
|
||||
""" Unit test for mean function """
|
||||
test_arr = [-1,2,-3,4,-5]
|
||||
result = mymath.mean(test_arr)
|
||||
self.assertEqual(result, -1, "test_mean_odd - exp: -1, res: " + str(result))
|
||||
|
||||
def test_mean_float(self):
|
||||
""" Unit test for mean function """
|
||||
test_arr = [1.9,2.007,3.4,4,50.678]
|
||||
result = mymath.mean(test_arr)
|
||||
self.assertEqual(result, 12.397, "test_mean_float - exp: 12.397, res: " + str(result))
|
||||
|
||||
def test_mean_empty(self):
|
||||
""" Unit test for mean function """
|
||||
test_arr = []
|
||||
result = mymath.mean(test_arr)
|
||||
self.assertIsNone(result)
|
@ -1,23 +0,0 @@
|
||||
|
||||
from re import match, sub
|
||||
|
||||
class wifi_fieldstrength:
|
||||
def __init__(self, name = "wlan0"):
|
||||
self._name = name
|
||||
self.wf_name = "/proc/net/wireless"
|
||||
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
def read(self):
|
||||
ret = False
|
||||
f = open(self.wf_name, "r")
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
mstr = "^" + self._name
|
||||
if match(mstr, line):
|
||||
line = sub("\s+", " ", line)
|
||||
tmp = line.split(" ")
|
||||
tmp[3] = sub("\.", "", tmp[3])
|
||||
ret = int(tmp[3])
|
||||
return ret
|
0
tests/unittests/__init__.py
Normal file
0
tests/unittests/__init__.py
Normal file
Loading…
Reference in New Issue
Block a user