Coverage for intelligence_toolkit/tests/unit/AI/test_metaprompts.py: 100%

36 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-10-16 13:41 -0300

1# Copyright (c) 2024 Microsoft Corporation. All rights reserved. 

2# Licensed under the MIT license. See LICENSE file in the project. 

3# 

4from intelligence_toolkit.AI.metaprompts import ( 

5 do_not_disrespect_context, 

6 do_not_harm, 

7 do_not_harm_question_answering, 

8) 

9 

10 

11def test_do_not_harm_question_answering_exists(): 

12 assert do_not_harm_question_answering is not None 

13 assert isinstance(do_not_harm_question_answering, str) 

14 assert len(do_not_harm_question_answering) > 0 

15 

16 

17def test_do_not_harm_question_answering_contains_key_phrases(): 

18 assert "Decline to answer" in do_not_harm_question_answering 

19 assert "Never" in do_not_harm_question_answering 

20 assert "speculate" in do_not_harm_question_answering 

21 assert "relevant documents" in do_not_harm_question_answering 

22 

23 

24def test_do_not_harm_exists(): 

25 assert do_not_harm is not None 

26 assert isinstance(do_not_harm, str) 

27 assert len(do_not_harm) > 0 

28 

29 

30def test_do_not_harm_contains_key_phrases(): 

31 assert "must not generate content" in do_not_harm 

32 assert "harmful" in do_not_harm 

33 assert "hateful" in do_not_harm 

34 assert "racist" in do_not_harm 

35 assert "sexist" in do_not_harm 

36 assert "violent" in do_not_harm 

37 

38 

39def test_do_not_disrespect_context_exists(): 

40 assert do_not_disrespect_context is not None 

41 assert isinstance(do_not_disrespect_context, str) 

42 assert len(do_not_disrespect_context) > 0 

43 

44 

45def test_do_not_disrespect_context_contains_key_phrases(): 

46 assert "tone of the document" in do_not_disrespect_context 

47 assert "vague" in do_not_disrespect_context 

48 assert "controversial" in do_not_disrespect_context 

49 assert "dates and times" in do_not_disrespect_context 

50 assert "professional conversation" in do_not_disrespect_context 

51 

52 

53def test_all_metaprompts_are_strings(): 

54 prompts = [ 

55 do_not_harm_question_answering, 

56 do_not_harm, 

57 do_not_disrespect_context, 

58 ] 

59 for prompt in prompts: 

60 assert isinstance(prompt, str) 

61 assert len(prompt.strip()) > 0