mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-06 06:01:31 -05:00
fix: test catch if function is empty (#54597)
This commit is contained in:
@@ -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)
|
||||
`))
|
||||
})
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user