A Python package to check if an object is of a certain type in an instant.
poetry install
poetry shell
pytest
This package was created with Cookiecutter and the joaopalmeiro/cookiecutter-templates/python-pkg
project template.
- pyenv:
pyenv local 3.6.13
. It generates a.python-version
file. It is similar to the.nvmrc
file (nvm).- Should we gitignore the .python-version file?.
- Vim:
- Learning tools:
- Two basic modes:
insert
mode (i
): to write text (like in a text editor).normal
mode (Esc
): to navigate and manipulate text.
- Basic movement:
h
(←),j
(↓),k
(↑), andl
(→). - Word movement:
w
: start of the next word.e
: end of the word.b
: beginning of the word.- These keys can be combined with a number (number powered movement).
3w
is the same as pressingw
3x, for example.
- Insert text repeatedly:
30
+i
+-
+Esc
to insert-
30x, for example. - Find a character:
f
: next occurrence of a character.F
: previous occurrence of a character.fo
to find the nexto
, for example.- These keys can also be combined with numbers.
- Go to matching parentheses:
%
. - Go to start/end of line:
0
/$
. - Find word under cursor:
*
: next occurrence.#
: previous occurrence.
- Go to beginning/end of file:
gg
/G
.G
can be combined with a number too. - Search:
/<text>
.n
: next occurrence.N
: previous occurrence.
- Insert new line:
o
: below the current line.O
: above the current line.- The editor is set to
insert
mode.
- Remove a character:
x
: under the cursor.X
: to the left of the cursor.
- Replace a character:
r
.- Under the cursor, without switching to
insert
mode.
- Delete:
d
.- It can be combined with numbers and movement keys (
dw
andd2e
, for example). - It copies the content. Content can be pasted with
p
.
- Repeat the previous command:
.
. - Visual mode:
v
.- To select text with the movement keys first and then apply a command.
- Exiting:
:w
: save.:q
: quit.:q!
: quit without saving.
- Editing:
u
: undo.Ctrl
+r
: redo.
Vim.gitignore
file.
.vimrc
file.vim --version
.- *nix or Unix-like systems.
- Check the Python version used in Vim:
:python import sys; print(sys.version)
. - Extensions or bundles or plugins.
- Vundle:
pip
for Vim/Vim plugin manager.git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
.- Extensions can be managed from the
.vimrc
file (touch ~/.vimrc
) +:PluginInstall
.
- Split layouts:
:sp <filename>
: vertical split.:vs <filename>
: horizontal split.
- vscode-viml-syntax (VS Code extension).
- Buffers:
- Think of a buffer as a recently opened file.
:b <buffer name or number>
: switch to an open buffer.:ls
: list all buffers.
- Extensions:
- SimpylFold (code folding).
- indentpython.vim.
- YouCompleteMe (auto-complete). Installation instructions.
- syntastic (syntax checking).
- vim-flake8.
- NERDTree (file browsing).
- CtrlP (searching).
- fugitive.vim (Git integration).
- Powerline (status bar).
poetry add -D pytest
.- Arrange (set up)-Act-Assert model.
- pytest allows you to use Python's
assert
directly. - Test double: an object that stands in for another object during a test (source), such as mocks, for example.
- Fixtures (
@pytest.fixture
decorator +conftest.py
file):- Functions that create data/test doubles or initialize some system state for the test suite.
- They are appropriate to be used across multiple tests.
- They are used as arguments (explicit dependency declarations).
- They are modular, so they can depend on other fixtures.
- Test filtering:
- Name-based filtering (
-k
). - Directory scoping.
- Test categorization (
-m <name>
or-m "not <name>"
). pytest allows you to create marks (custom labels) for any test.
- Name-based filtering (
- Test parameterization.
- Plugin-based architecture.
monkeypatch
fixture (+@pytest.fixture(autouse=True)
in theconftest.py
file): to safely patch and mock functionality in tests, allowing to set/delete an attribute, dictionary item, or environment variable, for example (requests.get()
, for example).- Marks (
@pytest.mark.<name>
):- It is possible to register marks in the
pytest.ini
file (or in thepyproject.toml
file). This can be combined with the--strict-markers
flag to ensure that all marks in the tests are registered in the pytest configuration. On the other hand,addopts = --strict-markers
can be added to thepytest.ini
file. - Run
pytest --markers
to check the list of marks. skip
: to skip a test.skipif
: to skip a test if the expression passed to it evaluates toTrue
.xfail
: a test is expected to fail.parametrize
. The first argument is a comma-delimited string of parameter names. The second argument is a list of either tuples or single values.
- It is possible to register marks in the
--durations
flag:- To include a duration report in the results.
--durations=3
to report the slowest 3 tests, for example.
- Plugins:
- List.
- pytest-randomly: to run the tests in a random order.
- pytest-cov: to generate coverage reports (coverage.py package).
- pytest-bdd (for behavior-driven development).
- Uninstall PyCharm.
- Black integration.
open -na "PyCharm CE.app"
(source).