{ "info": { "author": "Gregory Kwok", "author_email": "gkwok@google.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Software Development :: Quality Assurance", "Topic :: Software Development :: Testing" ], "description": "\n\n# PyTruth: Truth in Python\n\nProvides unittest assertions in a fluent style.\nTranslated from the Java implementation,\n[google/truth](https://github.com/google/truth).\n\n## License\n\nPyTruth is licensed under the [Apache 2.0 license](LICENSE).\n\n## Disclaimer\n\nPyTruth is not an official Google product.\n\n## Contributing\n\nPlease see the [guidelines for contributing](CONTRIBUTING.md)\nbefore creating pull requests.\n\n## Support\n\nPyTruth is not an actively maintained project. No support is provided.\n\nIt is shared with the community to bring an expressive, consistent assertion\nstyle to projects that may be using a combination of\n[unittest](https://docs.python.org/3/library/unittest.html),\n[abseil](https://github.com/abseil/abseil-py),\n[googletest](https://github.com/google/googletest),\n[mox](https://pypi.python.org/pypi/mox), and\n[mock](https://docs.python.org/3/library/unittest.mock.html)—especially\nto people familiar with [Java Truth](https://github.com/google/truth).\n\nUser group:\n[pytruth-users@googlegroups.com](https://groups.google.com/d/forum/pytruth-users)\n\n### Installing\n\nPyTruth can be installed using [pip](https://pypi.org/project/pip/):\n\n```bash\npip install pytruth\n```\n\n## Overview\n\nImport the `truth` module and alias the `AssertThat()` method to begin asserting\nthings:\n\n```python\nfrom truth.truth import AssertThat\n```\n\nThen, instead of writing\n\n```python\nself.assertEqual(a, b)\nself.assertTrue(c)\nself.assertIn(a, d)\nself.assertTrue(a in d and b in d)\nself.assertTrue(a in d or b in d or c in d)\nwith self.assertRaises(Error):\n Explode()\n```\n\none would write\n\n```python\nAssertThat(a).IsEqualTo(b)\nAssertThat(c).IsTrue()\nAssertThat(d).Contains(a)\nAssertThat(d).ContainsAllOf(a, b)\nAssertThat(d).ContainsAnyOf(a, b, c)\nwith AssertThat(Error).IsRaised():\n Explode()\n```\n\nTests should be easier to read and write, and flow more clearly.\n\n## Limitations\n\nunittest assertions accept a `msg` parameter to display if the assertion fails.\nPyTruth has no such mechanism, though its failure messages tend to be more\ninformative.\n\nThe type of the subject under test (the parameter passed to `AssertThat()`) will\nnot be known until runtime, unlike Java where the type is known at compile time.\nIDEs may not correctly autocomplete available predicates on an asserted subject.\n\nIn Python 2, `None` compares less than every other thing, except `None` itself.\n`None` is less than `nan`, and it is less than negative infinity. Therefore, use\ncaution when a function might return `None`. The assertion\n`AssertThat(Func()).IsLessThan(0)` succeeds whether `Func()` returns a negative\nnumber or `None`. Instead, first check the `None`-ness of the return value with\n`IsNone()` or `IsNotNone()` before performing an inequality assertion.\n\nIn Python 3, `None` is no longer comparable using `<` `>` `<=` `>=`.\nPyTruth detects the version of the Python interpreter and compares or fails\nappropriately, rather than allowing Python 3's `TypeError` to bubble up.\n\nIf the iterator over a shared value (either expected or actual) changes that\nvalue or its underlying elements, the behavior is undefined:\nall, none, or some of the assertions may succeed or fail, arbitrarily.\n\nThis library is threadsafe; you may execute multiple assertions in parallel.\n\n## Conversion Recipes\n\n### General\nunittest | PyTruth\n-----------------------------|----------------------------------------\n`assertEqual(a, b)` | `AssertThat(a).IsEqualTo(b)`\n`assertNotEqual(a, b)` | `AssertThat(a).IsNotEqualTo(b)`\n`assertTrue(a)` | `AssertThat(a).IsTruthy()`\n`assertFalse(a)` | `AssertThat(a).IsFalsy()`\n`assertIs(a, True)` | `AssertThat(a).IsTrue()`\n`assertIs(a, False)` | `AssertThat(a).IsFalse()`\n`assertIs(a, b)` | `AssertThat(a).IsSameAs(b)`\n`assertIsNot(a, b)` | `AssertThat(a).IsNotSameAs(b)`\n`assertIsNone(a)` | `AssertThat(a).IsNone()`\n`assertIsNotNone(a)` | `AssertThat(a).IsNotNone()`\n`assertIn(a, b)` | `AssertThat(a).IsIn(b)`\n`assertIn(a, [b, c, d])` | `AssertThat(a).IsAnyOf(b, c, d)`\n`assertNotIn(a, b)` | `AssertThat(a).IsNotIn(b)`\n`assertNotIn(a, [b, c, d])` | `AssertThat(a).IsNoneOf(b, c, d)`\n`assertIsInstance(a, b)` | `AssertThat(a).IsInstanceOf(b)`\n`assertIsNotInstance(a, b)` | `AssertThat(a).IsNotInstanceOf(b)`\n`assertTrue(hasattr(a, b))` | `AssertThat(a).HasAttribute(b)`\n`assertFalse(hasattr(a, b))` | `AssertThat(a).DoesNotHaveAttribute(b)`\n`assertTrue(callable(a))` | `AssertThat(a).IsCallable()`\n`assertFalse(callable(a))` | `AssertThat(a).IsNotCallable()`\n\n#### Truthiness\n\nPyTruth supports a finer grained distinction of truthiness than unittest does.\nIn particular, it differentiates between \"is `True`\" and \"is *truthy*.\"\nunittest's `assertTrue(x)` is equivalent to `assertIs(bool(x), True)`,\nand its `assertFalse(x)` is equivalent to `assertIs(bool(x), False)`.\nPyTruth's `IsTrue()` and `IsFalse()` predicates match *only* the boolean\nsubjects `True` and `False` themselves.\nTherefore it is important not to blindly convert `assertTrue()` to `IsTrue()`,\nand likewise with `assertFalse()` and `IsFalse()`.\n\nTruthy assertion | Result | Falsy assertion | Result\n------------------------------|----------|-------------------------------|---------\n`assertTrue(True)` | succeeds | `assertFalse(False)` | succeeds\n`assertTrue(1)` | succeeds | `assertFalse(0)` | succeeds\n`assertTrue(None)` | fails | `assertFalse(None)` | succeeds\n`AssertThat(True).IsTrue()` | succeeds | `AssertThat(False).IsFalse()` | succeeds\n`AssertThat(1).IsTrue()` | fails | `AssertThat(0).IsFalse()` | fails\n`AssertThat(None).IsTrue()` | fails | `AssertThat(None).IsFalse()` | fails\n`AssertThat(True).IsTruthy()` | succeeds | `AssertThat(False).IsFalsy()` | succeeds\n`AssertThat(1).IsTruthy()` | succeeds | `AssertThat(0).IsFalsy()` | succeeds\n`AssertThat(None).IsTruthy()` | fails | `AssertThat(None).IsFalsy()` | succeeds\n\n### Strings\nunittest | PyTruth\n---------------------------------------------------------------|---------------------------------------\n`assertEqual(len(s), n)` | `AssertThat(s).HasLength(n)`\n`assertTrue(s.startswith('a'))` | `AssertThat(s).StartsWith('a')`\n`assertTrue(s.endswith('a'))` | `AssertThat(s).EndsWith('a')`\n`assertRegex(s, r)`
`assertRegexpMatches(s, r)` | `AssertThat(s).ContainsMatch(r)`\n`assertNotRegex(s, r)`
`assertNotRegexpMatches(s, r)` | `AssertThat(s).DoesNotContainMatch(r)`\n`assertRegex(s, '^r')`
`assertRegexpMatches(s, '^r')` | `AssertThat(s).Matches('r')`\n`assertNotRegex(s, '^r')`
`assertNotRegexpMatches(s, '^r')` | `AssertThat(s).DoesNotMatch('r')`\n\n#### Matching strings\n\nThe `r` parameter passed to the matching functions may either be a\n`r'raw string'`, or a pattern object returned from `re.compile()`.\n\n### Numbers, strings, and other comparable things\nunittest | PyTruth\n---------------------------|---------------------------------\n`assertLess(a, b)` | `AssertThat(a).IsLessThan(b)`\n`assertGreater(a, b)` | `AssertThat(a).IsGreaterThan(b)`\n`assertLessEqual(a, b)` | `AssertThat(a).IsAtMost(b)`\n`assertGreaterEqual(a, b)` | `AssertThat(a).IsAtLeast(b)`\n\n### Numbers\nunittest | PyTruth\n--------------------------------------|-------------------------------------\n`assertEqual(a, 0)` | `AssertThat(a).IsZero()`\n`assertNotEqual(a, 0)` | `AssertThat(a).IsNonZero()`\n`assertEqual(a, float('inf'))` | `AssertThat(a).IsPositiveInfinity()`\n`assertEqual(a, float('-inf'))` | `AssertThat(a).IsNegativeInfinity()`\n`assertFalse(a.isinf() or a.isnan())` | `AssertThat(a).IsFinite()`\n`assertTrue(a.isnan())` | `AssertThat(a).IsNan()`\n`assertFalse(a.isnan())` | `AssertThat(a).IsNotNan()`\n`assertAlmostEqual(a, b, delta=d)` | `AssertThat(a).IsWithin(d).Of(b)`\n`assertNotAlmostEqual(a, b, delta=d)` | `AssertThat(a).IsNotWithin(d).Of(b)`\n\n### Lists, strings, and other iterables\nunittest | PyTruth\n--------------------------------|---------------------------------------------\n`assertEqual(len(a), n)` | `AssertThat(a).HasSize(n)`\n`assertEqual(len(a), 0)` | `AssertThat(a).IsEmpty()`\n`assertGreaterThan(len(a), 0)` | `AssertThat(a).IsNotEmpty()`\n`assertIn(b, a)` | `AssertThat(a).Contains(b)`\n`assertNotIn(b, a)` | `AssertThat(a).DoesNotContain(b)`\n`assertTrue(b in a and c in a)` | `AssertThat(a).ContainsAllOf(b, c)`
`AssertThat(a).ContainsAllIn([b, c])`\n`assertTrue(b in a or c in a)` | `AssertThat(a).ContainsAnyOf(b, c)`
`AssertThat(a).ContainsAnyIn([b, c])`\n`assertTrue(b in a and c in a and len(a) == 2)` | `AssertThat(a).ContainsExactly(b, c)`\n`assertCountEqual(a, b)`
`assertItemsEqual(a, b)` | `AssertThat(sorted(a)).ContainsExactlyElementsIn(sorted(b)).InOrder()`\n`assertTrue(b not in a and c not in a)` | `AssertThat(a).ContainsNoneOf(b, c)`
`AssertThat(a).ContainsNoneIn([b, c])`\nN/A | `AssertThat(a).ContainsNoDuplicates()`\nN/A | `AssertThat(a).IsOrdered()`\nN/A | `AssertThat(a).IsOrderedAccordingTo(cf)`\nN/A | `AssertThat(a).IsStrictlyOrdered()`\nN/A | `AssertThat(a).IsStrictlyOrderedAccordingTo(cf)`\n\nabsltest | PyTruth\n--------------------------------|---------------------------------------------\n`assertLen(a, n)` | `AssertThat(a).HasSize(n)`\n`assertEmpty(a)` | `AssertThat(a).IsEmpty()`\n`assertNotEmpty(a)` | `AssertThat(a).IsNotEmpty()`\n\n#### Defining order\n\nThe `cf` parameter passed to `IsOrderedAccordingTo()` and\n`IsStrictlyOrderedAccordingTo()` should be a callable that follows the contract\nof `cmp(x, y)`: it should return negative if x < y, zero if x == y,\nand positive if x > y.\n\n*Ordered* means that the iterable's elements must increase (or decrease,\ndepending on `cf`) from beginning to end. Adjacent elements are allowed to be\nequal. *Strictly ordered* means that in addition, the elements must be unique\n(*i.e.*, monotonically increasing or decreasing).\n\n`IsOrdered()` is equivalent to `IsOrderedAccordingTo(cmp)`.\n\n`IsStrictlyOrdered()` is equivalent to `IsStrictlyOrderedAccordingTo(cmp)`.\n\n#### Asserting order\n\nBy default, `ContainsAll...` and `ContainsExactly...` do not enforce that the\norder of the elements in the subject under test matches the that of the expected\nvalue. To do that, append `InOrder()` to the returned predicate.\n\nContainment assertion | Result\n-----------------------------------------------------------|---------\n`AssertThat([2, 4, 6]).ContainsAllOf(6, 2)` | succeeds\n`AssertThat([2, 4, 6]).ContainsAllOf(6, 2).InOrder()` | fails\n`AssertThat([2, 4, 6]).ContainsAllOf(2, 6).InOrder()` | succeeds\n`AssertThat([2, 4, 6]).ContainsExactly(2, 6, 4)` | succeeds\n`AssertThat([2, 4, 6]).ContainsExactly(2, 6, 4).InOrder()` | fails\n`AssertThat([2, 4, 6]).ContainsExactly(2, 4, 6).InOrder()` | succeeds\n\nWhen using `InOrder()`, ensure that both the subject under test and the expected\nvalue have a predictable order, otherwise the result is undefined. For example,\n`AssertThat(list_a).ContainsExactlyElementsIn(set_a).InOrder()`\nmay or may not succeed, depending on how the `set` implements ordering.\n\n### Dictionaries, in addition to the table above\nunittest | PyTruth\n-----------------------------------|------------------------------------------------\n`assertIn(k, d)` | `AssertThat(d).ContainsKey(k)`\n`assertNotIn(k, d)` | `AssertThat(d).DoesNotContainKey(k)`\n`assertIn((k, v), d.items())` | `AssertThat(d).ContainsItem(k, v)`\n`assertNotIn((k, v), d.items())` | `AssertThat(d).DoesNotContainItem(k, v)`\n`assertEqual(d, {k1: v1, k2: v2})` | `AssertThat(d).ContainsExactly(k1, v1, k2, v2)`\n`assertEqual(d1, d2)` | `AssertThat(d1).ContainsExactlyItemsIn(d2)`\n`assertDictContainsSubset(d1, d2)` | `AssertThat(d1.items()).ContainsAllIn(d2.items())`\n\n### Exceptions\nunittest | PyTruth\n----------------------------------------|-------------------------------------------------\n`with assertRaises(e):` | `with AssertThat(e).IsRaised():`\n`with assertRaisesRegex(e, r):` | `with AssertThat(e).IsRaised(matching=r):`\nN/A | `with AssertThat(e).IsRaised(containing='a'):`\n`assertEqual(e.message, m)` | `AssertThat(e).HasMessage(m)`\n`assertTrue(e.message.startswith('a'))` | `AssertThat(e).HasMessageThat().StartsWith('a')`\n`assertIn(a, e.args)` | `AssertThat(e).HasArgsThat().Contains(a)`\n\n#### Matching raised exceptions\n\nWhen expecting an exception using the `AssertThat(e).IsRaised()` context, any\nexception raised whose type is equal to `e` or a subclass of `e` is accepted.\nIf an exception is raised that is not a subclass of `e`, the assertion fails.\n\nThe `e` parameter in the `AssertThat(e).IsRaised()` context may be either an\nexception *class* like `ValueError`, or it may be an exception *instance* like\n`ValueError('some error')`. If an instance is passed, then any exception raised\nby the code under test must also have matching `message` and `args` properties,\nin addition to being a subclass of the expected exception.\n\n### Mocked functions\nunittest | PyTruth\n----------------------------------------------------|-------------------------------------------------\n`m.assert_called()` | `AssertThat(m).WasCalled()`\n`m.assert_not_called()` | `AssertThat(m).WasNotCalled()`\n`m.assert_called_once()` | `AssertThat(m).WasCalled().Once()`\n`assertEqual(m.call_count, n)` | `AssertThat(m).WasCalled().Times(n)`\n`m.assert_called_with(*a, **k)` | `AssertThat(m).WasCalled().LastWith(*a, **k)`\n`m.assert_called_once_with(*a, **k)` | `AssertThat(m).WasCalled().Once().With(*a, **k)`\nN/A | `AssertThat(m).WasCalled().With(*a, **k).Once()`\n`m.assert_has_calls(calls,` `any_order=True)` | `AssertThat(m).HasCalls(calls)`\n`m.assert_has_calls(calls,` `any_order=False)` | `AssertThat(m).HasCalls(calls).InOrder()`\nN/A | `AssertThat(m).HasExactlyCalls(c1, c2)`\nN/A | `AssertThat(m).HasExactlyCalls(c1, c2).InOrder()`\n`m.assert_any_call(*a, **k)` | `AssertThat(m).WasCalled().With(*a, **k)`\n\n#### Being called once, with arguments\n\nThe `WasCalled().Once().With(...)` and `WasCalled().With(...).Once()` assertions\nare subtly different. `WasCalled().Once().With(...)` asserts that the function\nwas called one time ever, and that one time it was called, it was passed those\narguments. `WasCalled().With(...).Once()` asserts that the function was passed\nthose arguments exactly once, but it is permitted to have been called with\nother, irrelevant arguments. Thus, `WasCalled().Once().With(...)` is the\nstricter assertion. Consider using `HasExactlyCalls()` for more clarity.\n\n### Classes\nunittest | PyTruth\n------------------------------|--------------------------------\n`assertTrue(a.issubclass(b))` | `AssertThat(a).IsSubclassOf(b)`\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/google/pytruth", "keywords": "", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "pytruth", "package_url": "https://pypi.org/project/pytruth/", "platform": "", "project_url": "https://pypi.org/project/pytruth/", "project_urls": { "Bug Reports": "https://groups.google.com/d/forum/pytruth-users", "Homepage": "https://github.com/google/pytruth", "Source": "https://github.com/google/pytruth" }, "release_url": "https://pypi.org/project/pytruth/1.0.0/", "requires_dist": [ "wheel", "six" ], "requires_python": "", "summary": "Provides unittest assertions in a fluent style.", "version": "1.0.0" }, "last_serial": 5326739, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "feb0f783935683769c8abcab7d3dc44a", "sha256": "950796fca2fe489bca628a42134530154efe81ac20ad131074d9bcb1bc00df2a" }, "downloads": -1, "filename": "pytruth-1.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "feb0f783935683769c8abcab7d3dc44a", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 43884, "upload_time": "2019-05-26T12:07:57", "url": "https://files.pythonhosted.org/packages/fd/da/2c730b85830be057af77adc768fc336dd03d70628ed072bfd92b1f15a0af/pytruth-1.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2470e4f24a5d899d3d34ec18af4548d9", "sha256": "2e73257a24c69fe15aeed06164fee9e21ae525c9b2b3b4c5b54c23d81709c7f1" }, "downloads": -1, "filename": "pytruth-1.0.0.tar.gz", "has_sig": false, "md5_digest": "2470e4f24a5d899d3d34ec18af4548d9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 45677, "upload_time": "2019-05-26T12:08:00", "url": "https://files.pythonhosted.org/packages/d8/28/98b7a1457cbeaa317ae4195bf6e09c42c3d640685a4b14e9b751c16cef9e/pytruth-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "feb0f783935683769c8abcab7d3dc44a", "sha256": "950796fca2fe489bca628a42134530154efe81ac20ad131074d9bcb1bc00df2a" }, "downloads": -1, "filename": "pytruth-1.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "feb0f783935683769c8abcab7d3dc44a", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 43884, "upload_time": "2019-05-26T12:07:57", "url": "https://files.pythonhosted.org/packages/fd/da/2c730b85830be057af77adc768fc336dd03d70628ed072bfd92b1f15a0af/pytruth-1.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2470e4f24a5d899d3d34ec18af4548d9", "sha256": "2e73257a24c69fe15aeed06164fee9e21ae525c9b2b3b4c5b54c23d81709c7f1" }, "downloads": -1, "filename": "pytruth-1.0.0.tar.gz", "has_sig": false, "md5_digest": "2470e4f24a5d899d3d34ec18af4548d9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 45677, "upload_time": "2019-05-26T12:08:00", "url": "https://files.pythonhosted.org/packages/d8/28/98b7a1457cbeaa317ae4195bf6e09c42c3d640685a4b14e9b751c16cef9e/pytruth-1.0.0.tar.gz" } ] }