Skip to content

Commit 3bb17be

Browse files
committed
python: add concept and library tests
1 parent ce3ee65 commit 3bb17be

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

python/ql/test/experimental/meta/ConceptsTest.qll

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,42 @@ class SqlExecutionTest extends InlineExpectationsTest {
164164
}
165165
}
166166

167+
class XPathConstructionTest extends InlineExpectationsTest {
168+
XPathConstructionTest() { this = "XPathConstructionTest" }
169+
170+
override string getARelevantTag() { result = "constructedXPath" }
171+
172+
override predicate hasActualResult(Location location, string element, string tag, string value) {
173+
exists(location.getFile().getRelativePath()) and
174+
exists(XPathConstruction e, DataFlow::Node xpath |
175+
exists(location.getFile().getRelativePath()) and
176+
xpath = e.getXPath() and
177+
location = e.getLocation() and
178+
element = xpath.toString() and
179+
value = prettyNodeForInlineTest(xpath) and
180+
tag = "constructedXPath"
181+
)
182+
}
183+
}
184+
185+
class XPathExecutionTest extends InlineExpectationsTest {
186+
XPathExecutionTest() { this = "XPathExecutionTest" }
187+
188+
override string getARelevantTag() { result = "getXPath" }
189+
190+
override predicate hasActualResult(Location location, string element, string tag, string value) {
191+
exists(location.getFile().getRelativePath()) and
192+
exists(XPathExecution e, DataFlow::Node xpath |
193+
exists(location.getFile().getRelativePath()) and
194+
xpath = e.getXPath() and
195+
location = e.getLocation() and
196+
element = xpath.toString() and
197+
value = prettyNodeForInlineTest(xpath) and
198+
tag = "getXPath"
199+
)
200+
}
201+
}
202+
167203
class EscapingTest extends InlineExpectationsTest {
168204
EscapingTest() { this = "EscapingTest" }
169205

python/ql/test/library-tests/frameworks/lxml/ConceptsTest.expected

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import python
2+
import experimental.meta.ConceptsTest
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from lxml import etree
2+
from io import StringIO
3+
4+
def test_parse():
5+
tree = etree.parse(StringIO('<foo><bar></bar></foo>'))
6+
r = tree.xpath('/foo/bar') # $ getXPath='/foo/bar'
7+
8+
def test_XPath_class():
9+
root = etree.XML("<root><a>TEXT</a></root>")
10+
find_text = etree.XPath("path") # $ constructedXPath="path"
11+
text = find_text(root)[0]
12+
13+
def test_ETXpath_class():
14+
root = etree.XML("<root><a>TEXT</a></root>")
15+
find_text = etree.ETXPath("path") # $ constructedXPath="path"
16+
text = find_text(root)[0]
17+
18+
def test_XPathEvaluator_class():
19+
root = etree.XML("<root><a>TEXT</a></root>")
20+
search_root = etree.XPathEvaluator(root)
21+
text = search_root("path")[0] # $ MISSING: getXPath="path"

0 commit comments

Comments
 (0)