Coverage for tests/test_channel.py: 22%
46 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-20 03:51 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-20 03:51 -0700
1import filecmp
2import os
3import unittest
5import astshim as ast
6from astshim.test import MappingTestCase
9class TestChannel(MappingTestCase):
11 def setUp(self):
12 self.dataDir = os.path.join(os.path.dirname(__file__), "data")
14 def test_ChannelFileStream(self):
15 path1 = os.path.join(self.dataDir, "channelFileStream1.txt")
16 path2 = os.path.join(self.dataDir, "channelFileStream2.txt")
18 outstream = ast.FileStream(path1, True)
19 outchan = ast.Channel(outstream)
20 self.assertIsInstance(outchan, ast.Object)
21 self.assertIsInstance(outchan, ast.Channel)
23 zoommap = ast.ZoomMap(2, 0.1, "ID=Hello there")
24 nobj = outchan.write(zoommap)
25 self.assertEqual(nobj, 1)
27 with self.assertRaises(RuntimeError):
28 obj = outchan.read()
30 instream = ast.FileStream(path1, False)
31 inchan = ast.Channel(instream)
32 obj = inchan.read()
33 self.assertEqual(obj.show(), zoommap.show())
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)
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()
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)
59if __name__ == "__main__": 59 ↛ 60line 59 didn't jump to line 60, because the condition on line 59 was never true
60 unittest.main()