forked from M-Labs/artiq
1
0
Fork 0

test: add test for exception on non-existent I2C bus

This commit is contained in:
Sebastien Bourdeauducq 2017-06-19 15:32:09 +08:00
parent d08bd58dff
commit 09d198c7a1
1 changed files with 16 additions and 0 deletions

View File

@ -2,6 +2,8 @@ import os, unittest
from artiq.experiment import *
from artiq.test.hardware_testbench import ExperimentCase
from artiq.coredevice.exceptions import I2CError
from artiq.coredevice.i2c import PCA9548
class I2CSwitch(EnvExperiment):
@ -19,7 +21,21 @@ class I2CSwitch(EnvExperiment):
self.set_dataset("passed", passed)
class NonexistentI2CBus(EnvExperiment):
def build(self):
self.setattr_device("core")
self.broken_switch = PCA9548(self._HasEnvironment__device_mgr, 255)
@kernel
def run(self):
self.broken_switch.set(0)
class I2CTest(ExperimentCase):
def test_i2c_switch(self):
self.execute(I2CSwitch)
self.assertTrue(self.dataset_mgr.get("passed"))
def test_nonexistent_bus(self):
with self.assertRaises(I2CError):
self.execute(NonexistentI2CBus)