Пример #1
0
 def test_6_build_incomplete_task_message(self):
     # Test #6. Build task message with incomplete parameters (without 'results')
     # Expected result: error is raised
     configurations = [[2200.0, 8]]
     expected_result = (
         "Invalid parameters passed to send message via API: "
         "The results(key parameter) are not provided or have invalid format!"
     )
     with pytest.raises(KeyError) as excinfo:
         APIMessageBuilder.build('NEW', configurations=configurations)
     assert expected_result in str(excinfo.value)
Пример #2
0
 def test_7_build_inconsistent_task_message(self):
     # Test #7. Build task message with inconsistent dimensionality of 'configurations' and 'results'
     # Expected result: error is raised
     configurations = [[2200.0, 8]]
     results = [123, 234]
     expected_result = "Different sizes of provided parameters!"
     with pytest.raises(KeyError) as excinfo:
         APIMessageBuilder.build('NEW',
                                 configurations=configurations,
                                 results=results)
     assert expected_result in str(excinfo.value)
Пример #3
0
 def test_5_build_invalid_task_message(self):
     # Test #5. Build task message with the invalid values according to the API message format
     # Expected result: error is raised, that invalid parameters are passed
     expected_result = (
         "Invalid parameters passed to send message via API: "
         "The configurations(key parameter) are not provided or have invalid format!"
     )
     with pytest.raises(KeyError) as excinfo:
         APIMessageBuilder.build('NEW',
                                 configurations="Invalid string",
                                 results="Invalid string")
     assert expected_result in str(excinfo.value)
Пример #4
0
 def test_9_build_incomplete_experiment_message(self):
     # Test #9. Build experiment message from incomplete parameters
     # Expected result: error is raised
     from tools.initial_config import load_experiment_setup
     expected_result = "Invalid parameters passed to send message via API: The search space description is not provided!"
     experiment_description, _ = load_experiment_setup(
         "./Resources/EnergyExperiment/EnergyExperiment.json")
     global_config = experiment_description["General"]
     with pytest.raises(KeyError) as excinfo:
         APIMessageBuilder.build(
             'EXPERIMENT',
             global_config=global_config,
             experiment_description=experiment_description)
     assert expected_result in str(excinfo.value)
Пример #5
0
 def test_0_build_log_message(self):
     # Test #0. Build log message according to the API message format
     # Expected result: the message of type 'string' is built independently on its content
     expected_result = "This is log"
     msg = "This is log"
     actual_result = APIMessageBuilder.build('LOG', message=msg)
     assert actual_result == expected_result
Пример #6
0
 def test_3_build_new_task_message(self):
     # Test #3. Build task message according to the API message format. The 'result' is an empty list
     # Expected result: the task message of type 'list' is built. It contains the "configuration-result" pair as a dictionary.
     expected_result = [{'configurations': [2200.0, 8], 'results': None}]
     configurations = [[2200.0, 8]]
     actual_result = APIMessageBuilder.build('NEW',
                                             configurations=configurations,
                                             results=[None])
     assert actual_result == expected_result
Пример #7
0
 def test_1_build_log_message_of_multiple_parts(self):
     # Test #1. Build log message according to the API message format. Message consists of several parts
     # Expected result: the single message of type 'string' is built by concatenation
     expected_result = "This is log"
     msg1 = "This is "
     msg2 = "log"
     actual_result = APIMessageBuilder.build('LOG',
                                             message1=msg1,
                                             message2=msg2)
     assert actual_result == expected_result
Пример #8
0
 def test_4_build_task_message_with_result(self):
     # Test #4. Build task message according to the API message format. Use different supported message types
     # Expected result: the task message of type 'list' is built. It contains the "configuration-result" pair as a dictionary.
     expected_result = [{'configurations': [2200.0, 8], 'results': 123}]
     configurations = [[2200.0, 8]]
     results = [123]
     message_types = ['DEFAULT', 'PREDICTIONS', 'FINAL']
     for message_type in message_types:
         actual_result = APIMessageBuilder.build(
             message_type, configurations=configurations, results=results)
         assert actual_result == expected_result
Пример #9
0
 def test_8_build_experiment_message(self):
     # Test #8. Build experiment message according to the API message format
     # Expected result: the message of type 'dictionary' is built and contains all needed fields
     from tools.initial_config import load_experiment_setup
     experiment_description, searchspace_description = \
         load_experiment_setup("./Resources/EnergyExperiment/EnergyExperiment.json")
     global_config = experiment_description["General"]
     actual_result = APIMessageBuilder.build(
         'EXPERIMENT',
         global_config=global_config,
         experiment_description=experiment_description,
         searchspace_description=searchspace_description)
     assert actual_result["global_configuration"]
     assert actual_result["experiment_description"]
     assert actual_result["searchspace_description"]
Пример #10
0
 def test_2_build_empty_log_message(self):
     # Test #2. Build log message according to the API message format. Message is empty
     # Expected result: the single empty message of type 'string' is built
     expected_result = ""
     actual_result = APIMessageBuilder.build('LOG')
     assert actual_result == expected_result