import tempfile,unittest,csv
from pathlib import Path
from dashboard import acquire
class Tests(unittest.TestCase):
 def test_sim(self):
  with tempfile.TemporaryDirectory() as d:
   p=Path(d)/'log.csv';r=acquire('simulation','',10,3,2,p,'600,10000,0');self.assertEqual(r['wheel_per_clock_cycle'],'0.01'); self.assertEqual(r['encoder_edges'],600)
   acquire('simulation','',10,1,1,p,'1,2,1')
   with p.open() as f:self.assertEqual(len(list(csv.reader(f))),3)
 def test_bad(self):
  with tempfile.TemporaryDirectory() as d:
   for args in [('simulation','',0,1,1),('simulation','',1,0,1),('unqualified_hardware','',1,1,1),('bad','',1,1,1)]:
    with self.assertRaises(ValueError):acquire(*args,Path(d)/'x','1,2,0')
 def test_invalid(self):
  with tempfile.TemporaryDirectory() as d:
   r=acquire('simulation','',1,1,1,Path(d)/'x','10,0,0');self.assertEqual(r['wheel_per_clock_cycle'],'')
if __name__=='__main__':unittest.main()
