Skip to content

Commit

Permalink
Merge fc2d2c1 into 0b9dd4a
Browse files Browse the repository at this point in the history
  • Loading branch information
macisamuele committed Mar 20, 2021
2 parents 0b9dd4a + fc2d2c1 commit 0ebbafa
Show file tree
Hide file tree
Showing 17 changed files with 401 additions and 117 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Generally speaking:
Here's a quick cookbook on how to have a Python installation working using Docker:

- Install [Docker CE](https://docs.docker.com/install/).
- Clone the repo: `git clone https://github.com/facebookincubator/TestSlide.git`.
- Clone the repo: `git clone https://github.com/facebook/TestSlide.git`.
- Create the Docker image: `docker create --name testslide --interactive --tty --mount type=bind,source="$PWD"/TestSlide,target=/root/src/TestSlide --workdir=/root/src/TestSlide debian /bin/bash`.
- Start a container with this image: `docker start --interactive testslide`.
- Install the dependencies: `apt update && apt -y install build-essential curl git libbz2-dev libncurses5-dev libreadline-dev libsqlite3-dev libssl-dev llvm vim wget zlib1g-dev`.
Expand Down
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ endif
.PHONY: all
all: tests coverage_report docs sdist

# .PHONY does not work for implicit rules, so we FORCE them
FORCE:

##
## Docs
##
Expand All @@ -57,7 +54,7 @@ docs_clean:
## Tests
##

%_unittest.py: FORCE coverage_erase
%_unittest.py: coverage_erase
@printf "${TERM_BRIGHT}UNITTEST $@\n${TERM_NONE}"
${Q} coverage run \
-m unittest \
Expand All @@ -70,15 +67,15 @@ unittest_tests: $(TESTS_SRCS)/*_unittest.py

.PHONY: pytest_tests
pytest_tests: export PYTHONPATH=${CURDIR}/pytest-testslide:${CURDIR}
pytest_tests: FORCE coverage_erase
pytest_tests: coverage_erase
@printf "${TERM_BRIGHT}INSTALL pytest_testslide DEPS ${TERM_NONE}\n"
${Q} pip install -r pytest-testslide/requirements.txt
@printf "${TERM_BRIGHT}PYTEST pytest_testslide${TERM_NONE}\n"
${Q} coverage run \
-m pytest \
pytest-testslide/tests
-m pytest \
pytest-testslide/tests

%_testslide.py: FORCE coverage_erase
%_testslide.py: coverage_erase
@printf "${TERM_BRIGHT}TESTSLIDE $@\n${TERM_NONE}"
${Q} coverage run \
-m testslide.cli \
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![TestSlide](./docs/testslide_logo.png)

[![Build Status](https://github.com/facebookincubator/TestSlide/workflows/CI/badge.svg)](https://github.com/facebookincubator/TestSlide/actions?query=workflow%3ACI)
[![Coverage Status](https://coveralls.io/repos/github/facebookincubator/TestSlide/badge.svg?branch=master)](https://coveralls.io/github/facebookincubator/TestSlide?branch=master)
[![Build Status](https://github.com/facebook/TestSlide/workflows/CI/badge.svg)](https://github.com/facebookincubator/TestSlide/actions?query=workflow%3ACI)
[![Coverage Status](https://coveralls.io/repos/github/facebook/TestSlide/badge.svg?branch=master)](https://coveralls.io/github/facebookincubator/TestSlide?branch=master)
[![Documentation Status](https://readthedocs.org/projects/testslide/badge/?version=master)](https://testslide.readthedocs.io/en/master/?badge=master)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![PyPI version](https://badge.fury.io/py/TestSlide.svg)](https://badge.fury.io/py/TestSlide)
Expand Down Expand Up @@ -56,7 +56,7 @@ TestSlide's `StrictMock`, `mock_constructor()` and `mock_callable()` are seamles

Run the test and see the failure:

![Failing test](https://raw.githubusercontent.com/facebookincubator/TestSlide/master/docs/test_fail.png)
![Failing test](https://raw.githubusercontent.com/facebook/TestSlide/master/docs/test_fail.png)

TestSlide's mocks failure messages guide you towards the solution, that you can now implement:

Expand All @@ -73,7 +73,7 @@ class Backup(object):

And watch the test go green:

![Passing test](https://raw.githubusercontent.com/facebookincubator/TestSlide/master/docs/test_pass.png)
![Passing test](https://raw.githubusercontent.com/facebook/TestSlide/master/docs/test_pass.png)

It is all about letting the failure messages guide you towards the solution. There's a plethora of validation inside TestSlide's mocks, so you can trust they will help you iterate quickly when writing code and also cover you when breaking changes are introduced.

Expand Down
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- Create a new release tag by running:
- `./release.sh $new_version`
- https://github.com/facebookincubator/TestSlide/actions
- https://github.com/facebook/TestSlide/actions
- Check if master build is OK.
- https://readthedocs.org/projects/testslide/
- Trigger bulid for
Expand Down
2 changes: 1 addition & 1 deletion pytest-testslide/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
py_modules=["pytest_testslide"],
maintainer="Balint Csergo",
maintainer_email="deathowlzz@gmail.com",
url="https://github.com/facebookincubator/TestSlide/tree/master/pytest-testslide",
url="https://github.com/facebook/TestSlide/tree/master/pytest-testslide",
license="MIT",
description="TestSlide fixture for pytest",
long_description=readme,
Expand Down
8 changes: 3 additions & 5 deletions pytest-testslide/tests/test_pytest_testslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def test_mock_async_callable_patching_works(testslide):
async def test_mock_async_callable_unpatching_works(testslide):
# This will fail if unpatching from test_mock_async_callable_patching_works does
# not happen
assert await sample_module.ParentTarget.async_static_method("a", "b") == "async original response"
assert await sample_module.ParentTarget.async_static_method("a", "b") == ["async original response"]
@pytest.mark.asyncio
async def test_mock_async_callable_assertion_works(testslide):
Expand All @@ -85,8 +85,7 @@ async def test_mock_async_callable_assertion_works(testslide):
def test_mock_async_callable_failing_assertion_works(testslide):
testslide.mock_async_callable(sample_module.ParentTarget, "async_static_method").for_call("a", "b").to_call_original().and_assert_called_once()
# mock_constructor integration test
def test_mock_constructor_patching_works(testslide):
testslide.mock_constructor(sample_module, "ParentTarget").to_raise(RuntimeError("Mocked!"))
Expand Down Expand Up @@ -115,7 +114,6 @@ def test_patch_attribute_unpatching_works(testslide):
# not happen
assert sample_module.SomeClass.attribute == "value"
def test_aggregated_exceptions(testslide):
mocked_cls = StrictMock(sample_module.CallOrderTarget)
testslide.mock_callable(mocked_cls, 'f1')\
Expand All @@ -131,7 +129,7 @@ def test_aggregated_exceptions(testslide):
assert "passed, 4 errors" in result.stdout.str()
assert "failed" not in result.stdout.str()
expected_failure = re.compile(
""".*_______ ERROR at teardown of test_mock_callable_failing_assertion_works ________
r""".*_______ ERROR at teardown of test_mock_callable_failing_assertion_works ________
1 failures.
<class \'AssertionError\'>: calls did not match assertion.
\'time\', \'sleep\':
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
packages=["testslide"],
maintainer="Fabio Pugliese Ornellas",
maintainer_email="fabio.ornellas@gmail.com",
url="https://github.com/facebookincubator/TestSlide",
url="https://github.com/facebook/TestSlide",
license="MIT",
description="A test framework for Python that makes mocking and iterating over code with tests a breeze",
long_description=readme,
Expand Down
10 changes: 5 additions & 5 deletions tests/lib_testslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def typevar(context):
def ingores_TypeVar(self):
"""
We currently can't enforce TypeVar:
https://github.com/facebookincubator/TestSlide/issues/165
https://github.com/facebook/TestSlide/issues/165
"""

def with_typevar(lolo: T) -> None:
Expand All @@ -189,7 +189,7 @@ def with_typevar(lolo: T) -> None:
def ignores_nested_TypeVar(self):
"""
We currently can't enforce TypeVar:
https://github.com/facebookincubator/TestSlide/issues/165
https://github.com/facebook/TestSlide/issues/165
"""

def with_typevar(arg1: Type[T]) -> None:
Expand Down Expand Up @@ -340,21 +340,21 @@ def assert_fails(self, value):

@context.example
def passes_for_correct_type(self):
self.assert_passes("arg1")
self.assert_passes(["arg1"])

@context.example
def passes_for_mock_without_template(self):
self.assert_passes(StrictMock())

@context.example
def passes_for_mock_with_correct_template(self):
self.assert_passes(StrictMock(template=str))
self.assert_passes([StrictMock(template=str)])

@context.example
def passes_if_TypeVar_in_signature(self):
"""
We currently can't enforce TypeVar:
https://github.com/facebookincubator/TestSlide/issues/165
https://github.com/facebook/TestSlide/issues/165
"""

def with_typevar_return() -> Type[TypeVar("T")]:
Expand Down
2 changes: 1 addition & 1 deletion tests/matchers_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def test_patch_callable(self):
self.mock_callable(sample_module, "test_function").for_call(
testslide.matchers.RegexMatches("foo"),
testslide.matchers.RegexMatches("bar"),
).to_return_value("mocked_response")
).to_return_value(["mocked_response"])
with self.assertRaises(testslide.mock_callable.UnexpectedCallArguments):
sample_module.test_function("meh", "moh")
sample_module.test_function("foo", "bar")
12 changes: 6 additions & 6 deletions tests/mock_async_callable_testslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def assertions(self):

@context.memoize_before
async def value(self):
return "mocked value"
return ["mocked value"]

##
## Functions
Expand Down Expand Up @@ -149,9 +149,9 @@ async def for_call(self):
mock_kwargs = {k: f"mock {str(v)}" for k, v in self.call_kwargs.items()}
mock_async_callable(self.target_arg, self.callable_arg).for_call(
*mock_args, **mock_kwargs
).to_return_value("mock")
).to_return_value(["mock"])
self.assertEqual(
await self.callable_target(*mock_args, **mock_kwargs), "mock"
await self.callable_target(*mock_args, **mock_kwargs), ["mock"]
)
if mock_args or mock_kwargs:
with self.assertRaises(UnexpectedCallArguments):
Expand Down Expand Up @@ -181,7 +181,7 @@ def to_return_values(context):
async def before(self):
mock_async_callable(
self.target_arg, self.callable_arg
).to_return_values([self.value, "mock2"])
).to_return_values([self.value, ["mock2"]])
self.callable_target = getattr(self.real_target, self.callable_arg)

@context.example
Expand All @@ -192,7 +192,7 @@ async def it_returns_values(self):
)
self.assertEqual(
await self.callable_target(*self.call_args, **self.call_kwargs),
"mock2",
["mock2"],
)
with self.assertRaisesRegex(
UndefinedBehaviorForCall, "No more values to return!"
Expand Down Expand Up @@ -348,7 +348,7 @@ async def and_assert(self):
async def mock_async_callable_can_not_assert_if_already_received_call(self):
mock = self.mock_async_callable(
self.target_arg, self.callable_arg
).to_return_value("mocked")
).to_return_value(["mocked"])
await self.callable_target(*self.call_args, **self.call_kwargs)
with self.assertRaisesRegex(
ValueError,
Expand Down
Loading

0 comments on commit 0ebbafa

Please sign in to comment.