Skip to content

Commit

Permalink
[TestSlide] Fix github build
Browse files Browse the repository at this point in the history
  • Loading branch information
deathowl committed May 8, 2024
1 parent 108c506 commit d966428
Show file tree
Hide file tree
Showing 28 changed files with 121 additions and 96 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pytest_tests: venv coverage_erase
%_testslide.py: venv coverage_erase
@printf "${TERM_BRIGHT}TESTSLIDE $@\n${TERM_NONE}"
${Q} ${CURDIR}/venv/bin/coverage run \
-m testslide.cli \
-m testslide.executor.cli \
--format $(TESTSLIDE_FORMAT) \
--show-testslide-stack-trace \
--fail-fast \
Expand Down
2 changes: 1 addition & 1 deletion pytest-testslide/pytest_testslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def mock_callable(
@staticmethod
def mock_async_callable(
*args: Any, **kwargs: Any
) -> testslide_module.mock_callable._MockAsyncCallableDSL:
) -> testslide_module.core.mock_callable._MockAsyncCallableDSL:
return testslide_module.mock_callable.mock_async_callable(*args, **kwargs)

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions pytest-testslide/tests/test_pytest_testslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_pass(testdir):
import pytest
from pytest_testslide import testslide
from tests import sample_module
from testslide import StrictMock
from testslide.core.strict_mock import StrictMock
def test_has_mock_callable(testslide):
testslide.mock_callable
Expand Down Expand Up @@ -146,7 +146,7 @@ def test_aggregated_exceptions(testslide):
______ ERROR at teardown of test_mock_constructor_failing_assertion_works ______
1 failures.
<class \'AssertionError\'>: calls did not match assertion.
<class \'testslide.mock_constructor.ParentTarget\'>, \'__new__\':
<class \'testslide.core.mock_constructor.ParentTarget\'>, \'__new__\':
expected: called exactly 1 time\(s\) with any arguments received: 0 call\(s\)
_______________ ERROR at teardown of test_aggregated_exceptions ________________
2 failures.
Expand Down
2 changes: 1 addition & 1 deletion pytest-testslide/testslide-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.1
3.0.0
10 changes: 5 additions & 5 deletions tests/dsl_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
from typing import List
from unittest.mock import Mock, call, patch

from testslide import (
from testslide.bdd.dsl import context, fcontext, xcontext
from testslide.bdd.lib import (
AggregatedExceptions,
Context,
Example,
LeftOverActiveTasks,
SlowCallback,
_ExampleRunner,
get_active_tasks,
reset,
)
from testslide.dsl import context, fcontext, xcontext
from testslide.runner import QuietFormatter
from testslide.executor.lib import _ExampleRunner
from testslide.executor.runner import QuietFormatter


def _get_name_to_examples():
Expand Down Expand Up @@ -2097,7 +2097,7 @@ def get_all_tasks():
task_cancelled,
]

with patch("testslide.get_all_tasks", new=get_all_tasks):
with patch("testslide.bdd.lib.get_all_tasks", new=get_all_tasks):
result = get_active_tasks()

self.assertEqual(result, [task_active])
Expand Down
12 changes: 6 additions & 6 deletions tests/lib_testslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import unittest.mock
from typing import Optional, Type, TypeVar

import testslide.lib
from testslide import StrictMock
from testslide.dsl import Skip, context, fcontext, xcontext # noqa: F401
import testslide.core.lib
from testslide.bdd.dsl import context
from testslide.core.strict_mock import StrictMock

from . import sample_module

Expand All @@ -34,17 +34,17 @@ def callable_template(self):

@context.function
def assert_passes(self, *args, **kwargs):
testslide.lib._validate_callable_arg_types(
testslide.core.lib._validate_callable_arg_types(
self.skip_first_arg, self.callable_template, args, kwargs
)

@context.function
def assert_fails(self, *args, **kwargs):
with self.assertRaisesRegex(
testslide.lib.TypeCheckError,
testslide.core.lib.TypeCheckError,
f"Call to {self.callable_template.__name__} has incompatible argument types",
):
testslide.lib._validate_callable_arg_types(
testslide.core.lib._validate_callable_arg_types(
self.skip_first_arg, self.callable_template, args, kwargs
)

Expand Down
8 changes: 4 additions & 4 deletions tests/mock_async_callable_testslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import contextlib

import testslide
from testslide.dsl import Skip, context, fcontext, xcontext # noqa: F401
from testslide.lib import TypeCheckError
from testslide.mock_callable import (
from testslide.bdd.dsl import context
from testslide.core.lib import TypeCheckError
from testslide.core.mock_callable import (
NotACoroutine,
UndefinedBehaviorForCall,
UnexpectedCallArguments,
mock_async_callable,
)
from testslide.strict_mock import StrictMock
from testslide.core.strict_mock import StrictMock

from . import sample_module

Expand Down
8 changes: 4 additions & 4 deletions tests/mock_callable_testslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import os

import testslide
from testslide.dsl import Skip, context, fcontext, xcontext # noqa: F401
from testslide.lib import CoroutineValueError, TypeCheckError
from testslide.mock_callable import (
from testslide.bdd.dsl import context
from testslide.core.lib import CoroutineValueError, TypeCheckError
from testslide.core.mock_callable import (
UndefinedBehaviorForCall,
UnexpectedCallArguments,
UnexpectedCallReceived,
mock_callable,
)
from testslide.strict_mock import StrictMock
from testslide.core.strict_mock import StrictMock

from . import sample_module

Expand Down
8 changes: 4 additions & 4 deletions tests/mock_constructor_testslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import sys
from typing import Optional

from testslide.dsl import Skip, context, fcontext, xcontext # noqa: F401
from testslide.lib import TypeCheckError
from testslide.mock_callable import _MockCallableDSL
from testslide.strict_mock import StrictMock
from testslide.bdd.dsl import context
from testslide.core.lib import TypeCheckError
from testslide.core.mock_callable import _MockCallableDSL
from testslide.core.strict_mock import StrictMock


class _PrivateClass:
Expand Down
8 changes: 4 additions & 4 deletions tests/patch_attribute_testslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# LICENSE file in the root directory of this source tree.

from testslide import StrictMock
from testslide.dsl import Skip, context, fcontext, xcontext # noqa: F401
from testslide.lib import TypeCheckError
from testslide.patch_attribute import unpatch_all_mocked_attributes
from testslide.strict_mock import UndefinedAttribute
from testslide.bdd.dsl import context
from testslide.core.lib import TypeCheckError
from testslide.core.patch_attribute import unpatch_all_mocked_attributes
from testslide.core.strict_mock import UndefinedAttribute

from . import sample_module

Expand Down
7 changes: 4 additions & 3 deletions tests/strict_mock_testslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
import sys
import unittest

from testslide.dsl import Skip, context, fcontext, xcontext # noqa: F401
from testslide.lib import TypeCheckError
from testslide.strict_mock import (
from testslide.bdd.dsl import context
from testslide.bdd.lib import Skip # noqa: F401
from testslide.core.lib import TypeCheckError
from testslide.core.strict_mock import (
NonAwaitableReturn,
NonCallableValue,
NonExistentAttribute,
Expand Down
20 changes: 11 additions & 9 deletions testslide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@
# LICENSE file in the root directory of this source tree.


import testslide.core.matchers as matchers
import sys
import unittest # noqa

import testslide.bdd.dsl as dsl
import testslide.core.lib as lib
import testslide.core.matchers as matchers
import testslide.core.mock_callable as mock_callable
import testslide.core.mock_constructor as mock_constructor
import testslide.core.patch_attribute as patch_attribute
import testslide.core.strict_mock as strict_mock # noqa
from testslide.core import TestCase, _importer # noqa
from testslide.core.strict_mock import StrictMock # noqa
from testslide.bdd.lib import Context, _ContextData # noqa
import testslide.bdd.dsl as dsl
import testslide.executor.runner as runner
import testslide.core.strict_mock as strict_mock # noqa
import testslide.executor.cli as cli
import testslide.executor.import_profiler as import_profiler
import sys
import unittest # noqa
import testslide.executor.runner as runner
from testslide.bdd.lib import Context, _ContextData # noqa
from testslide.core import TestCase, _importer # noqa
from testslide.core.strict_mock import StrictMock # noqa

# I'm sorry. I know. This is necessary to provide backwards compatibility with TestSlide 2.0 so I don't break the world.
sys.modules["testslide.lib"] = lib
sys.modules["testslide.matchers"] = matchers
Expand Down
11 changes: 6 additions & 5 deletions testslide/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from testslide.core import _importer # noqa
import unittest
from typing import Any

from testslide.bdd.lib import *
from testslide.bdd.lib import Context # noqa
from testslide.core import _importer # noqa
from testslide.executor.lib import *
from testslide.bdd.lib import Context #noqa
from typing import Any
import unittest

class TestCase(unittest.TestCase):
class TestCase(unittest.TestCase): # type: ignore
def setUp(self) -> None: ...
@staticmethod
def mock_callable(*args, **kwargs): ... # incomplete
Expand Down
2 changes: 1 addition & 1 deletion testslide/bdd/dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from testslide.core import TestCase

from .lib import Context as _Context, Skip # noqa: F401
from .lib import Context as _Context # noqa: F401

ExampleFunction = Callable[..., Any]
HaltingFunction = Callable[..., NoReturn]
Expand Down
6 changes: 4 additions & 2 deletions testslide/bdd/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import asyncio.log
import inspect
import os
import psutil
import re
import sys
import time
Expand All @@ -12,6 +11,8 @@
from functools import partial
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Type, Union

import psutil

import testslide.core.matchers
import testslide.core.mock_callable
import testslide.core.mock_constructor
Expand All @@ -33,6 +34,7 @@ class LeftOverActiveTasks(BaseException):

pass


class Skip(Exception):
"""
Raised by an example when it is skipped
Expand All @@ -53,7 +55,6 @@ class SlowCallback(Exception):
"""



def get_active_tasks():
return [
task for task in get_all_tasks() if not task.done() and not task.cancelled()
Expand All @@ -74,6 +75,7 @@ async def _async_ensure_no_leaked_tasks(coro):

return result


class BaseFormatter:
"""
Formatter base class. To be paired with Runner, to process / output example
Expand Down
5 changes: 2 additions & 3 deletions testslide/cli.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from testslide.executor.lib import *
from testslide.executor.lib import *
from testslide.executor.cli import *
from testslide.executor.import_profiler import *
from testslide.executor.import_profiler import ImportedModule, ImportProfiler
from testslide.executor.lib import *
15 changes: 7 additions & 8 deletions testslide/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
import os
import sys
import unittest

from typing import Any

from . import mock_callable as _mock_callable, mock_constructor as _mock_constructor, patch_attribute as _patch_attribute
from . import mock_callable as _mock_callable
from . import mock_constructor as _mock_constructor
from . import patch_attribute as _patch_attribute
from .strict_mock import StrictMock # noqa

if sys.version_info < (3, 7):
raise RuntimeError("Python >=3.7 required.")


def _importer(target: str) -> Any:
components = target.split(".")
import_path = components.pop(0)
Expand All @@ -39,24 +41,21 @@ def dot_lookup(thing: object, comp: str, import_path: str) -> Any:
thing = dot_lookup(thing, comp, import_path)
return thing


class TestCase(unittest.TestCase):
"""
A subclass of unittest.TestCase that adds TestSlide's features.
"""

def setUp(self) -> None:
_mock_callable.register_assertion = lambda assertion: self.addCleanup(
assertion
)
_mock_callable.register_assertion = lambda assertion: self.addCleanup(assertion)
self.addCleanup(_mock_callable.unpatch_all_callable_mocks)
self.addCleanup(_mock_constructor.unpatch_all_constructor_mocks)
self.addCleanup(_patch_attribute.unpatch_all_mocked_attributes)
super(TestCase, self).setUp()

@staticmethod
def mock_callable(
*args: Any, **kwargs: Any
) -> _mock_callable._MockCallableDSL:
def mock_callable(*args: Any, **kwargs: Any) -> _mock_callable._MockCallableDSL:
return _mock_callable.mock_callable(*args, **kwargs)

@staticmethod
Expand Down
7 changes: 5 additions & 2 deletions testslide/core/mock_callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
)
from unittest.mock import Mock

from testslide.core.lib import _validate_return_type, _wrap_signature_and_type_validation
from testslide.core.lib import (
_validate_return_type,
_wrap_signature_and_type_validation,
)
from testslide.core.strict_mock import StrictMock

from .lib import CoroutineValueError, _bail_if_private, _is_a_builtin
Expand Down Expand Up @@ -832,7 +835,7 @@ def __init__(
self._allow_coro = False
self._accept_partial_call = False
if isinstance(target, str):
from testslide import _importer
from testslide.core import _importer

self._target = _importer(target)
else:
Expand Down
2 changes: 1 addition & 1 deletion testslide/core/mock_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def mock_constructor(
raise ValueError("Second argument must be a string with the name of the class.")
_bail_if_private(class_name, allow_private)
if isinstance(target, str):
from testslide import _importer
from testslide.core import _importer

target = _importer(target)
target_class_id = (id(target), class_name)
Expand Down
2 changes: 1 addition & 1 deletion testslide/core/patch_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def patch_attribute(
_bail_if_private(attribute, allow_private)

if isinstance(target, str):
from testslide import _importer
from testslide.core import _importer

target = _importer(target)

Expand Down
Loading

0 comments on commit d966428

Please sign in to comment.