{ "info": { "author": "Franck LOURME", "author_email": "flourme@scaleway.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: MacOS :: MacOS X", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Topic :: Software Development :: Testing" ], "description": "# Fakear\n\nA module that creates fake binaries from valid configuration ( a yaml file or a dict ) and launch them in the context of your Python script, without efforts.\n\n# Installation\n\n```\npip install fakear\n```\n\n# Quick Start\n\nThis is a mock of a fake `ls` command, that \n\n```yaml\nls:\n - args:\n - dexter\n return_code: 0\n output: Omelette du Fromage\n```\n\nOn Python, you can now use Fakear to fake ls behaviour and act according to our mock.\n\n```python\n>>> from subprocess import run\n>>> from fakear import Fakear\n>>> p = run([\"ls\", \"dexter\"])\nls: dexter: No such file or directory\n>>> p.returncode\n1\n>>> with Fakear(cfg=\"fake_ls.yaml\"):\n... fake_cmd = run([\"ls\", \"dexter\"])\nOmelette du Fromage\n>>> fake_cmd.returncode\n0\n```\n\nYou can use it as well in your unit test routine:\n\n```python\nfrom fakear import Fakear\nfrom subprocess import check_output\n\ndef test_faked_ls(self):\n with Fakear(cfg=\"fake_ls.yaml\"):\n proc = check_output([\"ls\", \"dexter\"])\n\n assert proc.decode() == \"Omelette du fromage\\n\"\n```\n\n# How does it works ?\n\nAn instance handles a specific configuration file, with scenarios for one or\nmultiple commands to fake.\n\nBy default, an instance is deactivated, meaning you can still configure it\nbefore the fake happens\n\nWhen activated:\n - The instance creates the folder that should contains the fake binaries (faked_path)\n - It builds shell scripts corresponding to all the scenarios\n - It ensures every scripts are runnable\n - It sets in os.environ[\"PATH\"] the faked_path at first place\n\nSo, as long as the instance is activated, you can run faked commands with subprocess module.\n\nWhen deactivated, the instance removes the faked_path from PATH and deletes the folder from the filesystem\n\n\n# Documentation\n\n## YAML Files\n\nEvery program mock should start with the program name as a key. Then you can describe multiple behaviours for a given set of arguments.\n\n```yaml\n__command_name__ :\n # Default output with no arguments\n - return_code: -1\n output: This is a fake program, please give the correct arguments\n # output with arguments\n - args:\n - first_arg\n - sec_arg\n return_code: 0\n output: This is an example of fake command\n # output_file with arguments\n - args:\n - first_arg\n - sec_arg\n return_code: 0\n output_file: semver.txt\n__command2_name__ :\n # Default behaviour of a program generated by Fakear\n```\n\nYou can use those options to customise your fake program:\n\n - **args (Optionna\u0326l)** : a list of positionnal arguments that invoke this fake output\n - **return_code** : the return code when the program exits\n - **output**: The raw data to output when you invoke the program with these args\n - **output_file**: The path of a file containing the output to show\n\nNotice that if you mention no args to your list in a subcommand, it overrides the default behaviour of your fake program.\n\nAlso, you have to set either **output** or **output_file** keys in the same subcommand.\nOtherwise, it should throw an error.\n\n\n## API\n\nYou can use Fakear in two ways:\n\n- as an instance:\n```py\n>>> fakear = Fakear(cfg=\"path_of_a_valid.yml\")\n>>> fakear.enable()\n# DO THINGS\n>>> fakear.disable()\n```\nA Fakear instance can be manually enabled or disabled with the correct methods\n\n- as a Context Manager (recommended):\n\n```python\nwith Fakear(cfg=\"fake_ls.yml\"):\n # DO THINGS\n```\nWith the context manager, enable et disable are handled automatically, and you can set the fake path at instanciation\n\n### Init variables\n```py\nFakear(cfg=\"/path/cfg.yaml\", raw=cfg_data, path=\"/tmp/bin\")\n```\n\n- cfg: Path of the config file to use\n- raw: Python dict\n- path: Path for fake binaries\n\nYou can use either cfg or raw but not both of them, as it should overlap scenarios of the same command and create undefined behaviour.\n\n### Available Methods\n\n- enable() : Activate the instance\n- deactivate() : Deactivate the instance\n- set_path(path: str) : Sets a new path for faked commands. It must be absolute. You can't modify path when the instance is activated\n\n\n# Contribute\n\nFeel free to open an issue on this repository.\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "fakear", "package_url": "https://pypi.org/project/fakear/", "platform": "", "project_url": "https://pypi.org/project/fakear/", "project_urls": null, "release_url": "https://pypi.org/project/fakear/0.1.2/", "requires_dist": [ "pyyaml", "voluptuous" ], "requires_python": "", "summary": "A Shell-command faker for Python Unit Testing", "version": "0.1.2" }, "last_serial": 5203428, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "a233825a6bee203337f25c76f654cf7f", "sha256": "fdc615fd5b1489755df2464c0e5104b7d879657e70ee5e533c6d84c164956229" }, "downloads": -1, "filename": "fakear-0.1.1-py3.5.egg", "has_sig": false, "md5_digest": "a233825a6bee203337f25c76f654cf7f", "packagetype": "bdist_egg", "python_version": "3.5", "requires_python": null, "size": 18220, "upload_time": "2019-04-29T14:46:42", "url": "https://files.pythonhosted.org/packages/37/eb/e09f658592a365ca5c74c2767da5f1c61dd65ada8c377a9f23cde082ebde/fakear-0.1.1-py3.5.egg" }, { "comment_text": "", "digests": { "md5": "adf40fad55ac69b32a097fa2fd8c9877", "sha256": "c2bbf588967d10537b7549b2e0bcde1e3fd31fb3c0d5e57c0c400f7fcf22f7db" }, "downloads": -1, "filename": "fakear-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "adf40fad55ac69b32a097fa2fd8c9877", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9470, "upload_time": "2019-02-21T15:33:34", "url": "https://files.pythonhosted.org/packages/5a/9d/bdd12d3e97be412201b130b833b78e24aabbf30d164e7e4cbf21ae14a492/fakear-0.1.1-py3-none-any.whl" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "e01982b579525197f799cb1da190439f", "sha256": "58aef436bc2e2acc4470fb579f7e3064048cdafd5de2f1e48e71ba93c3cf1284" }, "downloads": -1, "filename": "fakear-0.1.2-py3.7.egg", "has_sig": false, "md5_digest": "e01982b579525197f799cb1da190439f", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 8579, "upload_time": "2019-04-29T14:46:46", "url": "https://files.pythonhosted.org/packages/ba/5b/06e3246afac45f58dc3f4d1173c574215433aeee810043c6a3d2af04f248/fakear-0.1.2-py3.7.egg" }, { "comment_text": "", "digests": { "md5": "15f459a6b61ee47a14a176ff6d1fe15c", "sha256": "e9b4e73dd5a93ebba46836124f0606b46ed2d4d54ab6df53f21f21d1b79e4070" }, "downloads": -1, "filename": "fakear-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "15f459a6b61ee47a14a176ff6d1fe15c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9664, "upload_time": "2019-04-29T14:46:36", "url": "https://files.pythonhosted.org/packages/99/55/bbb93c3bd0f826638dee915e1e7da7717109d1874c8651c8341530714b9c/fakear-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "89f2fc16d3c33a60ab49350f6e292f34", "sha256": "84305e83dae729667ee400871000c51220fe7e38fb2383960de51851d542061f" }, "downloads": -1, "filename": "fakear-0.1.2.tar.gz", "has_sig": false, "md5_digest": "89f2fc16d3c33a60ab49350f6e292f34", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7172, "upload_time": "2019-04-29T14:46:50", "url": "https://files.pythonhosted.org/packages/0c/88/86b6f0b744309510141ae6bc91c3df081617112fda178fe1341f3b477dd8/fakear-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e01982b579525197f799cb1da190439f", "sha256": "58aef436bc2e2acc4470fb579f7e3064048cdafd5de2f1e48e71ba93c3cf1284" }, "downloads": -1, "filename": "fakear-0.1.2-py3.7.egg", "has_sig": false, "md5_digest": "e01982b579525197f799cb1da190439f", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 8579, "upload_time": "2019-04-29T14:46:46", "url": "https://files.pythonhosted.org/packages/ba/5b/06e3246afac45f58dc3f4d1173c574215433aeee810043c6a3d2af04f248/fakear-0.1.2-py3.7.egg" }, { "comment_text": "", "digests": { "md5": "15f459a6b61ee47a14a176ff6d1fe15c", "sha256": "e9b4e73dd5a93ebba46836124f0606b46ed2d4d54ab6df53f21f21d1b79e4070" }, "downloads": -1, "filename": "fakear-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "15f459a6b61ee47a14a176ff6d1fe15c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9664, "upload_time": "2019-04-29T14:46:36", "url": "https://files.pythonhosted.org/packages/99/55/bbb93c3bd0f826638dee915e1e7da7717109d1874c8651c8341530714b9c/fakear-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "89f2fc16d3c33a60ab49350f6e292f34", "sha256": "84305e83dae729667ee400871000c51220fe7e38fb2383960de51851d542061f" }, "downloads": -1, "filename": "fakear-0.1.2.tar.gz", "has_sig": false, "md5_digest": "89f2fc16d3c33a60ab49350f6e292f34", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7172, "upload_time": "2019-04-29T14:46:50", "url": "https://files.pythonhosted.org/packages/0c/88/86b6f0b744309510141ae6bc91c3df081617112fda178fe1341f3b477dd8/fakear-0.1.2.tar.gz" } ] }