Please enable JavaScript.
Coggle requires JavaScript to display documents.
Hole Python - Coggle Diagram
Hole Python
Exception Handling
-
-
Custom Exceptions
All other exceptions are generated from the Exception base class #
-
-
-
Exception Performance
Remember that usage of the try-except block should be limited, it slows down the program.
-
File Handling
Reading from Files
-
Reading Methods (read, readline, readlines)
Writing to Files
Writing Methods (write, writelines)
-
File Operations (Opening, Closing, Appending)
File Modes (Read, Write, Append)
-
-
-
Syntax and Fundamentals
Variables and Data Types
Numeric Types (int, float)
-
-
-
-
-
Work with data
Data Structures
-
-
-
-
-
List Manipulation (Appending, Slicing, etc.)
-
-
-
-
-
Standard Library
Commonly Used Modules (e.g., math, random, datetime)
-
-
-
-
-
-
-
Memory Management
-
The memory manager ensures that it is enough space in your program to allocate memory. It is done by freeing objects that are not currently in use.
Python objects have three things: Type, value, and reference count.
-
Testing in Python
-
Automated testing
The assert Statement
The easiest tool you can find in Python to test your code is the assert statement. The condition should always be True unless you have a bug in your program. If it is False, then the assert raises the AssertionError exception.
But there is no need to do that because there are a lot of existing good tools to write automated tests
The unittest Framework
The unittest is a Python built-in testing framework.
The unittest is class-based, you need to put your tests into classes (that inherit from the unittest.TestCase class) as methods; you need to use a special assertion method of the unittest.TestCase class instead of the built-in assert statement.
The pytest is a python-based testing framework which is used to write and execute test codes.
First of all, you need to install the pytest by running the pip install pytest command.
Написання тестів для pytest виглядає в точності як вбудовані тести з assert Statement.
Running the pytest without mentioning a filename will run all files of the test_.py or **_test.py format (this step is called tests collection) in the current directory and subdirectories. Pytest automatically identifies those files as test files.
The pytest requires the test function names(def test_name) to start with the test. Other function names are not considered as test functions by the pytest.
The pytest.raises Method
When you want to test if your code raises the correct exception, you can use the pytest.raises as a context manager, which will capture the exception of the given type
Parametrization in the context of testing is a process of running the same test with different values from a prepared set. Each combination of a test and data is counted as a new test case. In the pytest for parametrization, we have the pytest.mark.parametrize decorator.
-
Схема тесту:
pytest.mark.parametrize(
"перелік змінних, які ми будемо призначати для кожного тесту(в спвльних лапках, через кому)",
(список кортежів з переліком значень для цих змінних)
[
(),
(),
()
]
(власне функція-тест, для якої ми зазначали перелік змінних і мноєини їж значень)
def test_...(self, перелік змінних, які ми параметризували для кожного тесту):
-
Testing in Details
Unittest Code
Mocking
Unittest
Mocking With an Unittest mock.patch
#
-
-
-
-
Organizing Pytest Code
Set Up Fixture in Pytest
Це функції, які будуть виконані до або після якогось тесту.
-
-
The test consists of the following steps: #
-
-
-
-
-