repo_id
stringclasses
409 values
prefix
large_stringlengths
34
36.3k
target
large_stringlengths
1
498
assertion_type
stringclasses
31 values
difficulty
stringclasses
8 values
test_file
stringlengths
10
121
test_function
stringlengths
1
104
test_class
stringlengths
0
51
lineno
int32
2
11.3k
commit_idx
int32
jrobichaud/django-structlog
import logging from django.test import TestCase from django_structlog import app_settings class TestAppSettings(TestCase): def test_status_5xx_log_level_default(self) -> None: settings = app_settings.AppSettings() self.assertEqual(settings.STATUS_5XX_LOG_LEVEL,
logging.ERROR)
self.assertEqual
complex_expr
test_app/tests/test_app_settings.py
test_status_5xx_log_level_default
TestAppSettings
33
null
jrobichaud/django-structlog
import logging from django.test import TestCase from django_structlog import app_settings class TestAppSettings(TestCase): def test_request_cancelled_log_level_default(self) -> None: settings = app_settings.AppSettings() self.assertEqual(settings.REQUEST_CANCELLED_LOG_LEVEL,
logging.WARNING)
self.assertEqual
complex_expr
test_app/tests/test_app_settings.py
test_request_cancelled_log_level_default
TestAppSettings
23
null
jrobichaud/django-structlog
import pytest from ninja.testing import TestClient from ..ninja_views import router pytestmark = pytest.mark.django_db class TestNinjaView: def test(self, caplog, request_factory): client = TestClient(router) response = client.get("/ninja") assert response.status_code ==
200
assert
numeric_literal
django_structlog_demo_project/home/tests/test_ninja_views.py
test
TestNinjaView
13
null
jrobichaud/django-structlog
import asyncio import logging import traceback import uuid from typing import Any, AsyncGenerator, Awaitable, Generator, Type, cast from unittest import mock from unittest.mock import AsyncMock, Mock, patch import structlog from django.contrib.auth.middleware import AuthenticationMiddleware from django.contrib.auth.mo...
int)
self.assertIsInstance
variable
test_app/tests/middlewares/test_request.py
test_process_request_user
TestRequestMiddleware
178
null
jrobichaud/django-structlog
import pytest from .. import api_views pytestmark = pytest.mark.django_db class TestApiView: def test(self, caplog, request_factory): response = api_views.home_api_view(request_factory.get("/")) assert response.status_code == 200 assert len(caplog.records) ==
1
assert
numeric_literal
django_structlog_demo_project/home/tests/test_api_views.py
test
TestApiView
12
null
jrobichaud/django-structlog
import logging import time from signal import SIGTERM from typing import Any, Optional, Type from unittest.mock import MagicMock, Mock, call, patch import structlog from celery import shared_task from django.contrib.auth.models import AnonymousUser from django.dispatch import receiver as django_receiver from django.te...
record.msg)
self.assertIn
complex_expr
test_app/tests/celery/test_receivers.py
test_defer_task
TestReceivers
45
null
jrobichaud/django-structlog
import asyncio import logging import traceback import uuid from typing import Any, AsyncGenerator, Awaitable, Generator, Type, cast from unittest import mock from unittest.mock import AsyncMock, Mock, patch import structlog from django.contrib.auth.middleware import AuthenticationMiddleware from django.contrib.auth.mo...
403)
self.assertEqual
numeric_literal
test_app/tests/middlewares/test_request.py
test_process_request_403_are_processed_as_regular_requests
TestRequestMiddleware
698
null
jrobichaud/django-structlog
import logging import time from signal import SIGTERM from typing import Any, Optional, Type from unittest.mock import MagicMock, Mock, call, patch import structlog from celery import shared_task from django.contrib.auth.models import AnonymousUser from django.dispatch import receiver as django_receiver from django.te...
headers)
self.assertDictEqual
variable
test_app/tests/celery/test_receivers.py
test_receiver_before_task_publish_celery_protocol_v2
TestReceivers
62
null
jrobichaud/django-structlog
import pytest from django.core import management from django_structlog_demo_project.command_examples.management.commands import ( example_command, ) pytestmark = pytest.mark.django_db class TestCommand: def test_command(self): assert
None
assert
none_literal
django_structlog_demo_project/command_examples/tests/test_commands.py
test_command
TestCommand
13
null
jrobichaud/django-structlog
import pytest from .. import celery pytestmark = pytest.mark.django_db class TestSuccessfulTask: def test(self, caplog): celery.successful_task(foo="bar") assert len(caplog.records) ==
1
assert
numeric_literal
django_structlog_demo_project/taskapp/tests/test_celery.py
test
TestSuccessfulTask
11
null
jrobichaud/django-structlog
import logging from django.test import TestCase from django_structlog import app_settings class TestAppSettings(TestCase): def test_celery_enabled(self) -> None: settings = app_settings.AppSettings() with self.settings(DJANGO_STRUCTLOG_CELERY_ENABLED=True): self.assertTrue(
settings.CELERY_ENABLED)
self.assertTrue
complex_expr
test_app/tests/test_app_settings.py
test_celery_enabled
TestAppSettings
13
null
jrobichaud/django-structlog
import logging import time from signal import SIGTERM from typing import Any, Optional, Type from unittest.mock import MagicMock, Mock, call, patch import structlog from celery import shared_task from django.contrib.auth.models import AnonymousUser from django.dispatch import receiver as django_receiver from django.te...
0)
self.assertGreaterEqual
numeric_literal
test_app/tests/celery/test_receivers.py
test_receiver_task_success
TestReceivers
307
null
jrobichaud/django-structlog
import pytest from django.conf import settings from django.urls import resolve, reverse pytestmark = pytest.mark.django_db def test_list(): assert reverse("users:list") ==
"/users/"
assert
string_literal
django_structlog_demo_project/users/tests/test_urls.py
test_list
21
null
jrobichaud/django-structlog
import asyncio import logging import traceback import uuid from typing import Any, AsyncGenerator, Awaitable, Generator, Type, cast from unittest import mock from unittest.mock import AsyncMock, Mock, patch import structlog from django.contrib.auth.middleware import AuthenticationMiddleware from django.contrib.auth.mo...
record.msg)
self.assertIn
complex_expr
test_app/tests/middlewares/test_request.py
test_process_request_without_user
TestRequestMiddleware
78
null
jrobichaud/django-structlog
import pytest from ninja.testing import TestClient from ..ninja_views import router pytestmark = pytest.mark.django_db class TestNinjaView: def test(self, caplog, request_factory): client = TestClient(router) response = client.get("/ninja") assert response.status_code == 200 asser...
"This is a ninja structured log"
assert
string_literal
django_structlog_demo_project/home/tests/test_ninja_views.py
test
TestNinjaView
17
null
jrobichaud/django-structlog
import pytest from django.conf import settings from django.urls import resolve, reverse pytestmark = pytest.mark.django_db def test_detail(user: settings.AUTH_USER_MODEL): route = f"/users/{user.username}/" assert reverse("users:detail", kwargs={"username": user.username}) == route assert resolve(route)....
"users:detail"
assert
string_literal
django_structlog_demo_project/users/tests/test_urls.py
test_detail
11
null
jrobichaud/django-structlog
import pytest from .. import celery pytestmark = pytest.mark.django_db class TestCorruptRejectedTask: def test(self, caplog): task_id = "11111111-1111-1111-1111-111111111111" headers = dict( id=task_id, task="django_structlog_demo_project.taskapp.celery.rejected_task", ...
"django_structlog_demo_project.taskapp.celery.successful_task"
assert
string_literal
django_structlog_demo_project/taskapp/tests/test_celery.py
test_other_tasks_not_corrupted
TestCorruptRejectedTask
74
null
jrobichaud/django-structlog
from unittest.mock import patch from django.test import TestCase from django_structlog.celery import steps class TestDjangoStructLogInitStep(TestCase): def test_call(self) -> None: with patch( "django_structlog.celery.receivers.CeleryReceiver.connect_worker_signals", autospec=True...
step.receiver)
self.assertIsNotNone
complex_expr
test_app/tests/celery/test_steps.py
test_call
TestDjangoStructLogInitStep
18
null
jrobichaud/django-structlog
import pytest from ninja.testing import TestClient from ..ninja_views import router pytestmark = pytest.mark.django_db class TestNinjaView: def test(self, caplog, request_factory): client = TestClient(router) response = client.get("/ninja") assert response.status_code == 200 asse...
{"result": "ok"}
assert
collection
django_structlog_demo_project/home/tests/test_ninja_views.py
test
TestNinjaView
14
null
jrobichaud/django-structlog
import pytest from django_structlog_demo_project.users.forms import UserCreationForm from django_structlog_demo_project.users.tests.factories import UserFactory pytestmark = pytest.mark.django_db class TestUserCreationForm: def test_clean_username(self): # A user with proto_user params does not exist yet...
form.errors
assert
complex_expr
django_structlog_demo_project/users/tests/test_forms.py
test_clean_username
TestUserCreationForm
40
null
jrobichaud/django-structlog
import pytest from django.conf import settings from django.urls import resolve, reverse pytestmark = pytest.mark.django_db def test_detail(user: settings.AUTH_USER_MODEL): route = f"/users/{user.username}/" assert reverse("users:detail", kwargs={"username": user.username}) ==
route
assert
variable
django_structlog_demo_project/users/tests/test_urls.py
test_detail
10
null
jrobichaud/django-structlog
import pytest from django.conf import settings pytestmark = pytest.mark.django_db def test_user_get_absolute_url(user: settings.AUTH_USER_MODEL): assert user.get_absolute_url() ==
"/users/{username}/".format( username=user.username )
assert
string_literal
django_structlog_demo_project/users/tests/test_models.py
test_user_get_absolute_url
8
null
jrobichaud/django-structlog
import asyncio import logging import traceback import uuid from typing import Any, AsyncGenerator, Awaitable, Generator, Type, cast from unittest import mock from unittest.mock import AsyncMock, Mock, patch import structlog from django.contrib.auth.middleware import AuthenticationMiddleware from django.contrib.auth.mo...
404)
self.assertEqual
numeric_literal
test_app/tests/middlewares/test_request.py
test_process_request_404_are_processed_as_regular_requests
TestRequestMiddleware
752
null
jrobichaud/django-structlog
from unittest.mock import create_autospec, patch from django.test import TestCase from django_structlog import apps, commands from django_structlog.celery import receivers class TestAppConfig(TestCase): def test_celery_enabled(self) -> None: app = apps.DjangoStructLogConfig( "django_structlog...
app._celery_receiver)
self.assertIsNotNone
complex_expr
test_app/tests/test_apps.py
test_celery_enabled
TestAppConfig
24
null
irgolic/AutoPR
import os from typing import Any, Optional from unittest.mock import patch import pydantic import pytest from autopr.actions.utils.prompt_context import PromptContext, PromptContextEntry from autopr.models.executable import ContextDict, ExecutableId from autopr.services.platform_service import DummyPlatformService f...
ValueError)
pytest.raises
variable
autopr/tests/actions/test_find_todos.py
test_language_not_found
217
null
irgolic/AutoPR
import pytest from git.repo import Repo from autopr.models.executable import ExecutableId from autopr.tests.utils import create_ephemeral_main_service, run_action_manually_with_main def check_commit(commit): # assert commit message assert commit.message == "My commit message\n" # assert fi...
{ "insertions": 1, "deletions": 0, "lines": 1, }
assert
collection
autopr/tests/actions/test_commit_and_push.py
check_commit
26
null
irgolic/AutoPR
import os from unittest.mock import AsyncMock, patch, MagicMock import pytest from autopr.actions.prompt import Inputs, PromptString from autopr.actions.utils.prompt_context import PromptContext, PromptContextEntry, trim_context from autopr.models.executable import ExecutableId from autopr.tests.mock_openai import mo...
3
assert
numeric_literal
autopr/tests/actions/test_prompt.py
test_trim_context
101
null
irgolic/AutoPR
import os from typing import Any, Optional import pydantic import pytest from autopr.actions.utils.prompt_context import PromptContext, PromptContextEntry from autopr.models.executable import ContextDict, ExecutableId from autopr.tests.mock_openai import mock_openai from autopr.tests.utils import run_action_manuall...
sorted(expected_ls)
assert
func_call
autopr/tests/actions/test_walk_files.py
test_actions
47
null
irgolic/AutoPR
import os from unittest.mock import AsyncMock, patch, MagicMock import pytest from autopr.actions.prompt import Inputs, PromptString from autopr.actions.utils.prompt_context import PromptContext, PromptContextEntry, trim_context from autopr.models.executable import ExecutableId from autopr.tests.mock_openai import mo...
"""Milk, eggs, cheese, Milk, ... (trimmed) ... eese, Milk, eggs, cheese, """
assert
string_literal
autopr/tests/actions/test_prompt.py
test_trim_context
122
null
irgolic/AutoPR
import os from typing import Any, Optional import pydantic import pytest from autopr.actions.utils.prompt_context import PromptContext, PromptContextEntry from autopr.models.executable import ContextDict, ExecutableId from autopr.tests.mock_openai import mock_openai from autopr.tests.utils import run_action_manuall...
expected_outputs
assert
variable
autopr/tests/test_actions.py
test_actions
114
null
irgolic/AutoPR
import json from typing import Optional import pytest from autopr.models.artifacts import Issue, Message from autopr.models.events import LabelEvent, EventUnion, PushEvent, CronEvent from autopr.models.executable import ContextDict from autopr.services.platform_service import GitHubPlatformService from autopr.tests.u...
[expected_resulting_context]
assert
collection
autopr/tests/test_event_triggers.py
test_event_triggers
108
null
irgolic/AutoPR
import os from typing import Any, Optional import pydantic import pytest from autopr.actions.utils.prompt_context import PromptContext, PromptContextEntry from autopr.models.executable import ContextDict, ExecutableId from autopr.tests.mock_openai import mock_openai from autopr.tests.utils import run_action_manuall...
outputs
assert
variable
autopr/tests/actions/test_walk_files.py
test_actions
46
null
irgolic/AutoPR
import os from typing import Any, Optional import pydantic import pytest from autopr.models.executable import ContextDict, ExecutableId from autopr.tests.mock_openai import mock_openai from autopr.tests.utils import run_action_manually @pytest.mark.parametrize( "inputs, expected_output, repo_resource", [ ...
expected_output
assert
variable
autopr/tests/actions/test_write_into_file.py
test_actions
41
null
irgolic/AutoPR
import json from typing import Optional import pytest from autopr.models.artifacts import Issue, Message from autopr.models.events import LabelEvent, EventUnion, PushEvent, CronEvent from autopr.models.executable import ContextDict from autopr.services.platform_service import GitHubPlatformService from autopr.tests.u...
1
assert
numeric_literal
autopr/tests/test_event_triggers.py
test_event_triggers
105
null
irgolic/AutoPR
import os from typing import Any, Optional import pydantic import pytest from autopr.models.executable import ContextDict, ExecutableId from autopr.tests.mock_openai import mock_openai from autopr.tests.utils import run_action_manually from autopr.actions.search import SearchHit @pytest.mark.parametrize( "input...
expected_output
assert
variable
autopr/tests/actions/test_search.py
test_actions
75
null
irgolic/AutoPR
import json import os from unittest.mock import MagicMock, patch, Mock import pytest from aioresponses import aioresponses from git import Commit from git.repo import Repo from autopr.models.artifacts import Issue, PullRequest, Message from autopr.models.events import EventUnion, LabelEvent from autopr.services.platf...
"comment1"
assert
string_literal
autopr/tests/test_platform_service.py
test_github_platform_service
130
null
irgolic/AutoPR
import os from unittest.mock import AsyncMock, patch, MagicMock import pytest from autopr.actions.prompt import Inputs, PromptString from autopr.actions.utils.prompt_context import PromptContext, PromptContextEntry, trim_context from autopr.models.executable import ExecutableId from autopr.tests.mock_openai import mo...
"What I have in my fridge"
assert
string_literal
autopr/tests/actions/test_prompt.py
test_trim_context
152
null
irgolic/AutoPR
import os from unittest.mock import AsyncMock, patch, MagicMock import pytest from autopr.actions.prompt import Inputs, PromptString from autopr.actions.utils.prompt_context import PromptContext, PromptContextEntry, trim_context from autopr.models.executable import ExecutableId from autopr.tests.mock_openai import mo...
1
assert
numeric_literal
autopr/tests/actions/test_prompt.py
test_caching
34
null
irgolic/AutoPR
import os from typing import Any, Optional import pydantic import pytest from autopr.actions.utils.prompt_context import PromptContext, PromptContextEntry from autopr.models.executable import ContextDict, ExecutableId from autopr.tests.mock_openai import mock_openai from autopr.tests.utils import run_action_manuall...
outputs
assert
variable
autopr/tests/resources/repos/example_repo_2/example_repo_2_subfolder/list_folder.py
test_actions
48
null
irgolic/AutoPR
import json import os from unittest.mock import patch, Mock import git.repo import pytest from autopr.models.artifacts import PullRequest, Message from autopr.models.events import PushEvent from autopr.services.platform_service import GitHubPlatformService from autopr.tests.mock_openai import mock_openai from autopr....
mock_content
assert
variable
autopr/tests/workflows/test_api_history_with_git.py
test_autogenerate_readmes
33
null
irgolic/AutoPR
import os from unittest.mock import AsyncMock, patch, MagicMock import pytest from autopr.actions.prompt import Inputs, PromptString from autopr.actions.utils.prompt_context import PromptContext, PromptContextEntry, trim_context from autopr.models.executable import ExecutableId from autopr.tests.mock_openai import mo...
"""Flour, sugar, sal ... (trimmed) ... ar, salt, pepper, """
assert
string_literal
autopr/tests/actions/test_prompt.py
test_trim_context
112
null
irgolic/AutoPR
import os from typing import Any, Optional import pydantic import pytest from autopr.models.executable import ContextDict, ExecutableId from autopr.tests.mock_openai import mock_openai from autopr.tests.utils import run_action_manually @pytest.mark.parametrize( "inputs, expected_output, repo_resource", [ ...
expected_output
assert
variable
autopr/tests/actions/test_read_file.py
test_actions
41
null
irgolic/AutoPR
import json import os from unittest.mock import MagicMock, patch, Mock import pytest from aioresponses import aioresponses from git import Commit from git.repo import Repo from autopr.models.artifacts import Issue, PullRequest, Message from autopr.models.events import EventUnion, LabelEvent from autopr.services.platf...
expected_issue
assert
variable
autopr/tests/test_platform_service.py
test_get_issue_by_title
301
null
irgolic/AutoPR
import os from typing import Any, Optional import pydantic import pytest from autopr.actions.utils.prompt_context import PromptContext, PromptContextEntry from autopr.models.executable import ContextDict, ExecutableId from autopr.tests.mock_openai import mock_openai from autopr.tests.utils import run_action_manuall...
sorted(expected_ls)
assert
func_call
autopr/tests/resources/repos/example_repo_2/example_repo_2_subfolder/list_folder.py
test_actions
49
null
irgolic/AutoPR
import os from typing import Any, Optional import pydantic import pytest from autopr.actions.utils.prompt_context import PromptContext, PromptContextEntry from autopr.models.executable import ContextDict, ExecutableId from autopr.tests.mock_openai import mock_openai from autopr.tests.utils import run_action_manuall...
sorted(expected_ls)
assert
func_call
autopr/tests/actions/test_crawl_folder.py
test_actions
45
null
irgolic/AutoPR
import os from typing import Any, Optional import pydantic import pytest from autopr.actions.utils.prompt_context import PromptContext, PromptContextEntry from autopr.models.executable import ContextDict, ExecutableId from autopr.tests.mock_openai import mock_openai from autopr.tests.utils import run_action_manuall...
outputs
assert
variable
autopr/tests/actions/test_crawl_folder.py
test_actions
44
null
irgolic/AutoPR
import json import os from unittest.mock import MagicMock, patch, Mock import pytest from aioresponses import aioresponses from git import Commit from git.repo import Repo from autopr.models.artifacts import Issue, PullRequest, Message from autopr.models.events import EventUnion, LabelEvent from autopr.services.platf...
expected_event
assert
variable
autopr/tests/test_platform_service.py
test_parse_event
239
null
irgolic/AutoPR
import os import pytest from autopr.models.config.entrypoints import get_params from autopr.triggers import get_all_triggers from autopr.workflows import get_all_workflows @pytest.mark.parametrize( "workflow_id, expected_params", [ ( "summarize_file", { "EMPTY_...
expected_params
assert
variable
autopr/tests/test_trigger_spec.py
test_get_params
65
null
irgolic/AutoPR
import os from typing import Any, Optional from unittest.mock import patch import pydantic import pytest from autopr.actions.utils.prompt_context import PromptContext, PromptContextEntry from autopr.models.executable import ContextDict, ExecutableId from autopr.services.platform_service import DummyPlatformService f...
expected_outputs
assert
variable
autopr/tests/actions/test_find_todos.py
test_actions
209
null
luizyao/pytest-chinese-doc
import pytest pytestmark = pytest.mark.parametrize('test_input, expected', [(1, 2), (3, 4)]) def test_module(test_input, expected): assert test_input + 1 ==
expected
assert
variable
src/chapter-11/test_module.py
test_module
28
null
luizyao/pytest-chinese-doc
def test_long_str_comparison(): str1 = 'show me codes' str2 = 'show me money' assert str1 ==
str2
assert
variable
src/chapter-3/test_special_compare.py
test_long_str_comparison
32
null
luizyao/pytest-chinese-doc
def test_foo_compare(): f1 = Foo(1) f2 = Foo(2) assert f1 ==
f2
assert
variable
src/chapter-3/test_foo_compare.py
test_foo_compare
37
null
luizyao/pytest-chinese-doc
def func(x): return x + 1 def test_sample(): assert func(3) ==
5
assert
numeric_literal
src/chapter-1/test_sample.py
test_sample
28
null
luizyao/pytest-chinese-doc
import sys def test_output(capsys): print('hello') print('world', file=sys.stderr, end='&') # 标准错误输出,修改结束符 captured = capsys.readouterr() assert captured.out ==
'hello\n'
assert
string_literal
src/chapter-7/test_output.py
test_output
29
null
luizyao/pytest-chinese-doc
def test_noop(smtp_connection): response, _ = smtp_connection.noop() assert response == 250 assert smtp_connection.extra_attr ==
0
assert
numeric_literal
src/chapter-4/test_module.py
test_noop
33
null
luizyao/pytest-chinese-doc
import pytest def max(request): return request.param - 1 def min(request): return request.param + 1 @pytest.mark.parametrize('min, max', [(1, 2), (3, 4)]) def test_indirect(min, max): assert min <=
max
assert
variable
src/chapter-11/test_indirect.py
test_indirect
38
null
luizyao/pytest-chinese-doc
import sys def test_output(capsys): print('hello') print('world', file=sys.stderr, end='&') # 标准错误输出,修改结束符 captured = capsys.readouterr() assert captured.out == 'hello\n' # print() 默认的结束符是换行符 assert captured.err == 'world&' print('next') captured = capsys.readouterr() assert captured...
'next\n'
assert
string_literal
src/chapter-7/test_output.py
test_output
33
null
luizyao/pytest-chinese-doc
import os import pytest def get_os_user(): username = os.getenv('USER') if username is None: raise IOError('"USER" environment variable is not set.') return username def test_user(monkeypatch): monkeypatch.setenv('USER', 'luizyao') assert get_os_user() ==
'luizyao'
assert
string_literal
src/chapter-5/test_env.py
test_user
38
null
luizyao/pytest-chinese-doc
CONTENT = "content" def test_create_file(tmp_path): d = tmp_path / "sub" d.mkdir() # 创建一个子目录 p = d / "hello.txt" p.write_text(CONTENT) assert p.read_text() == CONTENT assert len(list(tmp_path.iterdir())) ==
1
assert
numeric_literal
src/chapter-6/test_tmp_path.py
test_create_file
31
null
luizyao/pytest-chinese-doc
import pytest def f(): # 解释器请求退出 raise SystemExit(1) def test_mytest(): with pytest.raises(
SystemExit)
pytest.raises
variable
src/chapter-1/test_sysexit.py
test_mytest
31
null
luizyao/pytest-chinese-doc
def func(x): return x + 1 def test_sample(): assert func(3) ==
5
assert
numeric_literal
src/chapter-3/test_sample.py
test_sample
28
null
luizyao/pytest-chinese-doc
import pytest def db(): return DB() class TestClass: def transact(self, request, db): db.begin(request.function.__name__) yield db.rollback() def test_method2(self, db): assert db.intransaction ==
["test_method2"]
assert
collection
src/chapter-4/test_db_transact.py
test_method2
TestClass
52
null
luizyao/pytest-chinese-doc
CONTENT = "content" def test_create_file(tmpdir): p = tmpdir.mkdir("sub").join("hello.txt") # 创建子文件夹,并新建文件 p.write(CONTENT) assert p.read() == CONTENT assert len(tmpdir.listdir()) ==
1
assert
numeric_literal
src/chapter-6/test_tmpdir.py
test_create_file
29
null
luizyao/pytest-chinese-doc
import sys def test_disabling_capturing(capsys): print("hello") with capsys.disabled(): print("world") captured = capsys.readouterr() assert captured.out ==
"hello\n"
assert
string_literal
src/chapter-7/test_output.py
test_disabling_capturing
47
null
luizyao/pytest-chinese-doc
from urllib import request import pytest from app import get def test_get(monkeypatch): def mock_urlopen(*args, **kwargs): return MockResponse() # 使用 request.mock_urlopen 代替 request.urlopen monkeypatch.setattr(request, 'urlopen', mock_urlopen) data = get('https://luizyao.com') assert d...
'luizyao.com'
assert
string_literal
src/chapter-5/test_app.py
test_get
46
null
luizyao/pytest-chinese-doc
import sys def test_binary_output(capsysbinary): print('hello') captured = capsysbinary.readouterr() assert captured.out ==
b'hello\n'
assert
string_literal
src/chapter-7/test_output.py
test_binary_output
39
null
luizyao/pytest-chinese-doc
class TestClass: def test_one(self): x = 'this' assert 'h' in
x
assert
variable
src/chapter-1/test_class.py
test_one
TestClass
26
null
luizyao/pytest-chinese-doc
smtp_server = ("mail.python.org", 587) def test_163(smtp_connection_request): response, _ = smtp_connection_request.ehlo() assert response ==
250
assert
numeric_literal
src/chapter-4/test_request.py
test_163
28
null
luizyao/pytest-chinese-doc
def test_ehlo_in_module2(smtp_connection_package): response, _ = smtp_connection_package.ehlo() assert response ==
250
assert
numeric_literal
src/chapter-4/package_expr/test_module2.py
test_ehlo_in_module2
25
null
luizyao/pytest-chinese-doc
def test_parames(smtp_connection_params): response, _ = smtp_connection_params.ehlo() assert response ==
250
assert
numeric_literal
src/chapter-4/test_params.py
test_parames
25
null
luizyao/pytest-chinese-doc
CONTENT = "content" def test_create_file(tmpdir): p = tmpdir.mkdir("sub").join("hello.txt") # 创建子文件夹,并新建文件 p.write(CONTENT) assert p.read() ==
CONTENT
assert
variable
src/chapter-6/test_tmpdir.py
test_create_file
28
null
luizyao/pytest-chinese-doc
CONTENT = "content" def test_create_file(tmp_path): d = tmp_path / "sub" d.mkdir() # 创建一个子目录 p = d / "hello.txt" p.write_text(CONTENT) assert p.read_text() ==
CONTENT
assert
variable
src/chapter-6/test_tmp_path.py
test_create_file
30
null
luizyao/pytest-chinese-doc
import pytest def data_set(request): return request.param @pytest.mark.parametrize( 'test_input, expected', [('3+5', 8), pytest.param('6*9', 42, marks=pytest.mark.xfail, id='failed')]) def test_data2(test_input, expected): assert eval(test_input) ==
expected
assert
variable
src/chapter-4/test_fixture_marks.py
test_data2
42
null
luizyao/pytest-chinese-doc
def test_fail(): x = 1 assert x ==
0
assert
numeric_literal
src/chapter-2/test_pdb.py
test_fail
25
null
luizyao/pytest-chinese-doc
import pytest from _pytest.mark.structures import ParameterSet @pytest.mark.parametrize( 'input, expected', [(1, 2), ParameterSet(values=(1, 2), marks=[], id=None)]) def test_sample(input, expected): assert input + 1 ==
expected
assert
variable
src/chapter-11/test_sample.py
test_sample
31
null
luizyao/pytest-chinese-doc
import pytest class TestNodeId: @pytest.mark.parametrize('x,y', [(1, 1), (3, 4)]) def test_two(self, x, y): print(f'TestNodeId::test_two::{x} == {y}') assert x ==
y
assert
variable
src/chapter-2/test_nodeid.py
test_two
TestNodeId
38
null
luizyao/pytest-chinese-doc
def something(): '''文档字符串示例 >>> something() 42 ''' return 42 def test_module(): assert something() ==
42
assert
numeric_literal
src/chapter-9/test_module.py
test_module
33
null
luizyao/pytest-chinese-doc
import pytest def expensive_computation(): print("running expensive computation...") def mydata(request): # 从缓存中读取数据 val = request.config.cache.get("example/value", None) if val is None: expensive_computation() val = 42 # 如果缓存中没有,设置缓存中的值 request.config.cache.set("exampl...
23
assert
numeric_literal
src/chapter-12/test_caching.py
test_function
43
null
luizyao/pytest-chinese-doc
import warnings import pytest def api_call_v1(): warnings.warn('v1版本已废弃,请使用v2版本的api;', DeprecationWarning) return 200 def test_deprecation(): assert pytest.deprecated_call(api_call_v1) ==
200
assert
numeric_literal
src/chapter-8/test_show_deprecation.py
test_deprecation
32
null
luizyao/pytest-chinese-doc
def test_ehlo_in_module1(smtp_connection_package): response, _ = smtp_connection_package.ehlo() assert response ==
250
assert
numeric_literal
src/chapter-4/package_expr/test_module1.py
test_ehlo_in_module1
25
null
luizyao/pytest-chinese-doc
import pytest def db(): return DB() class TestClass: def transact(self, request, db): db.begin(request.function.__name__) yield db.rollback() def test_method1(self, db): assert db.intransaction ==
["test_method1"]
assert
collection
src/chapter-4/test_db_transact.py
test_method1
TestClass
49
null
luizyao/pytest-chinese-doc
import warnings import pytest def api_v1(): warnings.warn(UserWarning('请使用新版本的API。')) return 1 def test_one(): assert api_v1() ==
1
assert
numeric_literal
src/chapter-8/test_show_warnings.py
test_one
32
null
luizyao/pytest-chinese-doc
from pathlib import Path def getssh(): return Path.home() / ".ssh" def test_getssh(monkeypatch): def mockreturn(): return Path("/abc") # 替换 Path.home # 需要在真正的调用之前执行 monkeypatch.setattr(Path, "home", mockreturn) # 将会使用 mockreturn 代替 Path.home x = getssh() assert x ==
Path("/abc/.ssh")
assert
func_call
src/chapter-5/test_module.py
test_getssh
39
null
luizyao/pytest-chinese-doc
import os import pytest def get_os_user(): username = os.getenv('USER') if username is None: raise IOError('"USER" environment variable is not set.') return username def test_raise_exception(monkeypatch): monkeypatch.delenv('USER', raising=False) pytest.raises(
IOError)
pytest.raises
variable
src/chapter-5/test_env.py
test_raise_exception
43
null
luizyao/pytest-chinese-doc
def test_dict_comparison(): dict1 = { 'x': 1, 'y': 2, } dict2 = { 'x': 1, 'y': 1, } assert dict1 ==
dict2
assert
variable
src/chapter-3/test_special_compare.py
test_dict_comparison
44
null
rcmdnk/homebrew-file
from __future__ import annotations import io import logging import os from pathlib import Path import pytest from .brew_file import ( BrewFile, BrewHelper, BrewInfo, CmdError, __prog__, is_mac, ) def bf() -> BrewFile: return BrewFile({}) @pytest.mark.parametrize( ('input_value', 're...
ret
assert
variable
tests/test_brew_file.py
test_ask_yn
150
null
rcmdnk/homebrew-file
from __future__ import annotations import logging import subprocess from pathlib import Path from typing import Any import pytest from .brew_file import BrewFile, BrewHelper, CmdError, is_mac def helper() -> BrewHelper: bf = BrewFile() return bf.helper def err_cmd() -> dict[str, Any]: return { ...
0
assert
numeric_literal
tests/test_brew_helper.py
test_proc_dryrun
205
null
rcmdnk/homebrew-file
from __future__ import annotations import logging import subprocess from pathlib import Path from typing import Any import pytest from .brew_file import BrewFile, BrewHelper, CmdError, is_mac def helper() -> BrewHelper: bf = BrewFile() return bf.helper @pytest.mark.parametrize( ('cmd', 'ret', 'lines', ...
ret
assert
variable
tests/test_brew_helper.py
test_proc
71
null
rcmdnk/homebrew-file
from __future__ import annotations import logging import subprocess from pathlib import Path from typing import Any import pytest from .brew_file import BrewFile, BrewHelper, CmdError, is_mac def helper() -> BrewHelper: bf = BrewFile() return bf.helper def err_cmd() -> dict[str, Any]: return { ...
''
assert
string_literal
tests/test_brew_helper.py
test_get_desc_missing
316
null
rcmdnk/homebrew-file
from __future__ import annotations from pathlib import Path import pytest from .brew_file import BrewHelper, BrewInfo, is_mac def make_helper(**overrides: object) -> BrewHelper: opts: dict[str, object] = { 'form': 'file', 'caskonly': False, 'describe': False, 'full_name': False, ...
lines
assert
variable
tests/test_brew_info.py
test_desc_with_describe
390
null
rcmdnk/homebrew-file
from __future__ import annotations import logging import os from pathlib import Path from typing import Any import pytest from .brew_file import BrewFile, BrewHelper, BrewInfo, is_mac pytestmark = pytest.mark.destructive def clean(request: pytest.FixtureRequest) -> None: if getattr(request.config, 'destructive...
[]
assert
collection
tests/test_destructive.py
test_install_clean
884
null
rcmdnk/homebrew-file
from __future__ import annotations import logging import os import platform import sys from pathlib import Path import pytest from .brew_file import ( LogFormatter, expandpath, home_tilde, is_mac, shell_envs, to_bool, to_num, ) @pytest.mark.parametrize( ('path', 'result'), [ ...
Path(result)
assert
func_call
tests/test_utils.py
test_expandpath
111
null
rcmdnk/homebrew-file
from __future__ import annotations import logging import subprocess from pathlib import Path from typing import Any import pytest from .brew_file import BrewFile, BrewHelper, CmdError, is_mac def helper() -> BrewHelper: bf = BrewFile() return bf.helper def err_cmd() -> dict[str, Any]: return { ...
info
assert
variable
tests/test_brew_helper.py
test_get_json_info
246
null
rcmdnk/homebrew-file
from __future__ import annotations import logging import os import platform import sys from pathlib import Path import pytest from .brew_file import ( LogFormatter, expandpath, home_tilde, is_mac, shell_envs, to_bool, to_num, ) @pytest.mark.parametrize( ('val', 'result'), [ ...
result
assert
variable
tests/test_utils.py
test_to_bool
74
null
rcmdnk/homebrew-file
from __future__ import annotations import io import logging import os from pathlib import Path import pytest from .brew_file import ( BrewFile, BrewHelper, BrewInfo, CmdError, __prog__, is_mac, ) def bf() -> BrewFile: return BrewFile({}) def test_read(bf: BrewFile, tmp_path: Path) -> No...
f
assert
variable
tests/test_brew_file.py
test_read
195
null
rcmdnk/homebrew-file
from __future__ import annotations import io import logging import os from pathlib import Path import pytest from .brew_file import ( BrewFile, BrewHelper, BrewInfo, CmdError, __prog__, is_mac, ) def bf() -> BrewFile: return BrewFile({}) @pytest.mark.parametrize( ('app', 'token'), ...
token
assert
variable
tests/test_brew_file.py
test_generate_cask_token
381
null
rcmdnk/homebrew-file
from __future__ import annotations from pathlib import Path import pytest from . import brew_file def test_open_with_different_modes(tmp_path: Path) -> None: test_file = tmp_path / 'test.txt' # Test write mode with brew_file.OpenWrapper(test_file, 'w') as f: f.write('test') # Test read mod...
'test_append'
assert
string_literal
tests/test_open_wrapper.py
test_open_with_different_modes
46
null
rcmdnk/homebrew-file
from __future__ import annotations import logging import os from pathlib import Path from typing import Any import pytest from .brew_file import BrewFile, BrewHelper, BrewInfo, is_mac pytestmark = pytest.mark.destructive def clean(request: pytest.FixtureRequest) -> None: if getattr(request.config, 'destructive...
files
assert
variable
tests/test_destructive.py
test_get_files
406
null
rcmdnk/homebrew-file
from __future__ import annotations import io import logging import os from pathlib import Path import pytest from .brew_file import ( BrewFile, BrewHelper, BrewInfo, CmdError, __prog__, is_mac, ) def bf() -> BrewFile: return BrewFile({}) def test_set_args(bf: BrewFile) -> None: bf.o...
'1'
assert
string_literal
tests/test_brew_file.py
test_set_args
104
null
rcmdnk/homebrew-file
from __future__ import annotations import io import logging import os from pathlib import Path import pytest from .brew_file import ( BrewFile, BrewHelper, BrewInfo, CmdError, __prog__, is_mac, ) def bf() -> BrewFile: return BrewFile({}) def test_set_args(bf: BrewFile) -> None: bf.o...
0
assert
numeric_literal
tests/test_brew_file.py
test_set_args
114
null