RATapi 0.0.0.dev0__cp39-cp39-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. RATapi/__init__.py +8 -0
  2. RATapi/classlist.py +387 -0
  3. RATapi/controls.py +143 -0
  4. RATapi/eventManager.dll +0 -0
  5. RATapi/events.py +70 -0
  6. RATapi/examples/__init__.py +0 -0
  7. RATapi/examples/absorption/__init__.py +0 -0
  8. RATapi/examples/absorption/absorption.py +148 -0
  9. RATapi/examples/absorption/volume_thiol_bilayer.py +138 -0
  10. RATapi/examples/data/D2O_spin_down.dat +100 -0
  11. RATapi/examples/data/D2O_spin_up.dat +101 -0
  12. RATapi/examples/data/DSPC_D2O.dat +82 -0
  13. RATapi/examples/data/DSPC_SMW.dat +82 -0
  14. RATapi/examples/data/H2O_spin_down.dat +102 -0
  15. RATapi/examples/data/H2O_spin_up.dat +102 -0
  16. RATapi/examples/data/__init__.py +0 -0
  17. RATapi/examples/data/c_PLP0016596.dat +146 -0
  18. RATapi/examples/data/c_PLP0016601.dat +97 -0
  19. RATapi/examples/data/c_PLP0016607.dat +104 -0
  20. RATapi/examples/domains/__init__.py +0 -0
  21. RATapi/examples/domains/alloy_domains.py +26 -0
  22. RATapi/examples/domains/domains_XY_model.py +70 -0
  23. RATapi/examples/domains/domains_custom_XY.py +69 -0
  24. RATapi/examples/domains/domains_custom_layers.py +46 -0
  25. RATapi/examples/domains/domains_standard_layers.py +75 -0
  26. RATapi/examples/languages/__init__.py +0 -0
  27. RATapi/examples/languages/custom_bilayer.py +66 -0
  28. RATapi/examples/languages/run_custom_file_languages.py +41 -0
  29. RATapi/examples/languages/setup_problem.py +130 -0
  30. RATapi/examples/non_polarised/DSPC_custom_XY.py +140 -0
  31. RATapi/examples/non_polarised/DSPC_custom_layers.py +121 -0
  32. RATapi/examples/non_polarised/DSPC_standard_layers.py +358 -0
  33. RATapi/examples/non_polarised/__init__.py +0 -0
  34. RATapi/examples/non_polarised/custom_XY_DSPC.py +137 -0
  35. RATapi/examples/non_polarised/custom_bilayer_DSPC.py +85 -0
  36. RATapi/inputs.py +471 -0
  37. RATapi/models.py +288 -0
  38. RATapi/outputs.py +218 -0
  39. RATapi/project.py +659 -0
  40. RATapi/rat_core.cp39-win_amd64.pyd +0 -0
  41. RATapi/run.py +35 -0
  42. RATapi/utils/__init__.py +0 -0
  43. RATapi/utils/custom_errors.py +42 -0
  44. RATapi/utils/enums.py +101 -0
  45. RATapi/utils/plotting.py +211 -0
  46. RATapi/wrappers.py +115 -0
  47. RATapi-0.0.0.dev0.dist-info/METADATA +57 -0
  48. RATapi-0.0.0.dev0.dist-info/RECORD +64 -0
  49. RATapi-0.0.0.dev0.dist-info/WHEEL +5 -0
  50. RATapi-0.0.0.dev0.dist-info/top_level.txt +2 -0
  51. tests/__init__.py +0 -0
  52. tests/conftest.py +4728 -0
  53. tests/test_classlist.py +882 -0
  54. tests/test_controls.py +863 -0
  55. tests/test_custom_errors.py +49 -0
  56. tests/test_events.py +61 -0
  57. tests/test_inputs.py +908 -0
  58. tests/test_models.py +308 -0
  59. tests/test_outputs.py +31 -0
  60. tests/test_plotting.py +167 -0
  61. tests/test_project.py +1387 -0
  62. tests/test_run.py +570 -0
  63. tests/test_wrappers.py +57 -0
  64. tests/utils.py +171 -0
@@ -0,0 +1,49 @@
1
+ """Test the utils.custom_errors module."""
2
+
3
+ import re
4
+
5
+ import pytest
6
+ from pydantic import ValidationError, create_model
7
+
8
+ import RATapi.utils.custom_errors
9
+
10
+
11
+ @pytest.fixture
12
+ def TestModel():
13
+ """Create a custom pydantic model for the tests."""
14
+ TestModel = create_model("TestModel", int_field=(int, 1), str_field=(str, "a"), __config__={"extra": "forbid"})
15
+ return TestModel
16
+
17
+
18
+ @pytest.mark.parametrize(
19
+ ["custom_errors", "expected_error_message"],
20
+ [
21
+ (
22
+ {},
23
+ "2 validation errors for TestModel\nint_field\n Input should be a valid integer, unable to parse string "
24
+ "as an integer [type=int_parsing, input_value='string', input_type=str]\nstr_field\n Input should be a "
25
+ "valid string [type=string_type, input_value=5, input_type=int]",
26
+ ),
27
+ (
28
+ {"int_parsing": "This is a custom error message", "string_type": "This is another custom error message"},
29
+ "2 validation errors for TestModel\nint_field\n This is a custom error message [type=int_parsing, "
30
+ "input_value='string', input_type=str]\nstr_field\n This is another custom error message "
31
+ "[type=string_type, input_value=5, input_type=int]",
32
+ ),
33
+ ],
34
+ )
35
+ def test_custom_pydantic_validation_error(
36
+ TestModel,
37
+ custom_errors: dict[str, str],
38
+ expected_error_message: str,
39
+ ) -> None:
40
+ """When we call custom_pydantic_validation_error with custom errors, we should return an error list containing
41
+ PydanticCustomErrors, otherwise we return the original set of errors.
42
+ """
43
+ try:
44
+ TestModel(int_field="string", str_field=5)
45
+ except ValidationError as exc:
46
+ custom_error_list = RATapi.utils.custom_errors.custom_pydantic_validation_error(exc.errors(), custom_errors)
47
+
48
+ with pytest.raises(ValidationError, match=re.escape(expected_error_message)):
49
+ raise ValidationError.from_exception_data("TestModel", custom_error_list)
tests/test_events.py ADDED
@@ -0,0 +1,61 @@
1
+ from unittest import mock
2
+
3
+ import pytest
4
+
5
+ import RATapi.events
6
+
7
+
8
+ def test_event_register() -> None:
9
+ first_callback = mock.Mock()
10
+ second_callback = mock.Mock()
11
+
12
+ with pytest.raises(ValueError):
13
+ RATapi.events.register("Message", first_callback)
14
+
15
+ RATapi.events.register(RATapi.events.EventTypes.Message, first_callback)
16
+ result = RATapi.events.get_event_callback(RATapi.events.EventTypes.Message)
17
+ assert result == [first_callback]
18
+
19
+ RATapi.events.register(RATapi.events.EventTypes.Plot, second_callback)
20
+ assert RATapi.events.get_event_callback(RATapi.events.EventTypes.Plot) == [second_callback]
21
+
22
+ RATapi.events.register(RATapi.events.EventTypes.Message, second_callback)
23
+ # the list is not guaranteed to be in the same order as inputted hence the set
24
+ assert set(RATapi.events.get_event_callback(RATapi.events.EventTypes.Message)) == set(
25
+ [first_callback, second_callback]
26
+ )
27
+
28
+ RATapi.events.clear()
29
+ assert RATapi.events.get_event_callback(RATapi.events.EventTypes.Plot) == []
30
+ assert RATapi.events.get_event_callback(RATapi.events.EventTypes.Message) == []
31
+
32
+
33
+ def test_event_notify() -> None:
34
+ first_callback = mock.Mock()
35
+ second_callback = mock.Mock()
36
+ third_callback = mock.Mock()
37
+ RATapi.events.register(RATapi.events.EventTypes.Message, first_callback)
38
+ RATapi.events.register(RATapi.events.EventTypes.Plot, second_callback)
39
+ RATapi.events.register(RATapi.events.EventTypes.Progress, third_callback)
40
+
41
+ RATapi.events.notify(RATapi.events.EventTypes.Message, "Hello World")
42
+ first_callback.assert_called_once_with("Hello World")
43
+ second_callback.assert_not_called()
44
+
45
+ data = RATapi.events.PlotEventData()
46
+ RATapi.events.notify(RATapi.events.EventTypes.Plot, data)
47
+ first_callback.assert_called_once()
48
+ second_callback.assert_called_once_with(data)
49
+
50
+ data = RATapi.events.ProgressEventData()
51
+ RATapi.events.notify(RATapi.events.EventTypes.Progress, data)
52
+ first_callback.assert_called_once()
53
+ second_callback.assert_called_once()
54
+ third_callback.assert_called_once_with(data)
55
+
56
+ RATapi.events.clear()
57
+ RATapi.events.notify(RATapi.events.EventTypes.Message, "Hello World")
58
+ RATapi.events.notify(RATapi.events.EventTypes.Plot, data)
59
+ assert first_callback.call_count == 1
60
+ assert second_callback.call_count == 1
61
+ assert third_callback.call_count == 1