Exemple #1
0
    def test_immutablelist_imutability(self):
        frozen = immutabletypes.freeze([1, 2, 3])
        with self.assertRaises(TypeError):
            frozen[1] = 2

        with self.assertRaises(TypeError):
            frozen[1:-1] = 5
Exemple #2
0
 def test_freeze_list_sum(self):
     lst = [4, 5, 6]
     imt = immutabletypes.freeze([1, 2, 3])
     __add__ = imt + lst
     self.assertEqual(__add__, [1, 2, 3, 4, 5, 6])
     __radd__ = lst + imt
     self.assertEqual(__radd__, [4, 5, 6, 1, 2, 3])
Exemple #3
0
    def get_config(config_for, from_scratch=False):
        if from_scratch:
            if config_for in ('master', 'syndic_master', 'mm_master', 'mm_sub_master'):
                return hubblestack.config.master_config(
                    AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for)
                )
            elif config_for in ('minion', 'sub_minion'):
                return hubblestack.config.get_config(
                    AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for)
                )
            elif config_for in ('syndic',):
                return hubblestack.config.syndic_config(
                    AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for),
                    AdaptedConfigurationTestCaseMixin.get_config_file_path('minion')
                )
            elif config_for == 'client_config':
                return hubblestack.config.client_config(
                    AdaptedConfigurationTestCaseMixin.get_config_file_path('master')
                )

        if config_for not in RUNTIME_VARS.RUNTIME_CONFIGS:
            if config_for in ('master', 'syndic_master', 'mm_master', 'mm_sub_master'):
                RUNTIME_VARS.RUNTIME_CONFIGS[config_for] = freeze(
                    hubblestack.config.master_config(
                        AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for)
                    )
                )
            elif config_for in ('minion', 'sub_minion'):
                RUNTIME_VARS.RUNTIME_CONFIGS[config_for] = freeze(
                    hubblestack.config.get_config(
                        AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for)
                    )
                )
            elif config_for in ('syndic',):
                RUNTIME_VARS.RUNTIME_CONFIGS[config_for] = freeze(
                    hubblestack.config.syndic_config(
                        AdaptedConfigurationTestCaseMixin.get_config_file_path(config_for),
                        AdaptedConfigurationTestCaseMixin.get_config_file_path('minion')
                    )
                )
            elif config_for == 'client_config':
                RUNTIME_VARS.RUNTIME_CONFIGS[config_for] = freeze(
                    hubblestack.config.client_config(
                        AdaptedConfigurationTestCaseMixin.get_config_file_path('master')
                    )
                )
        return RUNTIME_VARS.RUNTIME_CONFIGS[config_for]
Exemple #4
0
    def test_immutabledict_imutability(self):
        data = {
            1: 1,
            2: 2,
            3: {
                3.1: 3.1,
                3.2: 3.2,
                3.3: {
                    3.31: 3.33,
                    3.32: 3.34,
                    3.33: [3.331, 3.332, 3.333]
                }
            },
            4: [4.1, 4.2, 4.3]
        }
        frozen = immutabletypes.freeze(data)
        with self.assertRaises(TypeError):
            frozen[1] = 2

        with self.assertRaises(TypeError):
            fdict = frozen[3]
            fdict[3.1] = 5

        with self.assertRaises(TypeError):
            fdict = frozen[3]
            fdict[3.4] = 3.4

        with self.assertRaises(TypeError):
            frozen[3][3.3][3.32] = 3.99

        with self.assertRaises(TypeError):
            frozen[3][3.3][3.33][0] = 5

        with self.assertRaises(TypeError):
            flist = frozen[4]
            flist[0] = 5
Exemple #5
0
 def lock(self):
     # Late import
     from hubblestack.utils.immutabletypes import freeze
     frozen_vars = freeze(self._vars.copy())
     self._vars = frozen_vars
     self._locked = True