Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

import os.path 

import unittest 

 

import astshim as ast 

from astshim.test import ObjectTestCase 

 

 

class TestXmlChan(ObjectTestCase): 

 

def setUp(self): 

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

 

def test_XmlChanDefaultAttributes(self): 

sstream = ast.StringStream() 

chan = ast.XmlChan(sstream) 

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

self.assertEqual(chan.xmlLength, 0) 

self.assertEqual(chan.xmlPrefix, "") 

 

zoommap = ast.ZoomMap(3, 2.0) 

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

 

def test_XmlChanSpecifiedAttributes(self): 

sstream = ast.StringStream() 

chan = ast.XmlChan( 

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

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

self.assertEqual(chan.xmlLength, 2000) 

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

zoommap = ast.ZoomMap(4, 1.5) 

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

 

def test_XmlChanSetAttributes(self): 

sstream = ast.StringStream() 

chan = ast.XmlChan(sstream) 

chan.xmlFormat = "QUOTED" 

chan.xmlLength = 1500 

chan.xmlPrefix = "test" 

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

self.assertEqual(chan.xmlLength, 1500) 

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

zoommap = ast.ZoomMap(1, 0.5) 

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

 

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

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

""" 

chan.write(obj) 

sstream.sinkToSource() 

obj_copy = chan.read() 

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

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

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

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

 

 

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

unittest.main()