fix: test catch if function is empty (#54597)

This commit is contained in:
Ilenia
2024-05-07 10:32:13 +02:00
committed by GitHub
parent 5694b0837c
commit dea35985c1

View File

@@ -14,10 +14,36 @@ dashedName: step-13
You should declare a function named `generate_password`.
```js
({ test: () => assert(__pyodide.runPython(`
import inspect
generate_psw = __locals.get("generate_password")
inspect.isfunction(generate_psw)
({
test: () => assert(runPython(`
_Node(_code).has_function('generate_password')
`))
})
```
The import statements should still be outside the function.
```js
({
test: () => assert(runPython(`
imports_list = _Node(_code).find_imports()
any([imp.is_equivalent('import secrets') for imp in imports_list]) and any([imp.is_equivalent('import string') for imp in imports_list])
`))
})
```
The four variable declarations should be moved inside the function.
```js
({
test: () => assert(runPython(`
func = _Node(_code).find_function('generate_password')
vars = ['letters', 'digits', 'symbols', 'all_characters']
func.find_variable('letters').is_equivalent('letters = string.ascii_letters') and \\
func.find_variable('digits').is_equivalent('digits = string.digits') and \\
func.find_variable('symbols').is_equivalent('symbols = string.punctuation') and \\
func.find_variable('all_characters').is_equivalent('all_characters = letters + digits + symbols') and \\
all(not _Node(_code).has_variable(var) for var in vars)
`))
})
```