Skip to content

Commit

Permalink
make format (#362)
Browse files Browse the repository at this point in the history
Summary:
github build is failing because of formatting errors - let's see if I can make the open-source formatter and the internal formatter happy at the same time...

Pull Request resolved: #362

Reviewed By: deathowl

Differential Revision: D55365615

Pulled By: shish

fbshipit-source-id: f0da6298324cb2f2eb4cdce976040ccdaff66a35
  • Loading branch information
shish authored and facebook-github-bot committed Mar 26, 2024
1 parent 16fac3e commit f8bffd3
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 34 deletions.
4 changes: 2 additions & 2 deletions tests/mock_callable_testslide.py
Expand Up @@ -7,13 +7,13 @@
import os

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

Expand Down
38 changes: 20 additions & 18 deletions testslide/cli.py
Expand Up @@ -356,32 +356,34 @@ def _get_config_from_parsed_args(self, parsed_args: Any) -> _Config:
force_color=parsed_args.force_color,
trim_path_prefix=parsed_args.trim_path_prefix[0],
show_testslide_stack_trace=parsed_args.show_testslide_stack_trace,
profile_threshold_ms=parsed_args.import_profiler[0]
if parsed_args.import_profiler
else None,
profile_threshold_ms=(
parsed_args.import_profiler[0] if parsed_args.import_profiler else None
),
shuffle=parsed_args.shuffle,
list=parsed_args.list,
seed=parsed_args.seed[0] if parsed_args.seed else None,
focus=parsed_args.focus,
fail_if_focused=parsed_args.fail_if_focused,
fail_fast=parsed_args.fail_fast,
names_text_filter=parsed_args.filter_text[0]
if parsed_args.filter_text
else None,
names_regex_filter=parsed_args.filter_regex[0]
if parsed_args.filter_regex
else None,
names_regex_exclude=parsed_args.exclude_regex[0]
if parsed_args.exclude_regex
else None,
names_text_filter=(
parsed_args.filter_text[0] if parsed_args.filter_text else None
),
names_regex_filter=(
parsed_args.filter_regex[0] if parsed_args.filter_regex else None
),
names_regex_exclude=(
parsed_args.exclude_regex[0] if parsed_args.exclude_regex else None
),
quiet=parsed_args.quiet,
dsl_debug=parsed_args.dsl_debug,
import_module_names=self._modules
if self._modules
else [
_filename_to_module_name(test_file)
for test_file in parsed_args.test_files
],
import_module_names=(
self._modules
if self._modules
else [
_filename_to_module_name(test_file)
for test_file in parsed_args.test_files
]
),
slow_callback_is_not_fatal=parsed_args.slow_callback_is_not_fatal,
)
return config
Expand Down
4 changes: 2 additions & 2 deletions testslide/mock_callable.py
Expand Up @@ -10,22 +10,22 @@
import re
from inspect import Traceback
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
List,
Optional,
Tuple,
Type,
TYPE_CHECKING,
Union,
)
from unittest.mock import Mock

from testslide.lib import _validate_return_type, _wrap_signature_and_type_validation
from testslide.strict_mock import StrictMock

from .lib import _bail_if_private, _is_a_builtin, CoroutineValueError
from .lib import CoroutineValueError, _bail_if_private, _is_a_builtin
from .patch import _is_instance_method, _patch

if TYPE_CHECKING:
Expand Down
21 changes: 12 additions & 9 deletions testslide/mock_constructor.py
Expand Up @@ -230,16 +230,18 @@ def _get_mocked_class(
_restore_dict[target_class_id][name] = value
# ...and reuse them...
mocked_class_dict = {
"__new__": _wrap_type_validation(
original_class,
callable_mock,
[
original_class_new,
original_class_init,
],
"__new__": (
_wrap_type_validation(
original_class,
callable_mock,
[
original_class_new,
original_class_init,
],
)
if type_validation
else callable_mock
)
if type_validation
else callable_mock
}
mocked_class_dict.update(
{
Expand Down Expand Up @@ -331,6 +333,7 @@ def mock_constructor(
_bail_if_private(class_name, allow_private)
if isinstance(target, str):
from testslide import _importer

target = _importer(target)
target_class_id = (id(target), class_name)

Expand Down
1 change: 1 addition & 0 deletions testslide/patch_attribute.py
Expand Up @@ -55,6 +55,7 @@ def patch_attribute(

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

target = _importer(target)

key = (id(target), attribute)
Expand Down
1 change: 1 addition & 0 deletions testslide/runner.py
Expand Up @@ -282,6 +282,7 @@ class FailurePrinterMixin(ColorFormatterMixin):
@property
def TESTSLIDE_PATH(self) -> str:
from testslide import __file__

return os.path.abspath(os.path.dirname(__file__))

def _get_test_module_index(self, tb: traceback.StackSummary) -> Optional[int]:
Expand Down
9 changes: 6 additions & 3 deletions testslide/strict_mock.py
Expand Up @@ -602,9 +602,12 @@ def __init__(
self.__dict__["_name"] = name
self.__dict__["_type_validation"] = type_validation
self.__dict__["__caller"] = self.__get_caller(1)
self.__dict__[
"_attributes_to_skip_type_validation"
] = attributes_to_skip_type_validation
# black on py3.7 formats this differently to black on py3.8+ -_-
# fmt: off
self.__dict__["_attributes_to_skip_type_validation"] = (
attributes_to_skip_type_validation
)
# fmt: on

caller_frame = inspect.currentframe().f_back # type: ignore
# loading the context ends up reading files from disk and that might block
Expand Down

0 comments on commit f8bffd3

Please sign in to comment.