def run_study_config_instanciation(self, tests, test_description, user_config_directory): for arguments, results in tests: args, kwargs = arguments sargs = ', '.join(repr(i) for i in args) if kwargs: sargs += ', '.join('%s=%s' % (repr(i), repr(j)) for i, j in six.iteritems(kwargs)) sc = StudyConfig(*args, **kwargs) (expected_config, expected_modules, global_config_file, study_config_file) = results if global_config_file: global_config_file = os.path.join(user_config_directory, global_config_file) if study_config_file: study_config_file = os.path.join(user_config_directory, study_config_file) config = sc.get_configuration_dict() modules = sorted(sc.modules.keys()) try: self.assertEqual(set(config), set(expected_config)) for name, value in six.iteritems(expected_config): self.assertEqual( config[name], value, 'StudyConfig(%s) %s attribute %s should be %s but is ' '%s' % (sargs, test_description, name, repr(value), repr(getattr(sc, name)))) self.assertEqual( modules, expected_modules, 'StudyConfig(%s) %s modules are %s but expected value is ' '%s' % (sargs, test_description, repr(modules), repr(expected_modules))) self.assertEqual( sc.global_config_file, global_config_file, 'StudyConfig(%s) %s global_config_file should be %s but ' 'is %s' % (sargs, test_description, repr(global_config_file), repr(sc.global_config_file))) self.assertEqual( sc.study_config_file, study_config_file, 'StudyConfig(%s) %s study_config_file should be %s but is ' '%s' % (sargs, test_description, repr(study_config_file), repr(sc.study_config_file))) except Exception as e: raise EnvironmentError( 'When testing StudyConfig(*{0}, **{1}), got the following error: {2}' .format(args, kwargs, e))
def run_study_config_instanciation(self, tests, test_description, user_config_directory): for arguments, results in tests: args, kwargs = arguments sargs = ', '.join(repr(i) for i in args) if kwargs: sargs += ', '.join('%s=%s' % (repr(i),repr(j)) for i,j in six.iteritems(kwargs)) sc = StudyConfig(*args, **kwargs) (expected_config, expected_modules, global_config_file, study_config_file) = results if global_config_file: global_config_file = os.path.join(user_config_directory, global_config_file) if study_config_file: study_config_file = os.path.join(user_config_directory, study_config_file) config = sc.get_configuration_dict() modules = sorted(sc.modules.keys()) self.assertEqual(set(config), set(expected_config)) for name, value in six.iteritems(expected_config): self.assertEqual(config[name], value, 'StudyConfig(%s) %s attribute %s should be %s but is ' '%s' % (sargs, test_description, name, repr(value), repr(getattr(sc, name)))) self.assertEqual(modules, expected_modules, 'StudyConfig(%s) %s modules are %s but expected value is ' '%s' % (sargs, test_description, repr(modules), repr(expected_modules))) self.assertEqual(sc.global_config_file, global_config_file, 'StudyConfig(%s) %s global_config_file should be %s but ' 'is %s' % (sargs,test_description, repr(global_config_file), repr(sc.global_config_file))) self.assertEqual(sc.study_config_file, study_config_file, 'StudyConfig(%s) %s study_config_file should be %s but is ' '%s' % (sargs, test_description, repr(study_config_file), repr(sc.study_config_file)))