| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
import gpiod |
| 5 |
import os |
| 6 |
import unittest |
| 7 |
|
| 8 |
from . import gpiosim |
| 9 |
from .helpers import LinkGuard |
| 10 |
from unittest import TestCase |
| 11 |
|
| 12 |
|
| 13 |
class IsGPIOChip(TestCase): |
| 14 |
def test_is_gpiochip_bad(self): |
| 15 |
self.assertFalse(gpiod.is_gpiochip_device("/dev/null")) |
| 16 |
self.assertFalse(gpiod.is_gpiochip_device("/dev/nonexistent")) |
| 17 |
|
| 18 |
def test_is_gpiochip_invalid_argument(self): |
| 19 |
with self.assertRaises(TypeError): |
| 20 |
gpiod.is_gpiochip_device(4) |
| 21 |
|
| 22 |
def test_is_gpiochip_superfluous_argument(self): |
| 23 |
with self.assertRaises(TypeError): |
| 24 |
gpiod.is_gpiochip_device("/dev/null", 4) |
| 25 |
|
| 26 |
def test_is_gpiochip_missing_argument(self): |
| 27 |
with self.assertRaises(TypeError): |
| 28 |
gpiod.is_gpiochip_device() |
| 29 |
|
| 30 |
def test_is_gpiochip_good(self): |
| 31 |
sim = gpiosim.Chip() |
| 32 |
self.assertTrue(gpiod.is_gpiochip_device(sim.dev_path)) |
| 33 |
|
| 34 |
def test_is_gpiochip_good_keyword_argument(self): |
| 35 |
sim = gpiosim.Chip() |
| 36 |
self.assertTrue(gpiod.is_gpiochip_device(path=sim.dev_path)) |
| 37 |
|
| 38 |
def test_is_gpiochip_link_good(self): |
| 39 |
link = "/tmp/gpiod-py-test-link.{}".format(os.getpid()) |
| 40 |
sim = gpiosim.Chip() |
| 41 |
|
| 42 |
with LinkGuard(sim.dev_path, link): |
| 43 |
self.assertTrue(gpiod.is_gpiochip_device(link)) |
| 44 |
|
| 45 |
def test_is_gpiochip_link_bad(self): |
| 46 |
link = "/tmp/gpiod-py-test-link.{}".format(os.getpid()) |
| 47 |
|
| 48 |
with LinkGuard("/dev/null", link): |
| 49 |
self.assertFalse(gpiod.is_gpiochip_device(link)) |
| 50 |
|
| 51 |
|
| 52 |
class VersionString(TestCase): |
| 53 |
|
| 54 |
VERSION_PATTERN = "^\\d+\\.\\d+(\\.\\d+|\\-devel|\\-rc\\d+)?$" |
| 55 |
|
| 56 |
def test_api_version_string(self): |
| 57 |
self.assertRegex(gpiod.api_version, VersionString.VERSION_PATTERN) |
| 58 |
|
| 59 |
def test_module_version(self): |
| 60 |
self.assertRegex(gpiod.__version__, VersionString.VERSION_PATTERN) |