ara-cli 0.1.9.92__py3-none-any.whl → 0.1.9.94__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.
@@ -2,6 +2,11 @@ import pytest
2
2
  from unittest.mock import MagicMock, patch
3
3
  from ara_cli.artefact_lister import ArtefactLister
4
4
  from ara_cli.list_filter import ListFilter
5
+ from ara_cli.artefact_models.artefact_data_retrieval import (
6
+ artefact_content_retrieval,
7
+ artefact_path_retrieval,
8
+ artefact_tags_retrieval,
9
+ )
5
10
 
6
11
 
7
12
  @pytest.fixture
@@ -9,66 +14,6 @@ def artefact_lister():
9
14
  return ArtefactLister()
10
15
 
11
16
 
12
- @pytest.mark.parametrize(
13
- "users, status, tags, expected_tags",
14
- [
15
- # Normal case with all fields populated
16
- (
17
- ["john", "alice"],
18
- "in-progress",
19
- ["important", "urgent"],
20
- ["user_john", "user_alice", "in-progress", "important", "urgent"]
21
- ),
22
- # Case with empty users
23
- (
24
- [],
25
- "to-do",
26
- ["feature", "backend"],
27
- ["to-do", "feature", "backend"]
28
- ),
29
- # Case with empty tags
30
- (
31
- ["bob"],
32
- "done",
33
- [],
34
- ["user_bob", "done"]
35
- ),
36
- # Case with all empty fields
37
- (
38
- [],
39
- "",
40
- [],
41
- [""]
42
- ),
43
- # Case with None values for tags (should handle gracefully)
44
- (
45
- ["admin"],
46
- "closed",
47
- None,
48
- ["user_admin", "closed"]
49
- ),
50
- ]
51
- )
52
- def test_artefact_tags_retrieval(users, status, tags, expected_tags):
53
- # Create a mock artefact with the specified attributes
54
- artefact_mock = MagicMock()
55
- artefact_mock.users = users
56
- artefact_mock.status = status
57
- artefact_mock.tags = tags if tags is not None else []
58
-
59
- # Call the method under test
60
- result = ArtefactLister.artefact_tags_retrieval(artefact_mock)
61
-
62
- # Verify the result
63
- assert result == expected_tags
64
-
65
-
66
- def test_artefact_tags_retrieval_with_none():
67
- # Test with None artefact
68
- result = ArtefactLister.artefact_tags_retrieval(None)
69
- assert result == []
70
-
71
-
72
17
  @pytest.mark.parametrize(
73
18
  "classified_files, list_filter, filter_result",
74
19
  [
@@ -76,39 +21,36 @@ def test_artefact_tags_retrieval_with_none():
76
21
  (
77
22
  {"type1": [MagicMock(), MagicMock()]},
78
23
  None,
79
- {"type1": [MagicMock(), MagicMock()]}
24
+ {"type1": [MagicMock(), MagicMock()]},
80
25
  ),
81
26
  # Case 2: Filter with include tags
82
27
  (
83
28
  {"type1": [MagicMock(), MagicMock()]},
84
29
  ListFilter(include_tags=["tag1"]),
85
- {"type1": [MagicMock()]}
30
+ {"type1": [MagicMock()]},
86
31
  ),
87
32
  # Case 3: Filter with exclude tags
88
33
  (
89
34
  {"type1": [MagicMock(), MagicMock()], "type2": [MagicMock()]},
90
35
  ListFilter(exclude_tags=["tag2"]),
91
- {"type1": [MagicMock()], "type2": []}
36
+ {"type1": [MagicMock()], "type2": []},
92
37
  ),
93
38
  # Case 4: Empty result after filtering
94
39
  (
95
40
  {"type1": [MagicMock(), MagicMock()]},
96
41
  ListFilter(include_tags=["nonexistent"]),
97
- {"type1": []}
42
+ {"type1": []},
98
43
  ),
99
44
  # Case 5: Multiple artefact types
100
45
  (
101
46
  {"type1": [MagicMock()], "type2": [MagicMock(), MagicMock()]},
102
47
  ListFilter(exclude_extension=[".txt"]),
103
- {"type1": [], "type2": [MagicMock()]}
48
+ {"type1": [], "type2": [MagicMock()]},
104
49
  ),
105
50
  ],
106
51
  )
107
52
  def test_filter_artefacts(
108
- artefact_lister,
109
- classified_files,
110
- list_filter,
111
- filter_result
53
+ artefact_lister, classified_files, list_filter, filter_result
112
54
  ):
113
55
  # Mock the filter_list function
114
56
  with patch("ara_cli.artefact_lister.filter_list") as mock_filter_list:
@@ -121,9 +63,9 @@ def test_filter_artefacts(
121
63
  mock_filter_list.assert_called_once_with(
122
64
  list_to_filter=classified_files,
123
65
  list_filter=list_filter,
124
- content_retrieval_strategy=ArtefactLister.artefact_content_retrieval,
125
- file_path_retrieval=ArtefactLister.artefact_path_retrieval,
126
- tag_retrieval=ArtefactLister.artefact_tags_retrieval
66
+ content_retrieval_strategy=artefact_content_retrieval,
67
+ file_path_retrieval=artefact_path_retrieval,
68
+ tag_retrieval=artefact_tags_retrieval,
127
69
  )
128
70
 
129
71
  # Verify the structure matches (don't compare the actual MagicMock objects)
@@ -132,30 +74,6 @@ def test_filter_artefacts(
132
74
  assert len(result[key]) == len(filter_result[key])
133
75
 
134
76
 
135
- @pytest.mark.parametrize("artefact_content", ["content1", "content2", "content3"])
136
- def test_artefact_content_retrieval(artefact_content):
137
- artefact_mock = MagicMock()
138
- artefact_mock.serialize.return_value = artefact_content # Mock serialize()
139
-
140
- content = ArtefactLister.artefact_content_retrieval(artefact_mock)
141
- assert content == artefact_content
142
-
143
-
144
- @pytest.mark.parametrize(
145
- "file_path",
146
- [
147
- ("./ara/userstories/test.userstory"),
148
- ("./ara/epics/test.epic"),
149
- ],
150
- )
151
- def test_artefact_path_retrieval(file_path):
152
- artefact_mock = MagicMock()
153
- artefact_mock.file_path = file_path
154
-
155
- path = ArtefactLister.artefact_path_retrieval(artefact_mock)
156
- assert path == file_path
157
-
158
-
159
77
  @pytest.mark.parametrize(
160
78
  "tags, navigate_to_target, list_filter, mock_artefacts, filtered_artefacts, expected_filtered",
161
79
  [
@@ -476,20 +394,21 @@ def test_list_data_artefact_found_data_exists(artefact_lister):
476
394
  classified_artefacts = {
477
395
  "epic": [
478
396
  {"title": "Epic1", "file_path": "path/to/Epic1.epic"},
479
- {"title": "Epic2", "file_path": "path/to/Epic2.epic"}
397
+ {"title": "Epic2", "file_path": "path/to/Epic2.epic"},
480
398
  ]
481
399
  }
482
-
483
- with patch("ara_cli.artefact_lister.FileClassifier") as mock_file_classifier, \
484
- patch("ara_cli.artefact_lister.suggest_close_name_matches") as mock_suggest, \
485
- patch("ara_cli.artefact_lister.os") as mock_os, \
486
- patch("ara_cli.artefact_lister.list_files_in_directory") as mock_list_files:
400
+
401
+ with patch("ara_cli.artefact_lister.FileClassifier") as mock_file_classifier, patch(
402
+ "ara_cli.artefact_lister.suggest_close_name_matches"
403
+ ) as mock_suggest, patch("ara_cli.artefact_lister.os") as mock_os, patch(
404
+ "ara_cli.artefact_lister.list_files_in_directory"
405
+ ) as mock_list_files:
487
406
 
488
407
  # Configure mocks
489
408
  mock_classifier_instance = MagicMock()
490
409
  mock_file_classifier.return_value = mock_classifier_instance
491
410
  mock_classifier_instance.classify_files.return_value = classified_artefacts
492
-
411
+
493
412
  mock_os.path.splitext.return_value = ("path/to/Epic1", ".epic")
494
413
  mock_os.path.exists.return_value = True
495
414
 
@@ -510,20 +429,21 @@ def test_list_data_artefact_found_data_not_exists(artefact_lister):
510
429
  classified_artefacts = {
511
430
  "epic": [
512
431
  {"title": "Epic1", "file_path": "path/to/Epic1.epic"},
513
- {"title": "Epic2", "file_path": "path/to/Epic2.epic"}
432
+ {"title": "Epic2", "file_path": "path/to/Epic2.epic"},
514
433
  ]
515
434
  }
516
-
517
- with patch("ara_cli.artefact_lister.FileClassifier") as mock_file_classifier, \
518
- patch("ara_cli.artefact_lister.suggest_close_name_matches") as mock_suggest, \
519
- patch("ara_cli.artefact_lister.os") as mock_os, \
520
- patch("ara_cli.artefact_lister.list_files_in_directory") as mock_list_files:
435
+
436
+ with patch("ara_cli.artefact_lister.FileClassifier") as mock_file_classifier, patch(
437
+ "ara_cli.artefact_lister.suggest_close_name_matches"
438
+ ) as mock_suggest, patch("ara_cli.artefact_lister.os") as mock_os, patch(
439
+ "ara_cli.artefact_lister.list_files_in_directory"
440
+ ) as mock_list_files:
521
441
 
522
442
  # Configure mocks
523
443
  mock_classifier_instance = MagicMock()
524
444
  mock_file_classifier.return_value = mock_classifier_instance
525
445
  mock_classifier_instance.classify_files.return_value = classified_artefacts
526
-
446
+
527
447
  mock_os.path.splitext.return_value = ("path/to/Epic1", ".epic")
528
448
  mock_os.path.exists.return_value = False
529
449
 
@@ -544,14 +464,15 @@ def test_list_data_artefact_not_found(artefact_lister):
544
464
  classified_artefacts = {
545
465
  "epic": [
546
466
  {"title": "Epic1", "file_path": "path/to/Epic1.epic"},
547
- {"title": "Epic2", "file_path": "path/to/Epic2.epic"}
467
+ {"title": "Epic2", "file_path": "path/to/Epic2.epic"},
548
468
  ]
549
469
  }
550
-
551
- with patch("ara_cli.artefact_lister.FileClassifier") as mock_file_classifier, \
552
- patch("ara_cli.artefact_lister.suggest_close_name_matches") as mock_suggest, \
553
- patch("ara_cli.artefact_lister.os") as mock_os, \
554
- patch("ara_cli.artefact_lister.list_files_in_directory") as mock_list_files:
470
+
471
+ with patch("ara_cli.artefact_lister.FileClassifier") as mock_file_classifier, patch(
472
+ "ara_cli.artefact_lister.suggest_close_name_matches"
473
+ ) as mock_suggest, patch("ara_cli.artefact_lister.os") as mock_os, patch(
474
+ "ara_cli.artefact_lister.list_files_in_directory"
475
+ ) as mock_list_files:
555
476
 
556
477
  # Configure mocks
557
478
  mock_classifier_instance = MagicMock()
@@ -562,10 +483,7 @@ def test_list_data_artefact_not_found(artefact_lister):
562
483
  artefact_lister.list_data(classifier, artefact_name, list_filter)
563
484
 
564
485
  # Verify interactions
565
- mock_suggest.assert_called_once_with(
566
- artefact_name,
567
- ["Epic1", "Epic2"]
568
- )
486
+ mock_suggest.assert_called_once_with(artefact_name, ["Epic1", "Epic2"])
569
487
  mock_os.path.splitext.assert_not_called()
570
488
  mock_os.path.exists.assert_not_called()
571
489
  mock_list_files.assert_not_called()
@@ -578,20 +496,21 @@ def test_list_data_with_filter(artefact_lister):
578
496
  classified_artefacts = {
579
497
  "userstory": [
580
498
  {"title": "Story1", "file_path": "path/to/Story1.userstory"},
581
- {"title": "Story2", "file_path": "path/to/Story2.userstory"}
499
+ {"title": "Story2", "file_path": "path/to/Story2.userstory"},
582
500
  ]
583
501
  }
584
-
585
- with patch("ara_cli.artefact_lister.FileClassifier") as mock_file_classifier, \
586
- patch("ara_cli.artefact_lister.suggest_close_name_matches") as mock_suggest, \
587
- patch("ara_cli.artefact_lister.os") as mock_os, \
588
- patch("ara_cli.artefact_lister.list_files_in_directory") as mock_list_files:
502
+
503
+ with patch("ara_cli.artefact_lister.FileClassifier") as mock_file_classifier, patch(
504
+ "ara_cli.artefact_lister.suggest_close_name_matches"
505
+ ) as mock_suggest, patch("ara_cli.artefact_lister.os") as mock_os, patch(
506
+ "ara_cli.artefact_lister.list_files_in_directory"
507
+ ) as mock_list_files:
589
508
 
590
509
  # Configure mocks
591
510
  mock_classifier_instance = MagicMock()
592
511
  mock_file_classifier.return_value = mock_classifier_instance
593
512
  mock_classifier_instance.classify_files.return_value = classified_artefacts
594
-
513
+
595
514
  mock_os.path.splitext.return_value = ("path/to/Story1", ".userstory")
596
515
  mock_os.path.exists.return_value = True
597
516
 
@@ -610,11 +529,12 @@ def test_list_data_empty_artefact_list(artefact_lister):
610
529
  artefact_name = "Epic1"
611
530
  list_filter = None
612
531
  classified_artefacts = {"epic": []}
613
-
614
- with patch("ara_cli.artefact_lister.FileClassifier") as mock_file_classifier, \
615
- patch("ara_cli.artefact_lister.suggest_close_name_matches") as mock_suggest, \
616
- patch("ara_cli.artefact_lister.os") as mock_os, \
617
- patch("ara_cli.artefact_lister.list_files_in_directory") as mock_list_files:
532
+
533
+ with patch("ara_cli.artefact_lister.FileClassifier") as mock_file_classifier, patch(
534
+ "ara_cli.artefact_lister.suggest_close_name_matches"
535
+ ) as mock_suggest, patch("ara_cli.artefact_lister.os") as mock_os, patch(
536
+ "ara_cli.artefact_lister.list_files_in_directory"
537
+ ) as mock_list_files:
618
538
 
619
539
  # Configure mocks
620
540
  mock_classifier_instance = MagicMock()
tests/test_chat.py CHANGED
@@ -635,14 +635,14 @@ def test_load_file(temp_chat_file, file_name, file_type, mime_type):
635
635
  patch.object(chat, 'load_text_file', return_value=True) as mock_load_text, \
636
636
  patch.object(chat, 'load_document_file', return_value=True) as mock_load_document:
637
637
 
638
- chat.load_file(file_name=file_name, prefix="p-", suffix="-s", block_delimiter="b", extract_images=False)
638
+ chat.load_file(file_name=file_name, prefix="p-", suffix="-f", block_delimiter="b", extract_images=False)
639
639
 
640
640
  if file_type == "binary":
641
641
  mock_load_binary.assert_called_once_with(
642
642
  file_path=file_name,
643
643
  mime_type=mime_type,
644
644
  prefix="p-",
645
- suffix="-s"
645
+ suffix="-f"
646
646
  )
647
647
  mock_load_text.assert_not_called()
648
648
  mock_load_document.assert_not_called()
@@ -652,7 +652,7 @@ def test_load_file(temp_chat_file, file_name, file_type, mime_type):
652
652
  mock_load_document.assert_called_once_with(
653
653
  file_path=file_name,
654
654
  prefix="p-",
655
- suffix="-s",
655
+ suffix="-f",
656
656
  block_delimiter="b",
657
657
  extract_images=False
658
658
  )
@@ -661,7 +661,7 @@ def test_load_file(temp_chat_file, file_name, file_type, mime_type):
661
661
  mock_load_text.assert_called_once_with(
662
662
  file_path=file_name,
663
663
  prefix="p-",
664
- suffix="-s",
664
+ suffix="-f",
665
665
  block_delimiter="b",
666
666
  extract_images=False
667
667
  )
@@ -714,7 +714,7 @@ def test_load_helper(monkeypatch, capsys, temp_chat_file, directory, pattern, fi
714
714
  def mock_input(prompt):
715
715
  return user_input
716
716
 
717
- def mock_load_file(self, file_path, prefix="", suffix=""):
717
+ def mock_load_file(self, file_path):
718
718
  return True
719
719
 
720
720
  monkeypatch.setattr(glob, 'glob', mock_glob)
@@ -750,7 +750,7 @@ def test_load_helper_with_exclude(monkeypatch, capsys, temp_chat_file, directory
750
750
  def mock_input(prompt):
751
751
  return user_input
752
752
 
753
- def mock_load_file(self, file_path, prefix="", suffix=""):
753
+ def mock_load_file(self, file_path):
754
754
  return True
755
755
 
756
756
  monkeypatch.setattr(glob, 'glob', mock_glob)
@@ -907,7 +907,7 @@ def test_load_image(capsys, temp_chat_file, file_name, is_image, expected_mime):
907
907
  chat = Chat(temp_chat_file.name, reset=False)
908
908
 
909
909
  with patch.object(chat, 'load_binary_file', return_value=True) as mock_load_binary:
910
- chat.load_image(file_name=file_name, prefix="p-", suffix="-s")
910
+ chat.load_image(file_name=file_name, prefix="p-", suffix="-f")
911
911
 
912
912
  if is_image:
913
913
  # FIX: The called method's parameter is `file_path`, not `file_name`.
@@ -915,7 +915,7 @@ def test_load_image(capsys, temp_chat_file, file_name, is_image, expected_mime):
915
915
  file_path=file_name,
916
916
  mime_type=expected_mime,
917
917
  prefix="p-",
918
- suffix="-s"
918
+ suffix="-f"
919
919
  )
920
920
  else:
921
921
  mock_load_binary.assert_not_called()
@@ -1232,13 +1232,14 @@ def test_do_EXTRACT(MockExtractCommand, temp_chat_file):
1232
1232
  with patch('ara_cli.prompt_handler.ConfigManager.get_config', return_value=mock_config):
1233
1233
  chat = Chat(temp_chat_file.name, reset=False)
1234
1234
 
1235
- # FIX: The `onecmd_plus_hooks` method requires the `orig_rl_history_length` argument.
1235
+ # The `onecmd_plus_hooks` method requires the `orig_rl_history_length` argument.
1236
1236
  # We can pass a dummy value like 0 for the test.
1237
1237
  chat.onecmd_plus_hooks("EXTRACT", orig_rl_history_length=0)
1238
1238
 
1239
1239
  MockExtractCommand.assert_called_once_with(
1240
1240
  file_name=chat.chat_name,
1241
- skip_queries=False,
1241
+ force=False,
1242
+ write=False,
1242
1243
  output=chat.poutput,
1243
1244
  error_output=chat.perror
1244
1245
  )