Table of Contents
Expycted is yet another expect
pattern implementation.
It is not dependent on any testing framework and can plug into any as it is just an abstraction over assert
.
Examples:
from expycted import expect
expect(True).to_not.be_false() # This will succeed
expect([]).to.be_empty() # This will succeed
expect([1,2,3]).to.contain(3) # This will succeed
expect(10).to.equal("10") # This will raise AssertionError
expect(10).to.be("10") # This will succeed
expect.function(int).to_raise(ValueError).when_called_with('a') # This will also succeed
This package was originally written by @petereon, many thanks!
Expycted can be installed from PyPi by running:
pip install expycted
Alternatively, you can clone the repository and build your own distribution using poetry:
git clone https://github.com/bdsoha/expycted.git
poetry build
Then you can install it using:
pip install ./dist/expycted-<version>-py3-none-any.whl
Matchers are used to ensure some conditions are met on an expected value.
Value matchers can be used in two equivalent ways demonstrated below:
expect.value(10).to.be_greater_than(1)
expect(10).to.be_greater_than(1)
Currently available matchers are:
Assert that the expected value is equivalent to the actual value using the ==
operator.
- Definition:
equal(self, value)
- Alias:
be_equal_to(self, value)
Assert that the expected value is the same as the actual value.
- Definition:
be(self, value)
- Details: Assert any of the following conditions:
- Assert the expected value's string representation is the same as the actual value's string representation.
- When provided two objects, assert that have the same attributes.
- Assert the expected value equals the actual value.
Assert that the expected value is greater than the actual value using the >
operator.
- Definition:
be_greater_than(self, value)
- Alias:
be_greater(self, value)
Assert that the expected value is less than the actual value using the <
operator.
- Definition:
be_lesser_than(self, value)
- Alias:
be_lesser(self, value)
be_less(self, value)
be_less_than(self, value)
Assert that the expected value is greater than the actual value using the >=
operator.
- Definition:
be_greater_or_equal_to(self, value)
- Alias:
be_greater_or_equal(self, value)
be_greater_than_or_equal_to(self, value)
Assert that the expected value is less than the actual value using the <=
operator.
- Definition:
be_lesser_or_equal_to(self, value)
- Alias:
be_lesser_or_equal(self, value)
be_less_or_equal(self, value)
be_less_than_or_equal_to(self, value)
be_lesser_than_or_equal_to(self, value)
Assert that the expected value is a number or can be parsed as a number from a string representation.
- Definition:
be_numeric(self)
- Alias:
be_a_number(self)
Assert the expected value contains a value using the in
keyword.
- Definition:
contain(self, value)
- Alias:
have(self, value)
include(self, value)
Assert the expected value is contained in a value using the in
keyword.
- Definition:
be_contained_in(self, value)
- Alias:
be_in(self, value)
be_included_in(self, value)
Assert that the expected value is iterable
and False
.
- Definition:
be_empty(self)
Assert that the expected value is strictly True
.
- Definition:
be_true(self)
Assert that the expected value is strictly False
.
- Definition:
be_false(self)
Assert that the expected value is equivalent to True
.
- Definition:
be_truthy(self)
- Alias:
be_truey(self)
be_trueish(self)
Assert that the expected value is equivalent to False
.
- Definition:
be_falsey(self)
- Alias:
be_falsy(self)
be_falsish(self)
Assert that the expected value has a given type.
- Definition:
be_of_type(self, value)
- Alias:
be_type(self, value)
have_type(self, value)
Assert that the expected value inherits or is a subclass of a given type.
- Definition:
inherit(self, value)
- Alias:
be_subclass_of(self, value)
have_parent(self, value)
Function matchers can be used as demonstrated below:
expect.function(string.replace).to_return('strength').when_called_with('string', 'ength')
Arguments can be passed to the expected function using the .when_called_with
method, (or its alias methods: when_called_with_args
and when_called_with_arguments
).
Assert that the expected function returns the actual value, or type, or both.
- Definition:
to_return(self, value=None, type_of_value=None)
Assert that the expected function raises the actual exception of a given type.
- Definition:
to_raise(self, exception_type)
Filesystem matchers can be used as demonstrated below:
expect.folder('/some/folder').to.contain('subfolder')
Matchers can be used with both expect.folder('/some/folder').to
and expect.folder('/some/folder').to_not
to check both positive and negative expectations.
Assert that the expected folder contains the actual file or folder.
- Definition:
contain(self, name, type: Union[File, Folder, None, str] = None)
- Details: When the
type
argument is specified, it will also assert whether actual value is aFile
orFolder
.
Assert that the expected folder contains the actual file.
- Definition:
contain_file(self, name)
Assert that the expected folder contains the actual folder.
- Definition:
contain_folder(self, name)
Assert that the expected folder exists.
- Definition:
exist(self)
Assert that the expected folder is empty.
- Definition:
be_empty(self)
For development a combination of poetry
and pipenv
is used. pipenv
is used to install dependencies and manage virtual environments while poetry
is used for building and metadata management.
To begin developing run the following commands in your terminal:
# Clone the repository
git clone https://github.com/bdsoha/expycted.git
# Install dependencies
pipenv install
# Run tests
pipenv run test
# Build the package
pipenv run build
Project is currently in its infancy, contributors, pull requests and issues are welcome