arkindex-base-worker 0.4.0b3__py3-none-any.whl → 0.4.0rc1__py3-none-any.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.
tests/test_base_worker.py CHANGED
@@ -206,6 +206,7 @@ def test_configure_worker_run(mocker, responses, caplog):
206
206
  "Loaded Worker Fake worker @ 123412 from API",
207
207
  ),
208
208
  ("arkindex_worker", logging.INFO, "Loaded user configuration from WorkerRun"),
209
+ ("arkindex_worker", logging.INFO, "User configuration retrieved"),
209
210
  ]
210
211
 
211
212
  assert worker.user_configuration == {"a": "b"}
@@ -284,12 +285,21 @@ def test_configure_user_configuration_defaults(mocker, responses):
284
285
 
285
286
  worker.configure()
286
287
 
287
- assert worker.config == {"param_1": "/some/path/file.pth", "param_2": 12}
288
288
  assert worker.user_configuration == {
289
289
  "integer_parameter": 0,
290
290
  "param_3": "Animula vagula blandula",
291
291
  "param_5": True,
292
292
  }
293
+ # All configurations are merged
294
+ assert worker.config == {
295
+ # Default config
296
+ "param_1": "/some/path/file.pth",
297
+ "param_2": 12,
298
+ # User config
299
+ "integer_parameter": 0,
300
+ "param_3": "Animula vagula blandula",
301
+ "param_5": True,
302
+ }
293
303
 
294
304
 
295
305
  @pytest.mark.parametrize("debug", [True, False])
@@ -676,7 +686,6 @@ def test_find_parents_file_paths(responses, mock_base_worker_with_cache, tmp_pat
676
686
  mock_base_worker_with_cache.args = mock_base_worker_with_cache.parser.parse_args()
677
687
 
678
688
  mock_base_worker_with_cache.configure()
679
- mock_base_worker_with_cache.configure_cache()
680
689
 
681
690
  assert mock_base_worker_with_cache.find_parents_file_paths(filename) == [
682
691
  tmp_path / "first" / filename,
@@ -753,3 +762,195 @@ def test_corpus_id_set_read_only_mode(
753
762
  mock_elements_worker_read_only.configure()
754
763
 
755
764
  assert mock_elements_worker_read_only.corpus_id == corpus_id
765
+
766
+
767
+ @pytest.mark.parametrize(
768
+ (
769
+ "wk_version_config",
770
+ "wk_version_user_config",
771
+ "frontend_user_config",
772
+ "model_config",
773
+ "expected_config",
774
+ ),
775
+ [
776
+ ({}, {}, {}, {}, {}),
777
+ # Keep parameters from worker version configuration
778
+ ({"parameter": 0}, {}, {}, {}, {"parameter": 0}),
779
+ # Keep parameters from worker version configuration + user_config defaults
780
+ (
781
+ {"parameter": 0},
782
+ {
783
+ "parameter2": {
784
+ "type": "int",
785
+ "title": "Lambda",
786
+ "default": 0,
787
+ "required": False,
788
+ }
789
+ },
790
+ {},
791
+ {},
792
+ {"parameter": 0, "parameter2": 0},
793
+ ),
794
+ # Keep parameters from worker version configuration + user_config no defaults
795
+ (
796
+ {"parameter": 0},
797
+ {
798
+ "parameter2": {
799
+ "type": "int",
800
+ "title": "Lambda",
801
+ "required": False,
802
+ }
803
+ },
804
+ {},
805
+ {},
806
+ {"parameter": 0},
807
+ ),
808
+ # Keep parameters from worker version configuration but user_config defaults overrides
809
+ (
810
+ {"parameter": 0},
811
+ {
812
+ "parameter": {
813
+ "type": "int",
814
+ "title": "Lambda",
815
+ "default": 1,
816
+ "required": False,
817
+ }
818
+ },
819
+ {},
820
+ {},
821
+ {"parameter": 1},
822
+ ),
823
+ # Keep parameters from worker version configuration + frontend config
824
+ (
825
+ {"parameter": 0},
826
+ {},
827
+ {"parameter2": 0},
828
+ {},
829
+ {"parameter": 0, "parameter2": 0},
830
+ ),
831
+ # Keep parameters from worker version configuration + frontend config overrides
832
+ ({"parameter": 0}, {}, {"parameter": 1}, {}, {"parameter": 1}),
833
+ # Keep parameters from worker version configuration + model config
834
+ (
835
+ {"parameter": 0},
836
+ {},
837
+ {},
838
+ {"parameter2": 0},
839
+ {"parameter": 0, "parameter2": 0},
840
+ ),
841
+ # Keep parameters from worker version configuration + model config overrides
842
+ ({"parameter": 0}, {}, {}, {"parameter": 1}, {"parameter": 1}),
843
+ # Keep parameters from worker version configuration + user_config default + model config overrides
844
+ (
845
+ {"parameter": 0},
846
+ {
847
+ "parameter": {
848
+ "type": "int",
849
+ "title": "Lambda",
850
+ "default": 1,
851
+ "required": False,
852
+ }
853
+ },
854
+ {},
855
+ {"parameter": 2},
856
+ {"parameter": 2},
857
+ ),
858
+ # Keep parameters from worker version configuration + model config + frontend config overrides
859
+ ({"parameter": 0}, {}, {"parameter": 2}, {"parameter": 1}, {"parameter": 2}),
860
+ # Keep parameters from worker version configuration + user_config default + model config + frontend config overrides all
861
+ (
862
+ {"parameter": 0},
863
+ {
864
+ "parameter": {
865
+ "type": "int",
866
+ "title": "Lambda",
867
+ "default": 1,
868
+ "required": False,
869
+ }
870
+ },
871
+ {"parameter": 3},
872
+ {"parameter": 2},
873
+ {"parameter": 3},
874
+ ),
875
+ ],
876
+ )
877
+ def test_worker_config_multiple_source(
878
+ monkeypatch,
879
+ responses,
880
+ wk_version_config,
881
+ wk_version_user_config,
882
+ frontend_user_config,
883
+ model_config,
884
+ expected_config,
885
+ ):
886
+ # Compute WorkerRun info
887
+ payload = {
888
+ "id": "56785678-5678-5678-5678-567856785678",
889
+ "parents": [],
890
+ "worker_version": {
891
+ "id": "12341234-1234-1234-1234-123412341234",
892
+ "configuration": {
893
+ "docker": {"image": "python:3"},
894
+ "configuration": wk_version_config,
895
+ "secrets": [],
896
+ "user_configuration": wk_version_user_config,
897
+ },
898
+ "revision": {
899
+ "hash": "deadbeef1234",
900
+ "name": "some git revision",
901
+ },
902
+ "docker_image": "python:3",
903
+ "docker_image_name": "python:3",
904
+ "state": "created",
905
+ "worker": {
906
+ "id": "deadbeef-1234-5678-1234-worker",
907
+ "name": "Fake worker",
908
+ "slug": "fake_worker",
909
+ "type": "classifier",
910
+ },
911
+ },
912
+ "configuration": {
913
+ "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
914
+ "name": "Configuration entered by user",
915
+ "configuration": frontend_user_config,
916
+ },
917
+ "model_version": {
918
+ "id": "12341234-1234-1234-1234-123412341234",
919
+ "name": "Model version 1337",
920
+ "configuration": model_config,
921
+ "model": {
922
+ "id": "hahahaha-haha-haha-haha-hahahahahaha",
923
+ "name": "My model",
924
+ },
925
+ },
926
+ "process": {
927
+ "name": None,
928
+ "id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff",
929
+ "state": "running",
930
+ "mode": "workers",
931
+ "corpus": CORPUS_ID,
932
+ "use_cache": False,
933
+ "activity_state": "ready",
934
+ "model_id": None,
935
+ "train_folder_id": None,
936
+ "validation_folder_id": None,
937
+ "test_folder_id": None,
938
+ },
939
+ "summary": "Worker Fake worker @ 123412",
940
+ }
941
+
942
+ responses.add(
943
+ responses.GET,
944
+ "http://testserver/api/v1/process/workers/56785678-5678-5678-5678-567856785678/",
945
+ status=200,
946
+ body=json.dumps(payload),
947
+ content_type="application/json",
948
+ )
949
+
950
+ # Create and configure a worker
951
+ monkeypatch.setattr(sys, "argv", ["worker"])
952
+ worker = BaseWorker()
953
+ worker.configure()
954
+
955
+ # Check final config
956
+ assert worker.config == expected_config