expycted


Nameexpycted JSON
Version 0.8.2 PyPI version JSON
download
home_pagehttps://github.com/bdsoha/expycted
SummaryBecause tests should be easy to read
upload_time2022-12-08 08:26:05
maintainer
docs_urlNone
authorDov Benyomin Sohacheski
requires_python>=3.6,<4.0
licenseMIT
keywords expect expect-pattern testing test matchers
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Overview

__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:
```python
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

```

# Installation

__Expycted__ can be installed from PyPi by using:
```shell
pip install expycted
```

Alternatively, you can clone the repository and build your own distribution using poetry.
```sh
git clone https://github.com/petereon/expycted.git
poetry build
```
Then you can install it using:
```sh
pip install ./dist/expycted-<version>-py3-none-any.whl
```

# Matchers

Matchers are used to ensure some conditions are met.

## Value Matchers

Value matchers can be used in two equivalent ways demonstrated below:

```python
expect.value(10).to.be_greater_than(1)
expect(10).to.be_greater_than(1)
```

Currently available matchers are:

- Eqality and similarity
    - `equal(self, value)`: equivalent to "`==`". With alias `be_equal_to`
    - `be(self, value)`:  will check if string representation of values is same or if two objects have the same attributes or are equal
- Numeric
    - `be_greater_than(self, value)`: equivalent to "`>`". With alias `be_greater`
    - `be_lesser_than(self, value)`: equivalent to "`<`". With alias `be_lesser `, `be_less`, `be_less_than`
    - `be_greater_or_equal_to(self, value)`: equivalent to "`>=`". With aliases `be_greater_or_equal`, `be_greater_than_or_equal_to`
    - `be_lesser_or_equal_to(self, value)`: equivalent to "`<=`". With aliases `be_lesser_or_equal`, `be_less_or_equal`, `be_less_than_or_equal_to`, `be_lesser_than_or_equal_to`
    - `be_numeric(self)`: checks if `self.value` is a number or string covertible to a number. With alias `be_a_number`
- Containment and Emptiness
    - `contain(self, value)`: equivalent to "`in`". With aliases `have`, `include`
    - `be_contained_in(self, value)`: equivalent to "`in`". Qith aliases `be_in`, `be_included_in`
    - `be_empty(self)`: checks if `self.value` is iterable and `False`
- Truthiness
    - `be_true(self)`: checks if `self.value` is `True`
    - `be_false(self)`: checks if `self.value` is `False`
    - `be_truthy(self)`: checks if `self.value` behaves _true_ in if statement. With aliases `be_truey`, `be_trueish `
    - `be_falsey(self)`: checks if `self.value` behaves _false_ in if statement. With aliases `be_falsy`, `be_falsish`
- Typing
    - `be_of_type(self, value)`: checks if `self.value` is of specified type. With aliases `be_type`, `have_type`
    - `inherit(self, value)`: checks if `self.value` inherits/is a specified type. `be_subclass_of`, `have_parent`


## Function Matchers

Function matchers can be called as such:
```python
expect.function(string.replace).to_return('strength').when_called_with('ing', 'ength')
```

Currently available matchers are:
- `to_return(self, value=None, type_of_value=None)` - checks if function returns a specified value, or type, or both.
- `to_raise(self, exception_type)` - checks if function raises a specified exception.

In each case we have to specify arguments with which function is called in `.when_called_with` method. Method has aliases `when_called_with_args`, `when_called_with_arguments`

## Filesystem Matchers

Filesystem matchers can be called as such:
```python
expect.folder('/some/folder').to.contain('subfolder')
```
Currently available matchers are:
- `contain(self, name, type: Union[File, Folder, None, str] = None)` - checks if folder contains a specified file or folder. If type is specified, it will check if file is file or folder is folder.
- `contain_file(self, name)` - checks if folder contains a specified file.
- `contain_folder(self, name)` - checks if folder contains a specified folder.
- `exist(self)` - checks if folder exists.
- `be_empty(self)` - checks if folder is empty.

They can be used with both `expect.folder('/some/folder').to` and `expect.folder('/some/folder').to_not` to check both positive and negative expectations.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/bdsoha/expycted",
    "name": "expycted",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6,<4.0",
    "maintainer_email": "",
    "keywords": "expect,expect-pattern,testing,test,matchers",
    "author": "Dov Benyomin Sohacheski",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/78/75/98e72da8d61ab2b2e7c10dcee7ffe47d20a9212cddba0fc330b250db02ea/expycted-0.8.2.tar.gz",
    "platform": null,
    "description": "# Overview\n\n__Expycted__ is yet another `expect` pattern implementation.\n\nIt is not dependent on any testing framework and can plug into any as it is just an abstraction over `assert`.\n\nExamples:\n```python\nfrom expycted import expect\n\nexpect(True).to_not.be_false()                                  # This will succeed\n\nexpect([]).to.be_empty()                                        # This will succeed\n\nexpect([1,2,3]).to.contain(3)                                   # This will succeed\n\nexpect(10).to.equal(\"10\")                                       # This will raise AssertionError\n\nexpect(10).to.be(\"10\")                                          # This will succeed\n\nexpect.function(int).to_raise(ValueError).when_called_with('a') # This will also succeed\n\n```\n\n# Installation\n\n__Expycted__ can be installed from PyPi by using:\n```shell\npip install expycted\n```\n\nAlternatively, you can clone the repository and build your own distribution using poetry.\n```sh\ngit clone https://github.com/petereon/expycted.git\npoetry build\n```\nThen you can install it using:\n```sh\npip install ./dist/expycted-<version>-py3-none-any.whl\n```\n\n# Matchers\n\nMatchers are used to ensure some conditions are met.\n\n## Value Matchers\n\nValue matchers can be used in two equivalent ways demonstrated below:\n\n```python\nexpect.value(10).to.be_greater_than(1)\nexpect(10).to.be_greater_than(1)\n```\n\nCurrently available matchers are:\n\n- Eqality and similarity\n    - `equal(self, value)`: equivalent to \"`==`\". With alias `be_equal_to`\n    - `be(self, value)`:  will check if string representation of values is same or if two objects have the same attributes or are equal\n- Numeric\n    - `be_greater_than(self, value)`: equivalent to \"`>`\". With alias `be_greater`\n    - `be_lesser_than(self, value)`: equivalent to \"`<`\". With alias `be_lesser `, `be_less`, `be_less_than`\n    - `be_greater_or_equal_to(self, value)`: equivalent to \"`>=`\". With aliases `be_greater_or_equal`, `be_greater_than_or_equal_to`\n    - `be_lesser_or_equal_to(self, value)`: equivalent to \"`<=`\". With aliases `be_lesser_or_equal`, `be_less_or_equal`, `be_less_than_or_equal_to`, `be_lesser_than_or_equal_to`\n    - `be_numeric(self)`: checks if `self.value` is a number or string covertible to a number. With alias `be_a_number`\n- Containment and Emptiness\n    - `contain(self, value)`: equivalent to \"`in`\". With aliases `have`, `include`\n    - `be_contained_in(self, value)`: equivalent to \"`in`\". Qith aliases `be_in`, `be_included_in`\n    - `be_empty(self)`: checks if `self.value` is iterable and `False`\n- Truthiness\n    - `be_true(self)`: checks if `self.value` is `True`\n    - `be_false(self)`: checks if `self.value` is `False`\n    - `be_truthy(self)`: checks if `self.value` behaves _true_ in if statement. With aliases `be_truey`, `be_trueish `\n    - `be_falsey(self)`: checks if `self.value` behaves _false_ in if statement. With aliases `be_falsy`, `be_falsish`\n- Typing\n    - `be_of_type(self, value)`: checks if `self.value` is of specified type. With aliases `be_type`, `have_type`\n    - `inherit(self, value)`: checks if `self.value` inherits/is a specified type. `be_subclass_of`, `have_parent`\n\n\n## Function Matchers\n\nFunction matchers can be called as such:\n```python\nexpect.function(string.replace).to_return('strength').when_called_with('ing', 'ength')\n```\n\nCurrently available matchers are:\n- `to_return(self, value=None, type_of_value=None)` - checks if function returns a specified value, or type, or both.\n- `to_raise(self, exception_type)` - checks if function raises a specified exception.\n\nIn each case we have to specify arguments with which function is called in `.when_called_with` method. Method has aliases `when_called_with_args`, `when_called_with_arguments`\n\n## Filesystem Matchers\n\nFilesystem matchers can be called as such:\n```python\nexpect.folder('/some/folder').to.contain('subfolder')\n```\nCurrently available matchers are:\n- `contain(self, name, type: Union[File, Folder, None, str] = None)` - checks if folder contains a specified file or folder. If type is specified, it will check if file is file or folder is folder.\n- `contain_file(self, name)` - checks if folder contains a specified file.\n- `contain_folder(self, name)` - checks if folder contains a specified folder.\n- `exist(self)` - checks if folder exists.\n- `be_empty(self)` - checks if folder is empty.\n\nThey can be used with both `expect.folder('/some/folder').to` and `expect.folder('/some/folder').to_not` to check both positive and negative expectations.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Because tests should be easy to read",
    "version": "0.8.2",
    "split_keywords": [
        "expect",
        "expect-pattern",
        "testing",
        "test",
        "matchers"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "c6a4b22c6705ef7fb5dbcc600bf281f1",
                "sha256": "cac36bf7155ffc20a976a09996ae22e2ebdb9e45ece4ea9510113c16ee402e6c"
            },
            "downloads": -1,
            "filename": "expycted-0.8.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c6a4b22c6705ef7fb5dbcc600bf281f1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6,<4.0",
            "size": 8910,
            "upload_time": "2022-12-08T08:26:02",
            "upload_time_iso_8601": "2022-12-08T08:26:02.984040Z",
            "url": "https://files.pythonhosted.org/packages/fe/2b/7b170d1d934fda6d67dd0290acaef389085ec6b830161fdac20826ebbf08/expycted-0.8.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "e27d6daaff5c509c137475a9085ee115",
                "sha256": "7776757de000d2f724a7292c77c277d68e16f4d72fc6176eeb9743187f417540"
            },
            "downloads": -1,
            "filename": "expycted-0.8.2.tar.gz",
            "has_sig": false,
            "md5_digest": "e27d6daaff5c509c137475a9085ee115",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6,<4.0",
            "size": 8906,
            "upload_time": "2022-12-08T08:26:05",
            "upload_time_iso_8601": "2022-12-08T08:26:05.278166Z",
            "url": "https://files.pythonhosted.org/packages/78/75/98e72da8d61ab2b2e7c10dcee7ffe47d20a9212cddba0fc330b250db02ea/expycted-0.8.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-08 08:26:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "bdsoha",
    "github_project": "expycted",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "expycted"
}
        
Elapsed time: 0.01584s