def test_app_settings_should_ignore_default_value(self): # Set application setting by os.setenv os.environ.update({TEST_APP_SETTING_NAME: '42'}) # Try using utility to acquire application setting app_setting = common.get_app_setting(TEST_APP_SETTING_NAME, 'default') self.assertEqual(app_setting, '42')
def setUp(self): self.was_shmem_env_true = is_envvar_true( FUNCTIONS_WORKER_SHARED_MEMORY_DATA_TRANSFER_ENABLED) os.environ.update( {FUNCTIONS_WORKER_SHARED_MEMORY_DATA_TRANSFER_ENABLED: '1'}) os_name = platform.system() if os_name == 'Darwin': # If an existing AppSetting is specified, save it so it can be # restored later self.was_shmem_dirs = get_app_setting( UNIX_SHARED_MEMORY_DIRECTORIES) self._setUpDarwin() elif os_name == 'Linux': self._setUpLinux() self.file_accessor = FileAccessorFactory.create_file_accessor()
def test_app_settings_return_setting_value_when_validation_succeed(self): def parse_int_no_raise(value: str): try: int(value) return True except ValueError: return False # Set application setting to an invalid value os.environ.update({TEST_APP_SETTING_NAME: '42'}) app_setting = common.get_app_setting(TEST_APP_SETTING_NAME, default_value='1', validator=parse_int_no_raise) # Because 'invalid' is not an interger, falls back to default value self.assertEqual(app_setting, '42')
def test_app_settings_should_not_trigger_validator_when_not_set(self): def raise_excpt(value: str): raise Exception('Should not raise on app setting not found') common.get_app_setting(TEST_APP_SETTING_NAME, validator=raise_excpt)
def test_app_settings_not_set_should_return_default_value(self): app_setting = common.get_app_setting(TEST_APP_SETTING_NAME, 'default') self.assertEqual(app_setting, 'default')
def test_app_settings_not_set_should_return_none(self): app_setting = common.get_app_setting(TEST_APP_SETTING_NAME) self.assertIsNone(app_setting)