MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_reflection

Method test_reflection

Lib/test/test_winreg.py:475–516  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

473
474 @unittest.skipUnless(HAS_REFLECTION, "OS doesn't support reflection")
475 def test_reflection(self):
476 # Test that we can create, open, and delete keys in the 32-bit
477 # area. Because we are doing this in a key which gets reflected,
478 # test the differences of 32 and 64-bit keys before and after the
479 # reflection occurs (ie. when the created key is closed).
480 try:
481 with CreateKeyEx(HKEY_CURRENT_USER, test_reflect_key_name, 0,
482 KEY_ALL_ACCESS | KEY_WOW64_32KEY) as created_key:
483 self.assertNotEqual(created_key.handle, 0)
484
485 # The key should now be available in the 32-bit area
486 with OpenKey(HKEY_CURRENT_USER, test_reflect_key_name, 0,
487 KEY_ALL_ACCESS | KEY_WOW64_32KEY) as key:
488 self.assertNotEqual(key.handle, 0)
489
490 # Write a value to what currently is only in the 32-bit area
491 SetValueEx(created_key, "", 0, REG_SZ, "32KEY")
492
493 # The key is not reflected until created_key is closed.
494 # The 64-bit version of the key should not be available yet.
495 open_fail = lambda: OpenKey(HKEY_CURRENT_USER,
496 test_reflect_key_name, 0,
497 KEY_READ | KEY_WOW64_64KEY)
498 self.assertRaises(OSError, open_fail)
499
500 # Now explicitly open the 64-bit version of the key
501 with OpenKey(HKEY_CURRENT_USER, test_reflect_key_name, 0,
502 KEY_ALL_ACCESS | KEY_WOW64_64KEY) as key:
503 self.assertNotEqual(key.handle, 0)
504 # Make sure the original value we set is there
505 self.assertEqual("32KEY", QueryValue(key, ""))
506 # Set a new value, which will get reflected to 32-bit
507 SetValueEx(key, "", 0, REG_SZ, "64KEY")
508
509 # Reflection uses a "last-writer wins policy, so the value we set
510 # on the 64-bit key should be the same on 32-bit
511 with OpenKey(HKEY_CURRENT_USER, test_reflect_key_name, 0,
512 KEY_READ | KEY_WOW64_32KEY) as key:
513 self.assertEqual("64KEY", QueryValue(key, ""))
514 finally:
515 DeleteKeyEx(HKEY_CURRENT_USER, test_reflect_key_name,
516 KEY_WOW64_32KEY, 0)
517
518 @unittest.skipUnless(HAS_REFLECTION, "OS doesn't support reflection")
519 def test_disable_reflection(self):

Callers

nothing calls this directly

Calls 8

CreateKeyExFunction · 0.85
OpenKeyFunction · 0.85
SetValueExFunction · 0.85
QueryValueFunction · 0.85
DeleteKeyExFunction · 0.85
assertNotEqualMethod · 0.80
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected