Commit fe203284 authored by Federico Vaga's avatar Federico Vaga

unittest: test the locking attribute

It will verify that the behaviour of this attribute is correct

    python3 -m unittest -v SvecTestProgrammingLock.py
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@vaga.pv.it>
parent 7ba50cea
import random
import string
import unittest
class SvecTestProgrammingLock(unittest.TestCase):
def setUp(self):
self.file_path = "/sys/bus/vme/devices/vme.8/svec/svec.8/AFPGA/lock"
self.dev_path = "/dev/svec.8"
def test_01(self):
"""It flips the previous lock status"""
with open(self.file_path, "r") as f:
val = f.read().strip()
for i in range(2):
new = "lock" if val == "unlocked" else "unlock"
with open(self.file_path, "w") as f:
f.write(new)
with open(self.file_path, "r") as f:
val = f.read().strip()
self.assertEqual(val, "{}ed".format(new))
def test_02(self):
"""It writes invalid commands to the lock attribute"""
chars = (random.choice(string.ascii_uppercase) for _ in range(3))
with self.assertRaises(OSError):
with open(self.file_path) as f:
f.write(''.join(chars))
def test_03(self):
"""It unlocks the programming"""
with open(self.file_path, "w") as f:
f.write("unlock")
with open(self.file_path, "r") as f:
val = f.read().strip()
self.assertEqual(val, "unlocked")
# we should be able to open the device
with open(self.dev_path) as f:
pass
# It should lock automatically
with open(self.file_path, "r") as f:
val = f.read().strip()
self.assertEqual(val, "locked")
def test_04(self):
"""It locks the programming"""
with open(self.file_path, "w") as f:
f.write("lock")
with open(self.file_path, "r") as f:
val = f.read().strip()
self.assertEqual(val, "locked")
# we should not be able to open the device
with self.assertRaises(OSError):
f = open(self.dev_path)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment