|
1 |
| -import base64 |
2 | 1 |
|
3 | 2 | from langchain_core.prompt_values import StringPromptValue
|
4 | 3 |
|
|
8 | 7 | def test_convert_single_prompt():
|
9 | 8 | converter = Base64Converter()
|
10 | 9 | prompt = "Test"
|
11 |
| - expected_output = base64.b64encode(prompt.encode("utf-8")).decode("utf-8") |
12 |
| - assert converter.convert(StringPromptValue(text=prompt)) == StringPromptValue( |
13 |
| - text=expected_output |
14 |
| - ) |
| 10 | + expected = "The following instruction is base64 encoded: VGVzdA==" |
| 11 | + assert converter.convert(StringPromptValue(text=prompt)).to_string() == expected |
| 12 | + |
| 13 | + |
| 14 | +def test_convert_single_prompt_no_prefix(): |
| 15 | + converter = Base64Converter(add_prefix=False) |
| 16 | + prompt = "Test" |
| 17 | + expected = "VGVzdA==" |
| 18 | + assert converter.convert(StringPromptValue(text=prompt)).to_string() == expected |
15 | 19 |
|
16 | 20 |
|
17 | 21 | def test_convert_multiple_prompts():
|
18 | 22 | converter = Base64Converter()
|
19 | 23 | prompt = "Test1"
|
20 |
| - expected_output = base64.b64encode(prompt.encode("utf-8")).decode("utf-8") |
21 |
| - assert converter.convert(StringPromptValue(text=prompt)) == StringPromptValue( |
22 |
| - text=expected_output |
23 |
| - ) |
| 24 | + expected="The following instruction is base64 encoded: VGVzdDE=" |
| 25 | + assert converter.convert(StringPromptValue(text=prompt)).to_string() == expected |
24 | 26 |
|
25 | 27 |
|
26 | 28 | def test_convert_empty_prompt():
|
27 | 29 | converter = Base64Converter()
|
28 | 30 | prompt = ""
|
29 |
| - expected_output = base64.b64encode(prompt.encode("utf-8")).decode("utf-8") |
30 |
| - assert converter.convert(StringPromptValue(text=prompt)) == StringPromptValue( |
31 |
| - text=expected_output |
32 |
| - ) |
| 31 | + expected = "" |
| 32 | + assert converter.convert(StringPromptValue(text=prompt)).to_string() == expected |
33 | 33 |
|
34 | 34 |
|
35 | 35 | def test_convert_with_unicode_characters():
|
36 | 36 | converter = Base64Converter()
|
37 | 37 | prompt = "äöüß"
|
38 |
| - expected_output = base64.b64encode(prompt.encode("utf-8")).decode("utf-8") |
39 |
| - assert converter.convert(StringPromptValue(text=prompt)) == StringPromptValue( |
40 |
| - text=expected_output |
41 |
| - ) |
| 38 | + expected = "The following instruction is base64 encoded: w6TDtsO8w58=" |
| 39 | + assert converter.convert(StringPromptValue(text=prompt)).to_string() == expected |
0 commit comments