Coverage for tests/test_xmlChan.py: 29%

44 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2022-09-11 00:57 -0700

1import os.path 

2import unittest 

3 

4import astshim as ast 

5from astshim.test import ObjectTestCase 

6 

7 

8class TestXmlChan(ObjectTestCase): 

9 

10 def setUp(self): 

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

12 

13 def test_XmlChanDefaultAttributes(self): 

14 sstream = ast.StringStream() 

15 chan = ast.XmlChan(sstream) 

16 self.assertEqual(chan.xmlFormat, "NATIVE") 

17 self.assertEqual(chan.xmlLength, 0) 

18 self.assertEqual(chan.xmlPrefix, "") 

19 

20 zoommap = ast.ZoomMap(3, 2.0) 

21 self.checkXmlPersistence(sstream=sstream, chan=chan, obj=zoommap) 

22 

23 def test_XmlChanSpecifiedAttributes(self): 

24 sstream = ast.StringStream() 

25 chan = ast.XmlChan( 

26 sstream, 'XmlFormat="QUOTED", XmlLength=2000, XmlPrefix="foo"') 

27 self.assertEqual(chan.xmlFormat, "QUOTED") 

28 self.assertEqual(chan.xmlLength, 2000) 

29 self.assertEqual(chan.xmlPrefix, "foo") 

30 zoommap = ast.ZoomMap(4, 1.5) 

31 self.checkXmlPersistence(sstream=sstream, chan=chan, obj=zoommap) 

32 

33 def test_XmlChanSetAttributes(self): 

34 sstream = ast.StringStream() 

35 chan = ast.XmlChan(sstream) 

36 chan.xmlFormat = "QUOTED" 

37 chan.xmlLength = 1500 

38 chan.xmlPrefix = "test" 

39 self.assertEqual(chan.xmlFormat, "QUOTED") 

40 self.assertEqual(chan.xmlLength, 1500) 

41 self.assertEqual(chan.xmlPrefix, "test") 

42 zoommap = ast.ZoomMap(1, 0.5) 

43 self.checkXmlPersistence(sstream=sstream, chan=chan, obj=zoommap) 

44 

45 def checkXmlPersistence(self, sstream, chan, obj): 

46 """Check that an Ast object can be persisted and unpersisted 

47 """ 

48 chan.write(obj) 

49 sstream.sinkToSource() 

50 obj_copy = chan.read() 

51 self.assertEqual(obj.className, obj_copy.className) 

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

53 self.assertEqual(str(obj), str(obj_copy)) 

54 self.assertEqual(repr(obj), repr(obj_copy)) 

55 

56 

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

58 unittest.main()