Python: Add tests for full Python 3 parameters syntax

Currently keyword-only parameters are not handled properly :(
This commit is contained in:
Rasmus Wriedt Larsen
2020-04-24 14:48:53 +02:00
parent 96b36a7f0f
commit 0cc8d49112
20 changed files with 113 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
| test.py:4:1:11:2 | Function func | test.py:5:5:5:12 | pos_only |
| test.py:4:1:11:2 | Function func | test.py:7:5:7:10 | normal |
| test.py:4:1:11:2 | Function func | test.py:8:6:8:9 | args |
| test.py:4:1:11:2 | Function func | test.py:10:7:10:12 | kwargs |
| test.py:4:1:11:2 | Function func | test.py:12:5:12:41 | ExprStmt |
| test.py:4:1:11:2 | Function func | test.py:13:5:13:15 | ExprStmt |
| test.py:4:1:11:2 | Function func | test.py:14:5:14:17 | ExprStmt |

View File

@@ -0,0 +1,4 @@
import python
from Function f
select f, f.getAChildNode()

View File

@@ -0,0 +1,2 @@
| test.py:4:1:11:2 | Function func | 0 | test.py:5:5:5:12 | Parameter |
| test.py:4:1:11:2 | Function func | 1 | test.py:7:5:7:10 | Parameter |

View File

@@ -0,0 +1,4 @@
import python
from Function f, int i
select f, i, f.getArg(i)

View File

@@ -0,0 +1,2 @@
| test.py:4:1:11:2 | Function func | normal | test.py:7:5:7:10 | Parameter |
| test.py:4:1:11:2 | Function func | pos_only | test.py:5:5:5:12 | Parameter |

View File

@@ -0,0 +1,4 @@
import python
from Function f, string name
select f, name, f.getArgByName(name)

View File

@@ -0,0 +1,7 @@
| test.py:4:1:11:2 | FunctionExpr | test.py:5:15:5:17 | int |
| test.py:4:1:11:2 | FunctionExpr | test.py:5:21:5:22 | UnaryExpr |
| test.py:4:1:11:2 | FunctionExpr | test.py:7:13:7:15 | int |
| test.py:4:1:11:2 | FunctionExpr | test.py:7:19:7:20 | UnaryExpr |
| test.py:4:1:11:2 | FunctionExpr | test.py:8:12:8:23 | Str |
| test.py:4:1:11:2 | FunctionExpr | test.py:9:25:9:26 | UnaryExpr |
| test.py:4:1:11:2 | FunctionExpr | test.py:10:15:10:30 | Str |

View File

@@ -0,0 +1,4 @@
import python
from FunctionExpr fe
select fe, fe.getASubExpression()

View File

@@ -0,0 +1,2 @@
| test.py:4:1:11:2 | FunctionExpr | Arguments | test.py:5:21:5:22 | UnaryExpr |
| test.py:4:1:11:2 | FunctionExpr | Arguments | test.py:7:19:7:20 | UnaryExpr |

View File

@@ -0,0 +1,4 @@
import python
from FunctionExpr fe
select fe, fe.getArgs(), fe.getArgs().getADefault()

View File

@@ -0,0 +1 @@
| test.py:4:1:11:2 | FunctionExpr | Arguments | test.py:9:25:9:26 | UnaryExpr |

View File

@@ -0,0 +1,4 @@
import python
from FunctionExpr fe
select fe, fe.getArgs(), fe.getArgs().getAKwDefault()

View File

@@ -0,0 +1,20 @@
# not importing typing so we don't need to filter by location in Ql tests
def func(
pos_only: int = -1,
/,
normal: int = -2,
*args: "Tuple[str]",
keyword_only: int = -3,
**kwargs: "Dict[str, str]",
):
print(pos_only, normal, keyword_only)
print(args)
print(kwargs)
func(1, 2, keyword_only=3)
func(4, normal=5, keyword_only=6)
func(1, 2, "varargs0", "varargs1", keyword_only=3, kwargs0="0", kwargs1="1")

View File

@@ -0,0 +1,4 @@
| args | test.py:8:12:8:23 | Str |
| kwargs | test.py:10:15:10:30 | Str |
| normal | test.py:7:13:7:15 | int |
| pos_only | test.py:5:15:5:17 | int |

View File

@@ -0,0 +1,4 @@
import python
from Parameter p
select p.getName(), p.getAnnotation()

View File

@@ -0,0 +1,2 @@
| normal | test.py:7:19:7:20 | UnaryExpr |
| pos_only | test.py:5:21:5:22 | UnaryExpr |

View File

@@ -0,0 +1,4 @@
import python
from Parameter p
select p.getName(), p.getDefault()

View File

@@ -0,0 +1,4 @@
| args | varargs |
| kwargs | kwargs |
| normal | normal |
| pos_only | normal |

View File

@@ -0,0 +1,10 @@
import python
from Parameter p, string type
where
p.isKwargs() and type = "kwargs"
or
p.isVarargs() and type = "varargs"
or
not p.isKwargs() and not p.isVarargs() and type = "normal"
select p.getName(), type

View File

@@ -0,0 +1,20 @@
# not importing typing so we don't need to filter by location in Ql tests
def func(
pos_only: int = -1,
/,
normal: int = -2,
*args: "Tuple[str]",
keyword_only: int = -3,
**kwargs: "Dict[str, str]",
):
print(pos_only, normal, keyword_only)
print(args)
print(kwargs)
func(1, 2, keyword_only=3)
func(4, normal=5, keyword_only=6)
func(1, 2, "varargs0", "varargs1", keyword_only=3, kwargs0="0", kwargs1="1")