@@ -33,7 +33,7 @@ def test_docs():
33
33
def test_evidence ():
34
34
doc_path = "example.txt"
35
35
with open (doc_path , "w" , encoding = "utf-8" ) as f :
36
- # get wiki page about Obama
36
+ # get wiki page about politician
37
37
r = requests .get ("https://en.wikipedia.org/wiki/Frederick_Bates_(politician)" )
38
38
f .write (r .text )
39
39
docs = paperqa .Docs ()
@@ -48,7 +48,7 @@ def test_evidence():
48
48
def test_query ():
49
49
doc_path = "example.txt"
50
50
with open (doc_path , "w" , encoding = "utf-8" ) as f :
51
- # get wiki page about Obama
51
+ # get wiki page about politician
52
52
r = requests .get ("https://en.wikipedia.org/wiki/Frederick_Bates_(politician)" )
53
53
f .write (r .text )
54
54
docs = paperqa .Docs ()
@@ -73,3 +73,46 @@ def test_docs_pickle():
73
73
"What is today?" , k = 1 , max_sources = 1
74
74
) == docs2 .get_evidence ("What is today?" , k = 1 , max_sources = 1 )
75
75
os .remove (doc_path )
76
+
77
+
78
+ def test_bad_context ():
79
+ doc_path = "example.txt"
80
+ with open (doc_path , "w" , encoding = "utf-8" ) as f :
81
+ # get wiki page about politician
82
+ r = requests .get ("https://en.wikipedia.org/wiki/Frederick_Bates_(politician)" )
83
+ f .write (r .text )
84
+ docs = paperqa .Docs ()
85
+ docs .add (doc_path , "WikiMedia Foundation, 2023, Accessed now" )
86
+ answer = docs .query ("What year was Barack Obama born greatest accomplishment?" )
87
+ assert (
88
+ answer .answer
89
+ == "I cannot answer this question due to insufficient information."
90
+ )
91
+ os .remove (doc_path )
92
+
93
+
94
+ def test_repeat_keys ():
95
+ doc_path = "example.txt"
96
+ with open (doc_path , "w" , encoding = "utf-8" ) as f :
97
+ # get wiki page about politician
98
+ r = requests .get ("https://en.wikipedia.org/wiki/Frederick_Bates_(politician)" )
99
+ f .write (r .text )
100
+ docs = paperqa .Docs ()
101
+ docs .add (doc_path , "WikiMedia Foundation, 2023, Accessed now" )
102
+ docs .add (doc_path , "WikiMedia Foundation, 2023, Accessed now" )
103
+ assert len (docs .docs ) == 1
104
+
105
+ # now with different paths
106
+ doc_path2 = "example2.txt"
107
+ with open (doc_path2 , "w" , encoding = "utf-8" ) as f :
108
+ # get wiki page about politician
109
+ f .write (r .text )
110
+ docs .add (doc_path2 , "WikiMedia Foundation, 2023, Accessed now" )
111
+ assert len (docs .docs ) == 2
112
+
113
+ # check keys
114
+ assert docs .docs [doc_path ]["key" ] == "Wiki2023"
115
+ assert docs .docs [doc_path2 ]["key" ] == "Wiki2023a"
116
+
117
+ os .remove (doc_path )
118
+ os .remove (doc_path2 )
0 commit comments