Bintest
Bintest is a extension for unitest, it will provide a way to run a command and assert the output.
Installation
pip install bintest
Usage
- Create a file in your project: testcase.py for example
from bintest import bintest
import unittest
class MyTestCase(unittest.TestCase, bintest.BinTest):
__test__ = True
def setUp(self):
self.set_env(
env="./output", # temp dir
input="./tests_case.yml", # yml file
)
# This works
def test_simple_cat(self):
output, err = self.run_bin(name="SimpleCAT")
# two ways of test, this both will do exactly the same
self.assertEqual(output, "test\n")
# this one is more auto because is reading from the yml
self.assertOutput(name="SimpleCAT", output=output)
# This Fails
def test_simple_cat_fail(self):
output, err = self.run_bin(name="SimpleCATFail")
# this one will fail
self.assertOutput(name="SimpleCATFail", output=output)
if __name__ == "__main__":
unittest.main()
- Create the config file: tests_case.yml
---
# Example test file
# required: bin, output
# everything in the middle will be passing as paramters to the binary: only the values
SimpleCAT:
bin: /bin/cat
path: /Users/artur.gomes/projects/pybintest/examples/test.txt
output: "test\n"
SimpleCATFail:
bin: /bin/cat
path: /Users/artur.gomes/projects/pybintest/examples/test.txt
output: "not test\n"
In this case we are testing the cat command, using a file test.txt as argument and expecting the output
- Create the test.txt file
test
- Then run:
python3 -m unittest discover -vvv
- Unittest will find yout test and run it for you.
test_simple_cat (testcase.MyTestCase) ... ok
test_simple_cat_fail (testcase.MyTestCase) ... FAIL
======================================================================
FAIL: test_simple_cat_fail (testcase.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/artur.gomes/projects/test_bintest/testcase.py", line 26, in test_simple_cat_fail
self.assertOutput(name="SimpleCATFail", output=output)
File "/Users/artur.gomes/Library/Caches/pypoetry/virtualenvs/test-bintest-LukI1uz2-py3.9/lib/python3.9/site-packages/bintest/bintest.py", line 34, in assertOutput
raise self.failureException(msg)
AssertionError: Error: not test
!= test
----------------------------------------------------------------------
Ran 2 tests in 0.011s
FAILED (failures=1)
Contribution
If this helps you consider help me to improve.
Metadata
Release files for bintest 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bintest-0.3.0.tar.gz | 3.2 kB | Without provenance | Details for bintest-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bintest-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for bintest-0.3.0-py3-none-any.whl |
Total release size: 6.1 kB
Release files / bintest-0.3.0.tar.gz
| Download URL | bintest-0.3.0.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07b1b5c43e9b9087b29a5e0c14dfa68775a82c0cb7c5c843470bd2c95a080012
|
|
BLAKE2b-256 checksum How to use checksums |
3e40e8bc50f28f28ad2da25addcb3a0510ae08373229e7745bf2a636911bb8c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.9.12 Darwin/21.3.0
|
Release files / bintest-0.3.0-py3-none-any.whl
| Download URL | bintest-0.3.0-py3-none-any.whl |
|---|---|
| Size | 2.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bfc86e861498ed18310fdf2e87b1f6bbceb52be47e9a5b7e85f57ab3c5f89a3c
|
|
BLAKE2b-256 checksum How to use checksums |
7a2d39d7e7b0cc8a9a80d367fb27e23460aec9fd09fe6fab031393686a662728
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.9.12 Darwin/21.3.0
|
Security for bintest 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.