def load(self, path: str, check_reproducibility: bool = False, skip_unsettable: bool = False) -> TapType: """Loads the arguments in JSON format. Note: Due to JSON, tuples are loaded as lists. :param path: Path to the JSON file where the arguments will be loaded from. :param check_reproducibility: When True, raises an error if the loaded reproducibility information doesn't match the current reproducibility information. :param skip_unsettable: When True, skips attributes that cannot be set in the Tap object, e.g. properties without setters. :return: Returns self. """ with open(path) as f: args_dict = json.load(f, object_hook=as_python_object) # Remove loaded reproducibility information since it is no longer valid saved_reproducibility_data = args_dict.pop('reproducibility', None) if check_reproducibility: current_reproducibility_data = self.get_reproducibility_info() enforce_reproducibility(saved_reproducibility_data, current_reproducibility_data, path) self.from_dict(args_dict, skip_unsettable=skip_unsettable) return self
def test_throw_error_for_saved_uncommitted_changes(self): with self.assertRaises(ValueError): enforce_reproducibility( { 'git_url': 'none', 'git_has_uncommitted_changes': True }, {'git_url': 'some'}, 'here')
def test_git_urls_disagree(self): with self.assertRaises(ValueError): enforce_reproducibility({'git_url': 'none'}, {'git_url': 'some'}, 'here')
def test_git_url_not_in_current_reproducibility_data(self): with self.assertRaises(ValueError): enforce_reproducibility({'git_url': 'none'}, {}, 'here')
def test_git_url_not_in_saved_reproducibility_data(self): with self.assertRaises(ValueError): enforce_reproducibility({}, {}, 'here')
def test_saved_reproducibility_data_is_none(self): with self.assertRaises(ValueError): enforce_reproducibility(None, {}, 'here')