LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | List of all members
astshim.test.ObjectTestCase Class Reference
Inheritance diagram for astshim.test.ObjectTestCase:
astshim.test.MappingTestCase

Public Member Functions

def assertObjectsIdentical (self, obj1, obj2, checkType=True)
 
def checkCopy (self, obj)
 
def checkPersistence (self, obj, typeFromChannel=None)
 

Detailed Description

Base class for unit tests of objects

Definition at line 14 of file test.py.

Member Function Documentation

◆ assertObjectsIdentical()

def astshim.test.ObjectTestCase.assertObjectsIdentical (   self,
  obj1,
  obj2,
  checkType = True 
)
Assert that two astshim objects are identical.

Identical means the objects are of the same class (if checkType)
and all properties are identical (including whether set or defaulted).

Definition at line 18 of file test.py.

18  def assertObjectsIdentical(self, obj1, obj2, checkType=True):
19  """Assert that two astshim objects are identical.
20 
21  Identical means the objects are of the same class (if checkType)
22  and all properties are identical (including whether set or defaulted).
23  """
24  if checkType:
25  self.assertIs(type(obj1), type(obj2))
26  self.assertEqual(obj1.show(), obj2.show())
27  self.assertEqual(str(obj1), str(obj2))
28  self.assertEqual(repr(obj1), repr(obj2))
29 
table::Key< int > type
Definition: Detector.cc:163

◆ checkCopy()

def astshim.test.ObjectTestCase.checkCopy (   self,
  obj 
)
Check that an astshim object can be deep-copied

Definition at line 30 of file test.py.

30  def checkCopy(self, obj):
31  """Check that an astshim object can be deep-copied
32  """
33  nobj = obj.getNObject()
34  nref = obj.getRefCount()
35 
36  def copyIter(obj):
37  yield obj.copy()
38  yield type(obj)(obj)
39 
40  for cp in copyIter(obj):
41  self.assertObjectsIdentical(obj, cp)
42  self.assertEqual(obj.getNObject(), nobj + 1)
43  # Object.copy makes a new pointer instead of copying the old one,
44  # so the reference count of the old one does not increase
45  self.assertEqual(obj.getRefCount(), nref)
46  self.assertFalse(obj.same(cp))
47  self.assertEqual(cp.getNObject(), nobj + 1)
48  self.assertEqual(cp.getRefCount(), 1)
49  # changing an attribute of the copy does not affect the original
50  originalIdent = obj.ident
51  cp.ident = obj.ident + " modified"
52  self.assertEqual(obj.ident, originalIdent)
53 
54  del cp
55  self.assertEqual(obj.getNObject(), nobj)
56  self.assertEqual(obj.getRefCount(), nref)
57 

◆ checkPersistence()

def astshim.test.ObjectTestCase.checkPersistence (   self,
  obj,
  typeFromChannel = None 
)
Check that an astshim object can be persisted and unpersisted

@param[in] obj  Object to be checked
@param[in] typeFromChannel  Type of object expected to be read from
                a channel (since some thin wrapper types are read
                as the underlying type); None if the original type

Check persistence using Channel, FitsChan (with native encoding,
as the only encoding compatible with all AST objects), XmlChan
and pickle.

Definition at line 58 of file test.py.

58  def checkPersistence(self, obj, typeFromChannel=None):
59  """Check that an astshim object can be persisted and unpersisted
60 
61  @param[in] obj Object to be checked
62  @param[in] typeFromChannel Type of object expected to be read from
63  a channel (since some thin wrapper types are read
64  as the underlying type); None if the original type
65 
66  Check persistence using Channel, FitsChan (with native encoding,
67  as the only encoding compatible with all AST objects), XmlChan
68  and pickle.
69  """
70  for channelType, options in (
71  (Channel, ""),
72  (FitsChan, "Encoding=Native"),
73  (XmlChan, ""),
74  ):
75  ss = StringStream()
76  chan = channelType(ss, options)
77  chan.write(obj)
78  ss.sinkToSource()
79  if channelType is FitsChan:
80  chan.clearCard()
81  obj_copy = chan.read()
82  if typeFromChannel is not None:
83  self.assertIs(type(obj_copy), typeFromChannel)
84  self.assertObjectsIdentical(obj, obj_copy, checkType=False)
85  else:
86  self.assertObjectsIdentical(obj, obj_copy)
87 
88  obj_copy = pickle.loads(pickle.dumps(obj))
89  self.assertObjectsIdentical(obj, obj_copy)
90 
91 

The documentation for this class was generated from the following file: