Skip to content

Instantly share code, notes, and snippets.

@felixhammerl
Created February 6, 2022 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixhammerl/9f93de071c00f774f9b8976c89b21629 to your computer and use it in GitHub Desktop.
Save felixhammerl/9f93de071c00f774f9b8976c89b21629 to your computer and use it in GitHub Desktop.
Python Snippet

For vi, place python.snippets in ~/.config/coc/ultisnips/

For vscode, paste python.json in CMD+p > Configure user snippets > Python

{
"Test Suite": {
"prefix": "mts",
"body": [
"# pyright: reportWildcardImportFromLibrary=false",
"from hamcrest import *",
"",
"",
"def test_$1():",
" $2"
]
},
"Test Function": {
"prefix": "mtc",
"body": [
"def test_$1($2):",
" $3"
]
},
"Test Run Only": {
"prefix": "tro",
"body": [
"import pytest",
"@pytest.mark.only"
]
},
"Test Assert Stage": {
"prefix": "tas",
"body": [
"import os",
"import pytest",
"STAGE = os.getenv(\"STAGE\")",
"if STAGE != \"dev\":",
" pytest.fail(msg=\"Test must be run in STAGE=dev\")"
]
},
"Hamcrest Contains List": {
"prefix": "ccl",
"body": "assert_that($1, contains_inanyorder(*$2))"
},
"Hamcrest Not None": {
"prefix": "cnn",
"body": "assert_that($1, is_(not_none()))"
},
"Hamcrest Equality": {
"prefix": "ceq",
"body": "assert_that($1, is_(equal_to($2)))"
}
}
{
snippet mts "Test Suite"
# pyright: reportWildcardImportFromLibrary=false
from hamcrest import *
def test_$1():
$2
endsnippet
snippet mtc "Test Function"
def test_$1($2):
$3
endsnippet
snippet tro "Test Run Only"
import pytest
@pytest.mark.only
endsnippet
snippet tas "Test Assert Stage"
import os
import pytest
STAGE = os.getenv("STAGE")
if STAGE != "dev":,
pytest.fail(msg="Test must be run in STAGE=dev")
endsnippet
snippet ccl "Hamcrest Contains List"
assert_that($1, contains_inanyorder(*$2))
endsnippet
snippet cnn "Hamcrest Not None"
assert_that($1, is_(not_none()))
endsnippet
snipper ceq "Hamcrest Equality": {
assert_that($1, is_(equal_to($2)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment