def test_deepcopy_on_readonly_list(): lst = [1, 2, 3, 4] lst = make_read_only(lst) lst = make_read_only(lst) copied_l = deepcopy(lst) for v, v_copied in zip(lst, copied_l): assert v == v_copied
def test_nested_readonly_list(): l = [1, [2, [3, [4]]]] l = make_read_only(l) _check_read_only_list(l) _check_read_only_list(l[1]) _check_read_only_list(l[1][1]) _check_read_only_list(l[1][1][1])
def finalize_initialization(self, run): # look at seed again, because it might have changed during the # configuration process if 'seed' in self.config: self.seed = self.config['seed'] self.rnd = create_rnd(self.seed) for cfunc in self._captured_functions: # Setup the captured function cfunc.logger = self.logger.getChild(cfunc.__name__) seed = get_seed(self.rnd) cfunc.rnd = create_rnd(seed) cfunc.run = run cfunc.config = get_by_dotted_path(self.get_fixture(), cfunc.prefix, default={}) # Make configuration read only if enabled in settings if SETTINGS.CONFIG.READ_ONLY_CONFIG: cfunc.config = make_read_only( cfunc.config, error_message='The configuration is read-only in a ' 'captured function!') if not run.force: self._warn_about_suspicious_changes()
def test_deepcopy_on_nested_readonly_list(): lst = [1, [2, [3, [4]]]] lst = make_read_only(lst) copied_l = deepcopy(lst) assert lst == copied_l for v, v_copied in zip(lst, copied_l): assert v == v_copied
def test_nested_readonly_list(): lst = [1, [2, [3, [4]]]] lst = make_read_only(lst) _check_read_only_list(lst) _check_read_only_list(lst[1]) _check_read_only_list(lst[1][1]) _check_read_only_list(lst[1][1][1])
def test_deepcopy_on_nested_readonly_dict(): d = dict(a=1, b=dict(c=3)) d = make_read_only(d) copied_d = deepcopy(d) for (k, v), (k_copied, v_copied) in zip(sorted(d.items()), sorted(copied_d.items())): assert k == k_copied assert v == v_copied
def test_deepcopy_on_readonly_dict(): d = dict(a=1, b=2, c=3) d = make_read_only(d) copied_d = deepcopy(d) for (k, v), (k_copied, v_copied) in zip(d.items(), copied_d.items()): assert k == k_copied assert v == v_copied
def test_nested_readonly_containers(): container = ([0, [], {}, ()], {0: (), 1: [], 2: {}}) container = make_read_only(container) _check_read_only_list(container[0]) _check_read_only_list(container[0][1]) _check_read_only_dict(container[0][2]) _check_read_only_dict(container[1]) _check_read_only_dict(container[1][2]) _check_read_only_list(container[1][1]) # Check explicitly for tuple (and not isinstance) to be sure that the type # is not altered assert type(container) == tuple assert type(container[0][3]) == tuple assert type(container[1][0]) == tuple
def test_readonly_list(): l = [1, 2, 3, 4] l = make_read_only(l) _check_read_only_list(l)
def test_nested_readonly_dict(): d = dict(a=1, b=dict(c=3)) d = make_read_only(d) _check_read_only_dict(d) _check_read_only_dict(d['b'])
def test_readonly_dict(): d = dict(a=1, b=2, c=3) d = make_read_only(d) _check_read_only_dict(d)
def test_deepcopy_on_nested_readonly_list_can_be_mutated(): lst = [1, [2, [3, [4]]]] lst = make_read_only(lst) copied_l = deepcopy(lst) copied_l[1][1].append(5) assert lst[1][1] != copied_l[1][1]
def test_copy_on_nested_readonly_dict_still_list(): lst = [1, [2, [3, [4]]]] lst = make_read_only(lst) copied_l = copy(lst) with pytest.raises(SacredError): copied_l[1][1].append(5)
def test_deepcopy_on_nested_readonly_dict_can_be_mutated(): d = dict(a=1, b=dict(c=3)) d = make_read_only(d) copied_d = deepcopy(d) copied_d["b"]["c"] = 4 assert d["b"]["c"] != copied_d["b"]["c"]
def test_copy_on_nested_readonly_dict_still_raises(): d = dict(a=1, b=dict(c=3)) d = make_read_only(d) copied_d = copy(d) with pytest.raises(SacredError): copied_d["b"]["c"] = 4
def test_readonly_list(): lst = [1, 2, 3, 4] lst = make_read_only(lst) _check_read_only_list(lst)