def test_from_file_set_zip(self): code_config = CodeConfig.from_file_set(LOCAL_MODULE_ZIP, 'processor:process_dataset') self.assertIsInstance(code_config, CodeConfig) self.assertIsNone(code_config.inline_code) self.assertIsInstance(code_config.file_set, FileSet) self.assertEqual('processor:process_dataset', code_config.callable_ref) self.assertTrue(callable(code_config.get_callable()))
def test_for_service_from_file_set_zip(self): user_code_config = CodeConfig.from_file_set( LOCAL_MODULE_ZIP, 'processor:process_dataset') service_code_config = user_code_config.for_service() self.assertIs(user_code_config, service_code_config) self.assertIs(user_code_config.file_set, service_code_config.file_set) self.assertIsInstance(service_code_config.file_set, FileSet) self.assertEqual(LOCAL_MODULE_ZIP, service_code_config.file_set.path)
def test_for_local_from_file_set_dir(self): user_code_config = CodeConfig.from_file_set( LOCAL_MODULE_DIR, 'processor:process_dataset') local_code_config = user_code_config.for_local() self.assertIs(user_code_config, local_code_config) self.assertIsInstance(local_code_config.file_set, FileSet) self.assertIs(user_code_config.file_set, local_code_config.file_set) self.assertEqual(LOCAL_MODULE_DIR, local_code_config.file_set.path) # CodeConfigs from for_local() shall be able to load callable self.assertTrue(callable(local_code_config.get_callable()))
def test_for_service_from_file_set_dir(self): user_code_config = CodeConfig.from_file_set( LOCAL_MODULE_DIR, 'processor:process_dataset') service_code_config = user_code_config.for_service() self.assertIsInstance(service_code_config, CodeConfig) self.assertIsInstance(service_code_config.callable_ref, str) self.assertIsNone(service_code_config._callable) self.assertIsNone(service_code_config.inline_code) self.assertIsInstance(service_code_config.file_set, FileSet) self.assertTrue(service_code_config.file_set.is_local_zip()) self.assertRegex(os.path.basename(service_code_config.file_set.path), 'xcube-byoa-*.') self.assertEqual('processor:process_dataset', service_code_config.callable_ref)
def test_for_local_from_file_set_zip(self): user_code_config = CodeConfig.from_file_set( LOCAL_MODULE_ZIP, 'processor:process_dataset') local_code_config = user_code_config.for_local() self.assertIsInstance(local_code_config, CodeConfig) self.assertIsInstance(local_code_config.callable_ref, str) self.assertIsNone(local_code_config._callable) self.assertIsNone(local_code_config.inline_code) self.assertIsInstance(local_code_config.file_set, FileSet) self.assertTrue(local_code_config.file_set.is_local_dir()) self.assertRegex(os.path.basename(local_code_config.file_set.path), 'xcube-byoa-*.') self.assertEqual('processor:process_dataset', local_code_config.callable_ref) # CodeConfigs from for_local() shall be able to load callable self.assertTrue(callable(local_code_config.get_callable()))
def test_to_dict(self): d = CodeConfig.from_callable(modify_dataset).to_dict() # Shall we raise instead? self.assertEqual({}, d) d = CodeConfig.from_code(INLINE_CODE, module_name='user_code').to_dict() self.assertEqual( { 'callable_ref': 'user_code:process_dataset', 'inline_code': INLINE_CODE, }, d) d = CodeConfig.from_file_set( FileSet('github://*****:*****@v0.8.2.dev0', includes='*.py'), callable_ref=('test.core.byoa.test_config:' 'modify_dataset')).to_dict() self.assertIsInstance(d.get('file_set'), dict) self.assertEqual(('test.core.byoa.test_config:' 'modify_dataset'), d.get('callable_ref'))