Skip to content
Snippets Groups Projects
Commit 627af5e1 authored by Daniel Meißner's avatar Daniel Meißner Committed by Daniel Meißner
Browse files

introduced basic integration tests and fixed first bugs

parent b5b5307a
No related branches found
No related tags found
No related merge requests found
[run]
omit = tests/*
......@@ -3,3 +3,4 @@ __pycache__
*autosave
*egg-info
.cache
.coverage
......@@ -2,6 +2,12 @@
echo:
@echo "clean | remove pyc files"
@echo "test | run tests with pytest"
clean:
find . -name "*pyc" -delete
find . -name "__pycache__" -delete
test:
py.test2 --cov
......@@ -16,6 +16,22 @@
* 100 GB of disc space
* HackRF One, rad1o or RTL-SDR DVB-T stick
## Tests
There are several integration tests available.
To run the tests you have to ensure, that the package is installed or
egg-infos are present in the project directory to have the right paths for
includes:
```
pip install -e .
```
After all paths are clear you are able to run "pytest":http//pytest.org
```
py.test
```
## Licence
Copyright (c) 2015, Daniel Meißner <daniel.meissner@smail.inf.h-brs.de>
......
......@@ -29,7 +29,7 @@ class Hardware(object):
lsusb_output = subprocess.check_output("lsusb", shell=True)
for line in lsusb_output.split("\n"):
if re.match("^Bus", line):
device = self._parse_lsusb_line(line)
device = self.parse_lsusb_line(line)
devices.append(device)
else:
continue
......@@ -44,7 +44,7 @@ class Hardware(object):
connected_devices = []
for device in devices:
if self._supported_device(self, device):
if self.supported_device(self, device):
connected_devices.append(device)
else:
continue
......@@ -52,7 +52,7 @@ class Hardware(object):
return connected_devices
@staticmethod
def _parse_lsusb_line(line):
def parse_lsusb_line(line):
"""
Splitt lsusb line in useful key values.
"""
......@@ -60,14 +60,14 @@ class Hardware(object):
device_unsorted = line.split(" ")
device['bus'] = device_unsorted[1]
device['device'] = device_unsorted[3]
device['device'] = re.match(r"(?P<id>\d+)", device_unsorted[3]).group()
device['id'] = device_unsorted[5]
device['name'] = " ".join(device_unsorted[6:])
return device
@staticmethod
def _supported_device(self, device):
def supported_device(self, device):
"""
Check if a given device is supported.
"""
......
[pytest]
addopts = --cov
setup.py 0 → 100644
#!/usr/bin/env python2.7
# -*- encoding: utf-8 -*-
from setuptools import setup
from lib.version import __version__
setup(name="Spectrum Usage",
version=__version__,
description="RF application to measure spectrum usage in specific frequencies.",
author="Daniel Meißner",
author_email="daniel.meissner@smail.inf.h-brs.de",
url="https://git.fslab.de/dmeiss2s/su",
license="GNU General Public License v3 (GPLv3)",
platform=["linux2"],
test_suite="tests",
classifiers=["Operating System :: POSIX",
"Programming Language :: Python :: 2.7"])
# -*- encoding: utf-8 -*-
import pytest
from os.path import expanduser
from lib.disk import Disk
class TestDisk:
def test_free_disk_space(self):
assert Disk.free_disk_space("/etca") == None
assert type(Disk.free_disk_space(expanduser("~"))) == int
def test_path_writeble(self):
assert Disk.path_writeble("/etca") == False
assert Disk.path_writeble("/etc/passwd") == False
assert Disk.path_writeble(expanduser("~")) == True
def test_sizeof_fmt(self):
assert Disk.sizeof_fmt(2691532) == "2.6 MiB"
# -*- encoding: utf-8 -*-
import pytest
from lib.hardware import Hardware
class TestHardware:
def test_parse_lsusb_line(self):
line = "Bus 006 Device 035: ID 0bda:2838 Realtek Semiconductor Corp. "\
"RTL2838 DVB-T"
dev = Hardware.parse_lsusb_line(line)
assert dev["id"] == "0bda:2838"
assert dev["name"] == "Realtek Semiconductor Corp. RTL2838 DVB-T"
assert dev["bus"] == "006"
assert dev["device"] == "035"
def test_supported_device(self):
not_supported_device = {"id": "ffff:ffff"}
supported_device = {"id": "0bda:2838"}
assert Hardware.supported_device(Hardware(), not_supported_device) \
== False
assert Hardware.supported_device(Hardware(), supported_device) \
== True
def test_supported_hardware(self):
assert type(Hardware.SUPPORTED_HARDWARE) == dict
assert len(Hardware.SUPPORTED_HARDWARE) != 0
# -*- encoding: utf-8 -*-
import pytest
from lib.version import __version__
class TestVersion:
def test_version(self):
assert type(__version__ ) == str
assert len(__version__.split(".")) == 3
# -*- encoding: utf-8 -*-
import pytest
import re
from lib.su import Su
from lib.version import __version__
class TestSu:
def test_version(self):
assert __version__ == Su.version()
assert type(Su.version()) == str
def test_name(self):
assert type(Su.name()) == str
def test_short_name(self):
assert type(Su.short_name()) == str
def test_name_and_version(self):
assert re.search(Su.name(), Su.name_and_version()) != None
assert re.search(Su.version(), Su.name_and_version()) != None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment