Esempio n. 1
0
 def testInvalidFontScale(self):
     invalid_font_scale = 99
     with self.assertRaisesWithLiteralMatch(
             ValueError,
             core._INVALID_FONT_SCALE.format(invalid_font_scale)):
         core.MjrContext(
             model=self.model,
             gl_context=None,  # Don't need a context for this test.
             font_scale=invalid_font_scale)
Esempio n. 2
0
  def testFreeMjrContext(self):
    for _ in range(5):
      renderer = render.Renderer(640, 480)
      with mock.patch.object(core.mjlib, "mjr_freeContext",
                             wraps=mjlib.mjr_freeContext) as mock_destructor:
        mjr_context = core.MjrContext(self.model, renderer)
        expected_address = ctypes.addressof(mjr_context.ptr.contents)
        mjr_context.free()

      self.assertIsNone(mjr_context.ptr)
      mock_destructor.assert_called_once()
      pointer = mock_destructor.call_args[0][0]
      actual_address = ctypes.addressof(pointer.contents)
      self.assertEqual(expected_address, actual_address)

      # Explicit freeing should not break any automatic GC triggered later.
      del mjr_context
      renderer.free()
      del renderer
      gc.collect()