This requires NPM to be installed.
If your project does not already have a 'package.json' file; run:
| def pytest_itemcollected(item): | |
| """Модифицирует название теста при сборке.""" | |
| if isinstance(item, pytest.Function): # Проверяем, что это тестовая функция | |
| class_doc = item.parent.obj.__doc__.strip() if item.parent.obj.__doc__ else "" | |
| method_doc = item.obj.__doc__.strip() if item.obj.__doc__ else "" | |
| if class_doc and method_doc: | |
| # Используем описание класса и метода | |
| item._nodeid = f"{class_doc} | {item.parent.obj.__name__}::{method_doc}" | |
| elif method_doc: |
| class InterceptHandler(logging.Handler): | |
| def emit(self, record): | |
| # Get corresponding Loguru level if it exists | |
| try: | |
| level = logger.level(record.levelname).name | |
| except ValueError: | |
| level = record.levelno | |
| # Find caller from where originated the logged message |
| def setup_console(sys_enc="utf-8"): | |
| reload(sys) | |
| try: | |
| # для win32 вызываем системную библиотечную функцию | |
| if sys.platform.startswith("win"): | |
| import ctypes | |
| enc = "cp%d" % ctypes.windll.kernel32.GetOEMCP() #TODO: проверить на win64/python64 | |
| else: | |
| # для Linux всё, кажется, есть и так | |
| enc = (sys.stdout.encoding if sys.stdout.isatty() else |
| /* Useful celery config. | |
| app = Celery('tasks', | |
| broker='redis://localhost:6379', | |
| backend='redis://localhost:6379') | |
| app.conf.update( | |
| CELERY_TASK_RESULT_EXPIRES=3600, | |
| CELERY_QUEUES=( | |
| Queue('default', routing_key='tasks.#'), |
| from django.db import models | |
| from django.contrib.contenttypes.fields import GenericForeignKey | |
| from django.contrib.contenttypes.models import ContentType | |
| from django.contrib.contenttypes.fields import GenericRelation | |
| # создадим класс, хранящий множество записей, которые могут привязываться к разным моделями | |
| class Accumulator(models.Model): | |
| # Ссылка на встроенную модель, где фигурируют все модели всех зарегистрированных приложений | |
| content_type = models.ForeignKey(ContentType, on_delete = models.PROTECT, editable = False, db_index = True) |
| function dump_debug($input, $collapse=false) { | |
| $recursive = function($data, $level=0) use (&$recursive, $collapse) { | |
| global $argv; | |
| $isTerminal = isset($argv); | |
| if (!$isTerminal && $level == 0 && !defined("DUMP_DEBUG_SCRIPT")) { | |
| define("DUMP_DEBUG_SCRIPT", true); | |
| echo '<script language="Javascript">function toggleDisplay(id) {'; |
| import importlib | |
| from typing import Any, Optional | |
| def import_class_by_path(path: str) -> Optional[Any]: | |
| """ Делает динамический импорт класса по пути типа apps.app.lib.classes.MyClass """ | |
| # Разбиваем модули на куски | |
| modules = path.split('.') | |
| # Берем конечный модуль из которого импортируем класс |
| def singleton(class_): | |
| instances = {} | |
| def getinstance(*args, **kwargs): | |
| if class_ not in instances: | |
| instances[class_] = class_(*args, **kwargs) | |
| return instances[class_] | |
| return getinstance |
| # coding=utf-8 | |
| # Пример диалплана | |
| # [custom-context] | |
| # same => n,Answer() | |
| # exten => _XXXX.,n,Stasis(ari_test) | |
| # ;exten => _XXXX.,n,Dial(${TDIAL_STRING}/${OUTNUM}${TDIAL_SUFFIX},${TRUNK_RING_TIMER},${DIAL_TRUNK_OPTIONS}) | |
| # exten => _XXXX.,n,NoOp(Left Stasis) | |
| # exten => _XXXX.,n,Hangup |