def test_set_output_givenBooleanValue_correctlyAdded(self): os.environ["WFE_INPUT_JSON"] = '{}' core = _core._core() core._set_output("test", True) self.assertEqual(core._outputs["test"], True)
def test_set_output_givenListValue_correctlyAdded(self): os.environ["WFE_INPUT_JSON"] = '{}' core = _core._core() core._set_output("test", ["test1", "test2"]) self.assertEqual(core._outputs["test"], ["test1", "test2"])
def test_set_output_givenDecimalValue_correctlyAdded(self): os.environ["WFE_INPUT_JSON"] = '{}' core = _core._core() core._set_output("test", 0.2) self.assertEqual(core._outputs["test"], 0.2)
def test_set_output_givenStringValue_correctlyAdded(self): os.environ["WFE_INPUT_JSON"] = '{}' core = _core._core() core._set_output("test", "string") self.assertEqual(core._outputs["test"], "string")
def test_get_inputs_givenInteger_isDeserialized(self): os.environ[ 'WFE_INPUT_JSON'] = '{"WFE_output_params_file":"param.json","red":2}' core = _core._core() inputs = core._get_inputs() self.assertEqual(inputs['red'], 2)
def test_get_inputs_givenString_isDeserialized(self): os.environ[ 'WFE_INPUT_JSON'] = '{"WFE_output_params_file":"param.json","value":"testValue"}' core = _core._core() inputs = core._get_inputs() self.assertEqual(inputs['value'], 'testValue')
def test_get_inputs_givenBoolean_isDeserialized(self): os.environ[ "WFE_INPUT_JSON"] = '{"WFE_output_params_file":"param.json","value":true}' core = _core._core() inputs = core._get_inputs() self.assertEqual(inputs["value"], True)
def test_init_givenEmptyInputJson_coreIsInitialized(self): os.environ['WFE_INPUT_JSON'] = '{}' core = _core._core() self.assertTrue(core) self.assertEqual(core._wfe_output_params_file, '') self.assertEqual(core._outputs, {})
def test_get_inputs_givenList_isDeserialized(self): os.environ[ "WFE_INPUT_JSON"] = '{"WFE_output_params_file":"param.json","value":["one", "two"]}' core = _core._core() inputs = core._get_inputs() self.assertEqual(inputs["value"], ["one", "two"])
def test_init_givenInputJson_coreIsInitalized(self): os.environ[ 'WFE_INPUT_JSON'] = '{"WFE_output_params_file":"param.json","red":0.2,"input_image":"test.jpg"}' core = _core._core() self.assertTrue(core) self.assertEqual(core._input_json['WFE_output_params_file'], 'param.json')
def test_set_file_output_givenEmptyFileNameList_FileNotCopied( self, mock_shutil): os.environ["WFE_INPUT_JSON"] = '{}' core = _core._core() core._set_file_output("file", ["", " ", ' ']) mock_shutil.copyfile.assert_not_called() self.assertEqual(len(core._outputs), 0)
def test_get_inputs_givenInputJson_paramFileIsNotPartOfInputs(self): os.environ[ 'WFE_INPUT_JSON'] = '{"WFE_output_params_file":"param.json","red":0.2}' core = _core._core() inputs = core._get_inputs() self.assertFalse('WFE_output_params_file' in inputs) self.assertEqual(len(inputs), 1)
def test_set_file_output_givenFileInOutputFolder_FileNotCopied( self, mock_shutil): os.environ["WFE_INPUT_JSON"] = '{}' core = _core._core() core._set_file_output("file", "/output/file.txt") mock_shutil.copyfile.assert_not_called() self.assertEqual(core._outputs["file"], "/output/file.txt")
def test_set_file_output_givenFileNotInOutputFolder_FileCopied( self, mock_shutil): os.environ["WFE_INPUT_JSON"] = '{}' core = _core._core() core._set_file_output("file", "file.txt") mock_shutil.copyfile.assert_called_with( "file.txt", os.path.join(self.output_dir, "file.txt")) self.assertEqual(core._outputs["file"], os.path.join(self.output_dir, "file.txt"))
def test_set_file_output_givenFileListNotInOutputFolder_FileCopied( self, mock_shutil): os.environ["WFE_INPUT_JSON"] = '{}' core = _core._core() core._set_file_output("file", ["file1.txt", "file2.txt"]) mock_shutil.copyfile.assert_has_calls([ mock.call("file1.txt", "/output/file1.txt"), mock.call("file2.txt", "/output/file2.txt") ]) self.assertEqual(core._outputs["file"], ["/output/file1.txt", "/output/file2.txt"])
from apeer_dev_kit import _core _adk = _core._core() def get_inputs(): """ Get inputs inside your module """ return _adk._get_inputs() def set_output(key, value): """ Set the output """ _adk._set_output(key, value) def set_file_output(key, filepath): """ Set the output """ _adk._set_file_output(key, filepath) def finalize(): """ This method should be called at the end """ _adk._finalize()
def test_init_givenNoEnvironmentVariable_coreIsNotInitialized(self): with self.assertRaises(KeyError): _core._core()
def test_set_output_givenNoneKey_raisesTypeError(self): os.environ["WFE_INPUT_JSON"] = '{}' core = _core._core() with self.assertRaises(TypeError): core._set_output(None, None)
def test_get_inputs_givenNoParamFileKey_throwsKeyErrorException(self): os.environ['WFE_INPUT_JSON'] = '{"red":0.2,"input_image":"test.jpg"}' core = _core._core() with self.assertRaises(KeyError): core._get_inputs()