Coverage for tests/test_channel.py: 23%

46 statements  

« prev     ^ index     » next       coverage.py v7.2.1, created at 2023-03-12 01:17 -0800

1import filecmp 

2import os 

3import unittest 

4 

5import astshim as ast 

6from astshim.test import MappingTestCase 

7 

8 

9class TestChannel(MappingTestCase): 

10 

11 def setUp(self): 

12 self.dataDir = os.path.join(os.path.dirname(__file__), "data") 

13 

14 def test_ChannelFileStream(self): 

15 path1 = os.path.join(self.dataDir, "channelFileStream1.txt") 

16 path2 = os.path.join(self.dataDir, "channelFileStream2.txt") 

17 

18 outstream = ast.FileStream(path1, True) 

19 outchan = ast.Channel(outstream) 

20 self.assertIsInstance(outchan, ast.Object) 

21 self.assertIsInstance(outchan, ast.Channel) 

22 

23 zoommap = ast.ZoomMap(2, 0.1, "ID=Hello there") 

24 nobj = outchan.write(zoommap) 

25 self.assertEqual(nobj, 1) 

26 

27 with self.assertRaises(RuntimeError): 

28 obj = outchan.read() 

29 

30 instream = ast.FileStream(path1, False) 

31 inchan = ast.Channel(instream) 

32 obj = inchan.read() 

33 self.assertEqual(obj.show(), zoommap.show()) 

34 

35 outstream2 = ast.FileStream(path2, True) 

36 outchan2 = ast.Channel(outstream2) 

37 outchan2.write(obj) 

38 self.assertTrue(filecmp.cmp(path1, path2, shallow=False)) 

39 os.remove(path1) 

40 os.remove(path2) 

41 

42 def test_ChannelStringStream(self): 

43 ss = ast.StringStream() 

44 channel = ast.Channel(ss) 

45 zoommap = ast.ZoomMap(2, 0.1, "ID=Hello there") 

46 n = channel.write(zoommap) 

47 self.assertEqual(n, 1) 

48 sinkData1 = ss.getSinkData() 

49 

50 ss.sinkToSource() 

51 obj = channel.read() 

52 self.assertEqual(obj.show(), zoommap.show()) 

53 n = channel.write(obj) 

54 self.assertEqual(n, 1) 

55 sinkData2 = ss.getSinkData() 

56 self.assertEqual(sinkData1, sinkData2) 

57 

58 

59if __name__ == "__main__": 59 ↛ 60line 59 didn't jump to line 60, because the condition on line 59 was never true

60 unittest.main()