LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
LSST Data Management Base Package
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
lsst.afw.typehandling.testUtils.MutableGenericMapTestBaseClass Class Reference
Inheritance diagram for lsst.afw.typehandling.testUtils.MutableGenericMapTestBaseClass:
lsst.afw.typehandling.testUtils.GenericMapTestBaseClass

Public Member Functions

def checkInsertItem (self, mapFactory, contents, msg="")
 
def checkSetdefault (self, mapFactory, contents, msg="")
 
def checkUpdateMapping (self, mapFactory, contents, msg="")
 
def checkUpdatePairs (self, mapFactory, contents, msg="")
 
def checkUpdateKwargs (self, mapFactory, contents, msg="")
 
def checkReplaceItem (self, genericMap, msg="")
 
def checkRemoveItem (self, mapFactory, contents, msg="")
 
def checkPop (self, mapFactory, contents, msg="")
 
def checkPopitem (self, mapFactory, contents, msg="")
 
def checkClear (self, mapFactory, contents, msg="")
 
def checkMutableViews (self, mapFactory, contents, msg="")
 
def getTestData (cls, keyClass)
 
def setUp (self)
 
def checkInitMapping (self, mapClass, contents, msg="")
 
def checkInitPairs (self, mapClass, contents, msg="")
 
def checkInitKwargs (self, mapClass, contents, msg="")
 
def checkFromKeysDefault (self, mapClass, keys, msg="")
 
def checkFromKeys (self, mapClass, keys, value, msg="")
 
def checkContains (self, genericMap, contents, msg="")
 
def checkContents (self, genericMap, contents, msg="")
 
def checkGet (self, genericMap, contents, msg="")
 
def checkIteration (self, genericMap, contents, msg="")
 
def checkViews (self, genericMap, contents, msg="")
 

Static Public Member Functions

def getValidKeys (mapClass)
 

Public Attributes

 longMessage
 

Detailed Description

Base class for unit tests of GenericMap that allow insertion/deletion.

Subclasses must call `MutableGenericMapTestBaseClass.setUp(self)`
if they provide their own version.

Definition at line 367 of file testUtils.py.

Member Function Documentation

◆ checkClear()

def lsst.afw.typehandling.testUtils.MutableGenericMapTestBaseClass.checkClear (   self,
  mapFactory,
  contents,
  msg = "" 
)
Check erasing a GenericMap.

Parameters
----------
mapFactory : callable
    A zero-argument callable that creates an empty
    `lsst.afw.typehandling.GenericMap` object of the type to be tested
contents : `Mapping`
    The key-value pairs initially occupying the map
msg : `str`
    Error message suffix describing test parameters

Definition at line 705 of file testUtils.py.

705  def checkClear(self, mapFactory, contents, msg=""):
706  """Check erasing a GenericMap.
707 
708  Parameters
709  ----------
710  mapFactory : callable
711  A zero-argument callable that creates an empty
712  `lsst.afw.typehandling.GenericMap` object of the type to be tested
713  contents : `Mapping`
714  The key-value pairs initially occupying the map
715  msg : `str`
716  Error message suffix describing test parameters
717  """
718  genericMap = self._fillMap(mapFactory, contents)
719  self.assertTrue(genericMap, msg=msg)
720 
721  genericMap.clear()
722  self.assertFalse(genericMap, msg=msg)
723  self.assertEqual(len(genericMap), 0, msg=msg)
724  for key in genericMap:
725  self.fail(f"Unexpected key: {key}", msg=msg)
726 

◆ checkContains()

def lsst.afw.typehandling.testUtils.GenericMapTestBaseClass.checkContains (   self,
  genericMap,
  contents,
  msg = "" 
)
inherited
Check the contents of a GenericMap.

Parameters
----------
genericMap : `lsst.afw.typehandling.GenericMap`
    The map to test.
contents : `Mapping`
    The key-value pairs that should be present in ``genericMap``
msg : `str`
    Error message suffix describing test parameters

Definition at line 262 of file testUtils.py.

262  def checkContains(self, genericMap, contents, msg=""):
263  """Check the contents of a GenericMap.
264 
265  Parameters
266  ----------
267  genericMap : `lsst.afw.typehandling.GenericMap`
268  The map to test.
269  contents : `Mapping`
270  The key-value pairs that should be present in ``genericMap``
271  msg : `str`
272  Error message suffix describing test parameters
273  """
274  for key in contents:
275  self.assertIn(key, genericMap, msg=msg)
276 
277  keyType = genericMap.dtype
278  for key in range(30):
279  if keyType(key) not in contents:
280  self.assertNotIn(keyType(key), genericMap, msg=msg)
281 
282  wrongType = float if keyType is not float else int
283  with self.assertRaises(TypeError):
284  wrongType(0) in genericMap
285 

◆ checkContents()

def lsst.afw.typehandling.testUtils.GenericMapTestBaseClass.checkContents (   self,
  genericMap,
  contents,
  msg = "" 
)
inherited
Check the contents of a GenericMap.

Parameters
----------
genericMap : `lsst.afw.typehandling.GenericMap`
    The map to test.
contents : `Mapping`
    The key-value pairs that should be present in ``genericMap``
msg : `str`
    Error message suffix describing test parameters

Definition at line 286 of file testUtils.py.

286  def checkContents(self, genericMap, contents, msg=""):
287  """Check the contents of a GenericMap.
288 
289  Parameters
290  ----------
291  genericMap : `lsst.afw.typehandling.GenericMap`
292  The map to test.
293  contents : `Mapping`
294  The key-value pairs that should be present in ``genericMap``
295  msg : `str`
296  Error message suffix describing test parameters
297  """
298  for key, value in contents.items():
299  self.assertEqual(genericMap[key], value, msg=msg)
300 
301  keyType = genericMap.dtype
302  for key in (keyType(key) for key in range(30) if keyType(key) not in contents):
303  with self.assertRaises(KeyError, msg=msg):
304  genericMap[key]
305 
306  wrongType = float if keyType is not float else int
307  with self.assertRaises(TypeError):
308  genericMap[wrongType(0)]
309 

◆ checkFromKeys()

def lsst.afw.typehandling.testUtils.GenericMapTestBaseClass.checkFromKeys (   self,
  mapClass,
  keys,
  value,
  msg = "" 
)
inherited
Check initialization using the ``fromkeys`` factory.

Parameters
----------
mapClass: `lsst.afw.typehandling.GenericMap`-type
    The class whose ``fromkeys`` method will be tested.
keys : `iterable`
    The keys to insert into the map.
value
    A legal value for a GenericMap.
msg : `str`
    Error message suffix describing test parameters

Definition at line 244 of file testUtils.py.

244  def checkFromKeys(self, mapClass, keys, value, msg=""):
245  """Check initialization using the ``fromkeys`` factory.
246 
247  Parameters
248  ----------
249  mapClass: `lsst.afw.typehandling.GenericMap`-type
250  The class whose ``fromkeys`` method will be tested.
251  keys : `iterable`
252  The keys to insert into the map.
253  value
254  A legal value for a GenericMap.
255  msg : `str`
256  Error message suffix describing test parameters
257  """
258  genericMap = mapClass.fromkeys(keys, value)
259  self.assertIsInstance(genericMap, mapClass, msg=msg)
260  self.checkContents(genericMap, dict.fromkeys(keys, value), msg=msg)
261 

◆ checkFromKeysDefault()

def lsst.afw.typehandling.testUtils.GenericMapTestBaseClass.checkFromKeysDefault (   self,
  mapClass,
  keys,
  msg = "" 
)
inherited
Check initialization using the ``fromkeys`` factory.

Unlike `checkFromKeys`, this method lets ``fromkeys`` use its default
value (which may give different behavior, in nonconforming
implementations, from explicitly passing `None`).

Parameters
----------
mapClass: `lsst.afw.typehandling.GenericMap`-type
    The class whose ``fromkeys`` method will be tested.
keys : `iterable`
    The keys to insert into the map.
msg : `str`
    Error message suffix describing test parameters

Definition at line 224 of file testUtils.py.

224  def checkFromKeysDefault(self, mapClass, keys, msg=""):
225  """Check initialization using the ``fromkeys`` factory.
226 
227  Unlike `checkFromKeys`, this method lets ``fromkeys`` use its default
228  value (which may give different behavior, in nonconforming
229  implementations, from explicitly passing `None`).
230 
231  Parameters
232  ----------
233  mapClass: `lsst.afw.typehandling.GenericMap`-type
234  The class whose ``fromkeys`` method will be tested.
235  keys : `iterable`
236  The keys to insert into the map.
237  msg : `str`
238  Error message suffix describing test parameters
239  """
240  genericMap = mapClass.fromkeys(keys)
241  self.assertIsInstance(genericMap, mapClass, msg=msg)
242  self.checkContents(genericMap, dict.fromkeys(keys), msg=msg)
243 

◆ checkGet()

def lsst.afw.typehandling.testUtils.GenericMapTestBaseClass.checkGet (   self,
  genericMap,
  contents,
  msg = "" 
)
inherited
Check that GenericMap.get works correctly.

Parameters
----------
genericMap : `lsst.afw.typehandling.GenericMap`
    The map to test.
contents : `Mapping`
    The key-value pairs that should be present in ``genericMap``
msg : `str`
    Error message suffix describing test parameters

Definition at line 310 of file testUtils.py.

310  def checkGet(self, genericMap, contents, msg=""):
311  """Check that GenericMap.get works correctly.
312 
313  Parameters
314  ----------
315  genericMap : `lsst.afw.typehandling.GenericMap`
316  The map to test.
317  contents : `Mapping`
318  The key-value pairs that should be present in ``genericMap``
319  msg : `str`
320  Error message suffix describing test parameters
321  """
322  default = "Not a default value"
323  for key, value in contents.items():
324  self.assertEqual(genericMap.get(key), value, msg=msg)
325  self.assertEqual(genericMap.get(key, default), value, msg=msg)
326 
327  keyType = genericMap.dtype
328  for key in (keyType(key) for key in range(30) if keyType(key) not in contents):
329  self.assertEqual(genericMap.get(key), None, msg=msg)
330  self.assertEqual(genericMap.get(key, default), default, msg=msg)
331 
332  wrongType = float if keyType is not float else int
333  with self.assertRaises(TypeError):
334  genericMap.get(wrongType(0))
335 

◆ checkInitKwargs()

def lsst.afw.typehandling.testUtils.GenericMapTestBaseClass.checkInitKwargs (   self,
  mapClass,
  contents,
  msg = "" 
)
inherited
Check bulk insertion from keywords into a GenericMap.

Parameters
----------
mapClass: `lsst.afw.typehandling.GenericMapS`-type
    The class whose ``__init__`` method will be tested.
    Must allow string keys.
contents : `Mapping`
    The key-value pairs to insert into the map
msg : `str`
    Error message suffix describing test parameters

Definition at line 205 of file testUtils.py.

205  def checkInitKwargs(self, mapClass, contents, msg=""):
206  """Check bulk insertion from keywords into a GenericMap.
207 
208  Parameters
209  ----------
210  mapClass: `lsst.afw.typehandling.GenericMapS`-type
211  The class whose ``__init__`` method will be tested.
212  Must allow string keys.
213  contents : `Mapping`
214  The key-value pairs to insert into the map
215  msg : `str`
216  Error message suffix describing test parameters
217  """
218  genericMap = mapClass(**contents)
219  self.checkContents(genericMap, contents, msg=msg)
220 
221  with self.assertRaises(TypeError, msg=msg):
222  mapClass(notAKey=GenericMapTestBaseClass.NotAStorable())
223 

◆ checkInitMapping()

def lsst.afw.typehandling.testUtils.GenericMapTestBaseClass.checkInitMapping (   self,
  mapClass,
  contents,
  msg = "" 
)
inherited
Check initialization from a mapping.

Parameters
----------
mapClass : `lsst.afw.typehandling.GenericMap`-type
    The class whose ``__init__`` method will be tested.
contents : `Mapping`
    The key-value pairs to insert into the map
msg : `str`
    Error message suffix describing test parameters

Definition at line 153 of file testUtils.py.

153  def checkInitMapping(self, mapClass, contents, msg=""):
154  """Check initialization from a mapping.
155 
156  Parameters
157  ----------
158  mapClass : `lsst.afw.typehandling.GenericMap`-type
159  The class whose ``__init__`` method will be tested.
160  contents : `Mapping`
161  The key-value pairs to insert into the map
162  msg : `str`
163  Error message suffix describing test parameters
164  """
165  for keyType in self.getValidKeys(mapClass):
166  genericMap = mapClass(contents)
167  self.checkContents(genericMap, contents, msg=msg)
168 
169  extraContents = {key: value for key, value in contents.items()} # contents need not define copy()
170  extraKey = keyType(101)
171  extraValue = 'Extra value'
172  extraContents[extraKey] = extraValue
173  genericMap = mapClass(contents, **{keyType(101): extraValue})
174  self.checkContents(genericMap, extraContents, msg=msg)
175 
176  with self.assertRaises(TypeError, msg=msg):
177  mapClass({keyType(0): GenericMapTestBaseClass.NotAStorable()})
178 

◆ checkInitPairs()

def lsst.afw.typehandling.testUtils.GenericMapTestBaseClass.checkInitPairs (   self,
  mapClass,
  contents,
  msg = "" 
)
inherited
Check initialization from an iterable of pairs.

Parameters
----------
mapClass: `lsst.afw.typehandling.GenericMap`-type
    The class whose ``__init__`` method will be tested.
contents : `Mapping`
    The key-value pairs to insert into the map
msg : `str`
    Error message suffix describing test parameters

Definition at line 179 of file testUtils.py.

179  def checkInitPairs(self, mapClass, contents, msg=""):
180  """Check initialization from an iterable of pairs.
181 
182  Parameters
183  ----------
184  mapClass: `lsst.afw.typehandling.GenericMap`-type
185  The class whose ``__init__`` method will be tested.
186  contents : `Mapping`
187  The key-value pairs to insert into the map
188  msg : `str`
189  Error message suffix describing test parameters
190  """
191  for keyType in self.getValidKeys(mapClass):
192  genericMap = mapClass(contents.items())
193  self.checkContents(genericMap, contents, msg=msg)
194 
195  extraContents = {key: value for key, value in contents.items()} # contents need not define copy()
196  extraKey = keyType(101)
197  extraValue = 'Extra value'
198  extraContents[extraKey] = extraValue
199  genericMap = mapClass(contents.items(), **{keyType(101): extraValue})
200  self.checkContents(genericMap, extraContents, msg=msg)
201 
202  with self.assertRaises(TypeError, msg=msg):
203  mapClass([(keyType(0), GenericMapTestBaseClass.NotAStorable())])
204 

◆ checkInsertItem()

def lsst.afw.typehandling.testUtils.MutableGenericMapTestBaseClass.checkInsertItem (   self,
  mapFactory,
  contents,
  msg = "" 
)
Check element insertion in a GenericMap.

Parameters
----------
mapFactory : callable
    A zero-argument callable that creates an empty
    `lsst.afw.typehandling.GenericMap` object of the type to be tested
contents : `Mapping`
    The key-value pairs to insert into the map
msg : `str`
    Error message suffix describing test parameters

Definition at line 430 of file testUtils.py.

430  def checkInsertItem(self, mapFactory, contents, msg=""):
431  """Check element insertion in a GenericMap.
432 
433  Parameters
434  ----------
435  mapFactory : callable
436  A zero-argument callable that creates an empty
437  `lsst.afw.typehandling.GenericMap` object of the type to be tested
438  contents : `Mapping`
439  The key-value pairs to insert into the map
440  msg : `str`
441  Error message suffix describing test parameters
442  """
443  genericMap = mapFactory()
444 
445  for length, (key, value) in enumerate(contents.items()):
446  loopMsg = f"{msg} Inserting {key!r}={value!r}"
447  genericMap[key] = value
448  self.assertEqual(len(genericMap), length+1, msg=loopMsg)
449  self.assertEqual(genericMap[key], value, msg=loopMsg)
450 
451  self.assertEqual(dict(genericMap), dict(contents), msg=msg)
452 
453  keyType = genericMap.dtype
454  with self.assertRaises(TypeError, msg=msg):
455  genericMap[keyType(0)] = GenericMapTestBaseClass.NotAStorable()
456 
457  wrongType = float if keyType is not float else int
458  with self.assertRaises(TypeError):
459  genericMap[wrongType(0)] = 0
460 

◆ checkIteration()

def lsst.afw.typehandling.testUtils.GenericMapTestBaseClass.checkIteration (   self,
  genericMap,
  contents,
  msg = "" 
)
inherited
Check the result of iterating over a GenericMap.

Parameters
----------
genericMap : `lsst.afw.typehandling.GenericMap`
    The map to test.
contents : `Mapping`
    The key-value pairs that should be present in ``genericMap``
msg : `str`
    Error message suffix describing test parameters

Definition at line 336 of file testUtils.py.

336  def checkIteration(self, genericMap, contents, msg=""):
337  """Check the result of iterating over a GenericMap.
338 
339  Parameters
340  ----------
341  genericMap : `lsst.afw.typehandling.GenericMap`
342  The map to test.
343  contents : `Mapping`
344  The key-value pairs that should be present in ``genericMap``
345  msg : `str`
346  Error message suffix describing test parameters
347  """
348  self.assertEqual({key: genericMap[key] for key in genericMap}, dict(contents), msg=msg)
349 

◆ checkMutableViews()

def lsst.afw.typehandling.testUtils.MutableGenericMapTestBaseClass.checkMutableViews (   self,
  mapFactory,
  contents,
  msg = "" 
)
Check that the views of a GenericMap update automatically.

This test supersedes `GenericMapTestBaseClass.checkViews`.

Parameters
----------
genericMap : `lsst.afw.typehandling.GenericMap`
    The map to test.
contents : `Mapping`
    The key-value pairs that should be present in ``genericMap``
msg : `str`
    Error message suffix describing test parameters

Definition at line 727 of file testUtils.py.

727  def checkMutableViews(self, mapFactory, contents, msg=""):
728  """Check that the views of a GenericMap update automatically.
729 
730  This test supersedes `GenericMapTestBaseClass.checkViews`.
731 
732  Parameters
733  ----------
734  genericMap : `lsst.afw.typehandling.GenericMap`
735  The map to test.
736  contents : `Mapping`
737  The key-value pairs that should be present in ``genericMap``
738  msg : `str`
739  Error message suffix describing test parameters
740  """
741  genericMap = mapFactory()
742  keyView = genericMap.keys()
743  valueView = genericMap.values()
744  itemView = genericMap.items()
745 
746  for view in (keyView, valueView, itemView):
747  self.assertEqual(len(view), len(genericMap), msg=msg)
748  # is initial state correct?
749  self.checkViews(genericMap, {}, msg)
750 
751  for key, value in contents.items():
752  genericMap[key] = value
753 
754  for view in (keyView, valueView, itemView):
755  self.assertEqual(len(view), len(genericMap), msg=msg)
756  # is final state correct?
757  self.checkViews(genericMap, contents, msg)

◆ checkPop()

def lsst.afw.typehandling.testUtils.MutableGenericMapTestBaseClass.checkPop (   self,
  mapFactory,
  contents,
  msg = "" 
)
Check that GenericMap.pop works correctly.

Parameters
----------
mapFactory : callable
    A zero-argument callable that creates an empty
    `lsst.afw.typehandling.GenericMap` object of the type to be tested
contents : `Mapping`
    The key-value pairs initially occupying the map
msg : `str`
    Error message suffix describing test parameters

Definition at line 642 of file testUtils.py.

642  def checkPop(self, mapFactory, contents, msg=""):
643  """Check that GenericMap.pop works correctly.
644 
645  Parameters
646  ----------
647  mapFactory : callable
648  A zero-argument callable that creates an empty
649  `lsst.afw.typehandling.GenericMap` object of the type to be tested
650  contents : `Mapping`
651  The key-value pairs initially occupying the map
652  msg : `str`
653  Error message suffix describing test parameters
654  """
655  genericMap = self._fillMap(mapFactory, contents)
656 
657  keyType = genericMap.dtype
658  with self.assertRaises(KeyError, msg=msg):
659  genericMap.pop(keyType(2019))
660 
661  default = "This is a default"
662  result = genericMap.pop(keyType(2019), default)
663  self.assertEqual(dict(genericMap), dict(contents), msg=msg)
664  self.assertEqual(result, default)
665 
666  wrongType = float if keyType is not float else int
667  with self.assertRaises(TypeError):
668  genericMap.pop(wrongType(0))
669 
670  itemsToRemove = list(contents.items())
671  np.random.shuffle(itemsToRemove)
672  for numPrevious, (rawKey, value) in enumerate(itemsToRemove):
673  key = keyType(rawKey)
674  loopMsg = f"{msg} Popping {key}={value}"
675  result = genericMap.pop(key)
676  self.assertEqual(len(genericMap), len(contents)-numPrevious-1, msg=loopMsg)
677  self.assertNotIn(key, genericMap, msg=loopMsg)
678  self.assertEqual(result, value, msg=loopMsg)
679 
daf::base::PropertyList * list
Definition: fits.cc:913

◆ checkPopitem()

def lsst.afw.typehandling.testUtils.MutableGenericMapTestBaseClass.checkPopitem (   self,
  mapFactory,
  contents,
  msg = "" 
)
Check that GenericMap.popitem works correctly.

Parameters
----------
mapFactory : callable
    A zero-argument callable that creates an empty
    `lsst.afw.typehandling.GenericMap` object of the type to be tested
contents : `Mapping`
    The key-value pairs initially occupying the map
msg : `str`
    Error message suffix describing test parameters

Definition at line 680 of file testUtils.py.

680  def checkPopitem(self, mapFactory, contents, msg=""):
681  """Check that GenericMap.popitem works correctly.
682 
683  Parameters
684  ----------
685  mapFactory : callable
686  A zero-argument callable that creates an empty
687  `lsst.afw.typehandling.GenericMap` object of the type to be tested
688  contents : `Mapping`
689  The key-value pairs initially occupying the map
690  msg : `str`
691  Error message suffix describing test parameters
692  """
693  genericMap = self._fillMap(mapFactory, contents)
694 
695  for numPrevious in range(len(genericMap)):
696  key, value = genericMap.popitem()
697  loopMsg = f"{msg} Popping {key}={value}"
698  self.assertIn((key, value), contents.items(), msg=loopMsg)
699  self.assertEqual(len(genericMap), len(contents)-numPrevious-1, msg=loopMsg)
700  self.assertNotIn(key, genericMap, msg=loopMsg)
701 
702  with self.assertRaises(KeyError, msg=msg):
703  genericMap.popitem()
704 

◆ checkRemoveItem()

def lsst.afw.typehandling.testUtils.MutableGenericMapTestBaseClass.checkRemoveItem (   self,
  mapFactory,
  contents,
  msg = "" 
)
Check element removal from a GenericMap.

Parameters
----------
mapFactory : callable
    A zero-argument callable that creates an empty
    `lsst.afw.typehandling.GenericMap` object of the type to be tested
contents : `Mapping`
    The key-value pairs initially occupying the map
msg : `str`
    Error message suffix describing test parameters

Definition at line 610 of file testUtils.py.

610  def checkRemoveItem(self, mapFactory, contents, msg=""):
611  """Check element removal from a GenericMap.
612 
613  Parameters
614  ----------
615  mapFactory : callable
616  A zero-argument callable that creates an empty
617  `lsst.afw.typehandling.GenericMap` object of the type to be tested
618  contents : `Mapping`
619  The key-value pairs initially occupying the map
620  msg : `str`
621  Error message suffix describing test parameters
622  """
623  genericMap = self._fillMap(mapFactory, contents)
624 
625  keyType = genericMap.dtype
626  with self.assertRaises(KeyError, msg=msg):
627  del genericMap[keyType(2019)]
628 
629  keysToRemove = list(contents.keys())
630  np.random.shuffle(keysToRemove)
631  for numPrevious, rawKey in enumerate(keysToRemove):
632  key = keyType(rawKey)
633  loopMsg = f"{msg} Deleting {key!r}"
634  del genericMap[key]
635  self.assertEqual(len(genericMap), len(contents)-numPrevious-1, msg=loopMsg)
636  self.assertNotIn(key, genericMap, msg=loopMsg)
637 
638  wrongType = float if keyType is not float else int
639  with self.assertRaises(TypeError):
640  del genericMap[wrongType(0)]
641 

◆ checkReplaceItem()

def lsst.afw.typehandling.testUtils.MutableGenericMapTestBaseClass.checkReplaceItem (   self,
  genericMap,
  msg = "" 
)
Check element replacement in a GenericMap.

Parameters
----------
genericMap : `lsst.afw.typehandling.GenericMap`
    The map to test. Must be empty.
msg : `str`
    Error message suffix describing test parameters

Definition at line 585 of file testUtils.py.

585  def checkReplaceItem(self, genericMap, msg=""):
586  """Check element replacement in a GenericMap.
587 
588  Parameters
589  ----------
590  genericMap : `lsst.afw.typehandling.GenericMap`
591  The map to test. Must be empty.
592  msg : `str`
593  Error message suffix describing test parameters
594  """
595  self.assertFalse(genericMap, msg=msg)
596  keyType = genericMap.dtype
597  key = keyType(42)
598 
599  for value in self.getTestData(keyType).values():
600  loopMsg = f"{msg} Inserting {key!r}={value!r}"
601  genericMap[key] = value # value may be of a different type
602  self.assertEqual(len(genericMap), 1, msg=loopMsg)
603  self.assertEqual(genericMap[key], value, msg=loopMsg)
604 
605  self.assertEqual(dict(genericMap), {key: value}, msg=msg)
606 
607  with self.assertRaises(TypeError, msg=msg):
608  genericMap[key] = GenericMapTestBaseClass.NotAStorable()
609 

◆ checkSetdefault()

def lsst.afw.typehandling.testUtils.MutableGenericMapTestBaseClass.checkSetdefault (   self,
  mapFactory,
  contents,
  msg = "" 
)
Check that GenericMap.setdefault works correctly.

Parameters
----------
mapFactory : callable
    A zero-argument callable that creates an empty
    `lsst.afw.typehandling.GenericMap` object of the type to be tested
contents : `Mapping`
    The key-value pairs to insert into the map
msg : `str`
    Error message suffix describing test parameters

Definition at line 461 of file testUtils.py.

461  def checkSetdefault(self, mapFactory, contents, msg=""):
462  """Check that GenericMap.setdefault works correctly.
463 
464  Parameters
465  ----------
466  mapFactory : callable
467  A zero-argument callable that creates an empty
468  `lsst.afw.typehandling.GenericMap` object of the type to be tested
469  contents : `Mapping`
470  The key-value pairs to insert into the map
471  msg : `str`
472  Error message suffix describing test parameters
473  """
474  genericMap = mapFactory()
475 
476  keyType = genericMap.dtype
477  result = genericMap.setdefault(keyType(0))
478  self.assertEqual(len(genericMap), 1, msg=msg)
479  self.assertIsNone(result, msg=msg)
480  self.assertIsNone(genericMap[keyType(0)], msg=msg)
481  del genericMap[keyType(0)]
482 
483  default = "This is a default"
484  for length, (key, _) in enumerate(contents.items()):
485  loopMsg = f"{msg} Defaulting {key!r}"
486  result = genericMap.setdefault(key, default)
487  self.assertEqual(len(genericMap), length+1, msg=loopMsg)
488  self.assertEqual(result, default, msg=loopMsg)
489  self.assertEqual(genericMap[key], default, msg=loopMsg)
490 
491  self.assertEqual(genericMap.keys(), contents.keys(), msg=msg)
492 
493  with self.assertRaises(TypeError, msg=msg):
494  genericMap.setdefault(keyType(100), GenericMapTestBaseClass.NotAStorable())
495 
496  wrongType = float if keyType is not float else int
497  with self.assertRaises(TypeError):
498  genericMap.setdefault(wrongType(0), default)
499 
500  genericMap = self._fillMap(mapFactory, contents)
501  for length, (key, value) in enumerate(contents.items()):
502  loopMsg = f"{msg} Defaulting existing {key!r}={value!r}"
503  result = genericMap.setdefault(key, default)
504  self.assertEqual(len(genericMap), len(contents), msg=loopMsg)
505  self.assertEqual(result, contents[key], msg=loopMsg)
506  self.assertEqual(genericMap[key], contents[key], msg=loopMsg)
507 

◆ checkUpdateKwargs()

def lsst.afw.typehandling.testUtils.MutableGenericMapTestBaseClass.checkUpdateKwargs (   self,
  mapFactory,
  contents,
  msg = "" 
)
Check bulk insertion from keywords into a GenericMap.

Parameters
----------
mapFactory : callable
    A zero-argument callable that creates an empty
    `lsst.afw.typehandling.GenericMap` object of the type to be tested
    Must allow string keys.
contents : `Mapping`
    The key-value pairs to insert into the map
msg : `str`
    Error message suffix describing test parameters

Definition at line 562 of file testUtils.py.

562  def checkUpdateKwargs(self, mapFactory, contents, msg=""):
563  """Check bulk insertion from keywords into a GenericMap.
564 
565  Parameters
566  ----------
567  mapFactory : callable
568  A zero-argument callable that creates an empty
569  `lsst.afw.typehandling.GenericMap` object of the type to be tested
570  Must allow string keys.
571  contents : `Mapping`
572  The key-value pairs to insert into the map
573  msg : `str`
574  Error message suffix describing test parameters
575  """
576  genericMap = self._fillPartialMap(mapFactory, dict.fromkeys(contents, 0), len(contents)/2)
577  self.assertLess(len(genericMap), len(contents), msg=msg)
578 
579  genericMap.update(**contents)
580  self.assertEqual(dict(genericMap), dict(contents), msg=msg)
581 
582  with self.assertRaises(TypeError, msg=msg):
583  genericMap.update(notAKey=GenericMapTestBaseClass.NotAStorable())
584 

◆ checkUpdateMapping()

def lsst.afw.typehandling.testUtils.MutableGenericMapTestBaseClass.checkUpdateMapping (   self,
  mapFactory,
  contents,
  msg = "" 
)
Check bulk insertion from a mapping into a GenericMap.

Parameters
----------
mapFactory : callable
    A zero-argument callable that creates an empty
    `lsst.afw.typehandling.GenericMap` object of the type to be tested
contents : `Mapping`
    The key-value pairs to insert into the map
msg : `str`
    Error message suffix describing test parameters

Definition at line 508 of file testUtils.py.

508  def checkUpdateMapping(self, mapFactory, contents, msg=""):
509  """Check bulk insertion from a mapping into a GenericMap.
510 
511  Parameters
512  ----------
513  mapFactory : callable
514  A zero-argument callable that creates an empty
515  `lsst.afw.typehandling.GenericMap` object of the type to be tested
516  contents : `Mapping`
517  The key-value pairs to insert into the map
518  msg : `str`
519  Error message suffix describing test parameters
520  """
521  genericMap = self._fillPartialMap(mapFactory, dict.fromkeys(contents, 0), len(contents)/2)
522  self.assertLess(len(genericMap), len(contents), msg=msg)
523 
524  genericMap.update(contents)
525  self.assertEqual(dict(genericMap), dict(contents), msg=msg)
526 
527  keyType = genericMap.dtype
528  with self.assertRaises(TypeError, msg=msg):
529  genericMap.update({keyType(0): GenericMapTestBaseClass.NotAStorable()})
530 
531  wrongType = float if keyType is not float else int
532  with self.assertRaises(TypeError, msg=msg):
533  genericMap.update({wrongType(0): 0})
534 

◆ checkUpdatePairs()

def lsst.afw.typehandling.testUtils.MutableGenericMapTestBaseClass.checkUpdatePairs (   self,
  mapFactory,
  contents,
  msg = "" 
)
Check bulk insertion from an iterable of pairs into a GenericMap.

Parameters
----------
mapFactory : callable
    A zero-argument callable that creates an empty
    `lsst.afw.typehandling.GenericMap` object of the type to be tested
contents : `Mapping`
    The key-value pairs to insert into the map
msg : `str`
    Error message suffix describing test parameters

Definition at line 535 of file testUtils.py.

535  def checkUpdatePairs(self, mapFactory, contents, msg=""):
536  """Check bulk insertion from an iterable of pairs into a GenericMap.
537 
538  Parameters
539  ----------
540  mapFactory : callable
541  A zero-argument callable that creates an empty
542  `lsst.afw.typehandling.GenericMap` object of the type to be tested
543  contents : `Mapping`
544  The key-value pairs to insert into the map
545  msg : `str`
546  Error message suffix describing test parameters
547  """
548  genericMap = self._fillPartialMap(mapFactory, dict.fromkeys(contents, 0), len(contents)/2)
549  self.assertLess(len(genericMap), len(contents), msg=msg)
550 
551  genericMap.update(contents.items())
552  self.assertEqual(dict(genericMap), dict(contents), msg=msg)
553 
554  keyType = genericMap.dtype
555  with self.assertRaises(TypeError, msg=msg):
556  genericMap.update([(keyType(0), GenericMapTestBaseClass.NotAStorable())])
557 
558  wrongType = float if keyType is not float else int
559  with self.assertRaises(TypeError, msg=msg):
560  genericMap.update([(wrongType(0), 0)])
561 

◆ checkViews()

def lsst.afw.typehandling.testUtils.GenericMapTestBaseClass.checkViews (   self,
  genericMap,
  contents,
  msg = "" 
)
inherited
Check the views provided by a GenericMap.

Parameters
----------
genericMap : `lsst.afw.typehandling.GenericMap`
    The map to test.
contents : `Mapping`
    The key-value pairs that should be present in ``genericMap``
msg : `str`
    Error message suffix describing test parameters

Definition at line 350 of file testUtils.py.

350  def checkViews(self, genericMap, contents, msg=""):
351  """Check the views provided by a GenericMap.
352 
353  Parameters
354  ----------
355  genericMap : `lsst.afw.typehandling.GenericMap`
356  The map to test.
357  contents : `Mapping`
358  The key-value pairs that should be present in ``genericMap``
359  msg : `str`
360  Error message suffix describing test parameters
361  """
362  self.assertEqual(set(genericMap.keys()), set(contents.keys()), msg=msg)
363  self.assertEqual(Counter(genericMap.values()), Counter(contents.values()), msg=msg)
364  self.assertEqual(Counter(genericMap.items()), Counter(contents.items()), msg=msg)
365 
366 
daf::base::PropertySet * set
Definition: fits.cc:912

◆ getTestData()

def lsst.afw.typehandling.testUtils.GenericMapTestBaseClass.getTestData (   cls,
  keyClass 
)
inherited
Generic dataset for testing GenericMap classes that can handle it.

Parameters
----------
keyClass : `type`
    The type of key expected by the GenericMap.

Definition at line 96 of file testUtils.py.

96  def getTestData(cls, keyClass):
97  """Generic dataset for testing GenericMap classes that can handle it.
98 
99  Parameters
100  ----------
101  keyClass : `type`
102  The type of key expected by the GenericMap.
103  """
104  return {keyClass(key): value for key, value in cls._testData.items()}
105 
std::vector< SchemaItem< Flag > > * items

◆ getValidKeys()

def lsst.afw.typehandling.testUtils.GenericMapTestBaseClass.getValidKeys (   mapClass)
staticinherited
Return all keys suitable for a GenericMap.

Parameters
----------
mapClass : `type`
    A type object for a subclass of either `GenericMap` or a
    key-specific specialization.

Returns
-------
keyTypes: `set` [`type`]
    The types that can be used as keys. If ``mapClass`` is a
    key-specific specialization, this set will contain exactly
    one type.

Definition at line 107 of file testUtils.py.

107  def getValidKeys(mapClass):
108  """Return all keys suitable for a GenericMap.
109 
110  Parameters
111  ----------
112  mapClass : `type`
113  A type object for a subclass of either `GenericMap` or a
114  key-specific specialization.
115 
116  Returns
117  -------
118  keyTypes: `set` [`type`]
119  The types that can be used as keys. If ``mapClass`` is a
120  key-specific specialization, this set will contain exactly
121  one type.
122  """
123  try:
124  return {mapClass.dtype}
125  except AttributeError:
126  return {cls.dtype for cls in mapClass.__subclasses__()}
127 

◆ setUp()

def lsst.afw.typehandling.testUtils.GenericMapTestBaseClass.setUp (   self)
inherited
Set up a test

Subclasses must call this method if they override setUp.

Definition at line 128 of file testUtils.py.

128  def setUp(self):
129  """Set up a test
130 
131  Subclasses must call this method if they override setUp.
132  """
133  super().setUp()
134  # tell unittest to use the msg argument of asserts as a supplement
135  # to the error message, rather than as the whole error message
136  self.longMessage = True
137 

Member Data Documentation

◆ longMessage

lsst.afw.typehandling.testUtils.GenericMapTestBaseClass.longMessage
inherited

Definition at line 136 of file testUtils.py.


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