import unittest
import spidev
from time import sleep
from opc import OPCN2
from opc.exceptions import SPIError, FirmwareError

class SetupTestCase(unittest.TestCase):

    def setUp(self):
        self.spi = spidev.SpiDev()
        self.spi.open(0, 0)
        self.spi.mode = 1
        self.spi.max_speed_hz = 500000

        self.alpha = OPCN2(self.spi)
        #self.assertRaises(SPIError, OPCN2, None)

    def tearDown(self):
        pass

    def test_spi(self):
        self.assertIsInstance(self.spi, spidev.SpiDev)

    def test_firmware(self):
        self.assertTrue(self.alpha.firmware in [14, 15, 16, 17])

    def test_opc(self):
        # Turn on the opc
        self.assertTrue(self.alpha.on())
        sleep(2)
        self.assertTrue(self.alpha.off())

    def test_ping(self):
        self.assertTrue(self.alpha.ping())

    #def test_read_info_string(self):
        #sleep(1)
        #infostring = self.alpha.read_info_string()

        #self.assertTrue('OPC-N2' in infostring)

    def test_read_config_variables(self):
        vars = self.alpha.read_config_variables()
        self.assertTrue(vars['Bin Boundary 0'] is not None)

    def test_write_config(self):
        pass

    def test_read_histogram(self):
        hist = self.alpha.read_histogram()

        self.assertTrue(hist is not None)
        self.assertTrue(hist['Temperature'] >= 0.0)

    def test_save_config(self):
        pass

    def test_bootloader_mode(self):
        pass

    def test_set_fan_power(self):
        #self.assertRaise(ValueError, self.alpha.set_fan_power, 300)
        self.assertTrue(self.alpha.set_fan_power(255))

    #def test_set_laser_power(self):
        #self.assertRaise(ValueError, self.alpha.set_laser_power(400))
        #sleep(2)
        #self.assertTrue(self.alpha.set_laser_power(150))

    def test_laser_settings(self):
        self.assertTrue(self.alpha.laser_on())
        sleep(2)
        self.assertTrue(self.alpha.laser_off())

    def test_fan_settings(self):
        self.assertTrue(self.alpha.fan_on())
        sleep(2)
        self.assertTrue(self.alpha.fan_off())


if __name__ == '__main__':
    unittest.main()

@@ -391,32 +391,949 @@
 , OPCN2, None)%0A%0A
+        self.assertIsInstance(self.spi, spidev.SpiDev)%0A%0A        self.assertTrue(self.alpha.firmware in %5B14, 15, 16, 17%5D)%0A%0A        self.assertTrue(self.alpha.on())%0A        sleep(2)%0A        self.assertTrue(self.alpha.off())%0A%0A        self.assertTrue(self.alpha.ping())%0A%0A        sleep(1)%0A        infostring = self.alpha.read_info_string()%0A%0A        self.assertTrue('OPC-N2' in infostring)%0A%0A        vars = self.alpha.read_config_variables()%0A        self.assertTrue(vars%5B'Bin Boundary 0'%5D is not None)%0A%0A        hist = self.alpha.read_histogram()%0A%0A        self.assertTrue(hist is not None)%0A        self.assertTrue(hist%5B'Temperature'%5D %3E= 0.0)%0A%0A        self.assertTrue(self.alpha.set_fan_power(255))%0A%0A        self.assertTrue(self.alpha.laser_on())%0A        sleep(2)%0A        self.assertTrue(self.alpha.laser_off())%0A%0A        self.assertTrue(self.alpha.fan_on())%0A        sleep(2)%0A        self.assertTrue(self.alpha.fan_off())%0A%0A'''%0A
     def tearDown
@@ -3011,16 +3011,19 @@
 _off())%0A
+'''
 %0A%0Aif __n

test all