コード例 #1
0
 def test_set_pref_mac(self, mock_set_macos_pref):
     """Preferences().set_pref should write macOS preference store on macOS."""
     self.mock_platform.return_value = "Darwin"
     fake_prefs = Preferences()
     fake_prefs.set_pref("TEST_KEY", "fake_value")
     value = fake_prefs.get_pref("TEST_KEY")
     self.assertEqual(value, "fake_value")
     mock_set_macos_pref.assert_called()
コード例 #2
0
 def test_set_pref_no_file(self, mock_write_file, mock_set_macos_pref):
     """set_pref should change the prefs object, but not write when no file loaded"""
     fake_prefs = Preferences()
     fake_prefs.set_pref("TEST_KEY", "fake_value")
     mock_write_file.assert_not_called()
     mock_set_macos_pref.assert_not_called()
     value = fake_prefs.get_pref("TEST_KEY")
     self.assertEqual(value, "fake_value")
コード例 #3
0
ファイル: test_preferences.py プロジェクト: discentem/autopkg
 def test_set_pref_mac_files(self, mock_open, mock_write_file, mock_set_macos_pref):
     """Preferences().set_pref should write file on macOS and read_file() used."""
     self.mock_platform.return_value = "darwin"
     fake_prefs = Preferences()
     fake_prefs.read_file("fake_config_file")
     mock_open.assert_called()
     fake_prefs.set_pref("TEST_KEY", "fake_value")
     mock_write_file.assert_called()
     mock_set_macos_pref.assert_not_called()
     value = fake_prefs.get_pref("TEST_KEY")
     self.assertEqual(value, "fake_value")
コード例 #4
0
 def test_set_pref_files(self, mock_write_file, mock_open):
     """Preferences().set_pref should write file on file-backed config platforms"""
     for platform in self.PRIMARY_NON_MACOS_PLATFORMS:
         with self.subTest(platform=platform):
             self.mock_platform.return_value = platform
             fake_prefs = Preferences()
             self.assertNotEqual(fake_prefs.file_path, None)
             fake_prefs.set_pref("TEST_KEY", "fake_value")
             mock_write_file.assert_called()
             value = fake_prefs.get_pref("TEST_KEY")
             self.assertEqual(value, "fake_value")
             mock_write_file.reset_mock()