|
207 | 207 | "\n", |
208 | 208 | " err = httpx.Response(401, headers={'X-Plash-Error': 'from header'}, text='from body')\n", |
209 | 209 | " _get_client = lambda: _FakeClient(err)\n", |
210 | | - " test_fail(_mk_auth_req, args=('https://example.com',), contains='from header', exc=PlashError)\n", |
| 210 | + " with expect_fail(PlashError, 'from header'): _mk_auth_req('https://example.com')\n", |
211 | 211 | "\n", |
212 | 212 | " err = httpx.Response(422, text='from body')\n", |
213 | 213 | " _get_client = lambda: _FakeClient(err)\n", |
214 | | - " test_fail(_mk_auth_req, args=('https://example.com',), contains='from body', exc=PlashError)\n", |
| 214 | + " with expect_fail(PlashError, 'from body'): _mk_auth_req('https://example.com')\n", |
215 | 215 | "\n", |
216 | 216 | " err = httpx.Response(503)\n", |
217 | 217 | " _get_client = lambda: _FakeClient(err)\n", |
218 | | - " test_fail(_mk_auth_req, args=('https://example.com',), contains='HTTP 503', exc=PlashError)\n", |
| 218 | + " with expect_fail(PlashError, 'HTTP 503'): _mk_auth_req('https://example.com')\n", |
219 | 219 | "finally: _get_client = orig_get_client" |
220 | 220 | ] |
221 | 221 | }, |
|
395 | 395 | "# Lets test each failure case:\n", |
396 | 396 | "with TemporaryDirectory() as td:\n", |
397 | 397 | " td = Path(td)\n", |
398 | | - " test_fail(_validate_app, args=(td,), contains=\"main.py\")\n", |
| 398 | + " with expect_fail(Exception, \"main.py\"): _validate_app(td)\n", |
399 | 399 | " \n", |
400 | 400 | " # test failure case of deps in both main.py and requirements.txt\n", |
401 | 401 | " (td / \"requirements.txt\").write_text(\"\")\n", |
402 | 402 | " (td / \"main.py\").write_text(Path(\"../examples/inline_dependencies/main.py\").read_text())\n", |
403 | | - " test_fail(_validate_app, args=(td,), contains=\"not contain both\")" |
| 403 | + " with expect_fail(Exception, \"not contain both\"): _validate_app(td)" |
404 | 404 | ] |
405 | 405 | }, |
406 | 406 | { |
|
438 | 438 | "def deploy(\n", |
439 | 439 | " path:Path='.', # Path to project\n", |
440 | 440 | " name:str=None, # Overrides the .plash file in project root if provided\n", |
441 | | - " _force_data:bool=False): # Overwrite data/ directory during deployment\n", |
| 441 | + " _force_data:bool=False # Overwrite data/ directory during deployment\n", |
| 442 | + "):\n", |
442 | 443 | " \"\"\"\n", |
443 | 444 | " Deploys app to production. By default, this command erases all files in your app which are not in data/.\n", |
444 | 445 | " Then uploads all files and folders, except paths starting with `.` and except the local data/ directory.\n", |
|
478 | 479 | " try:\n", |
479 | 480 | " msg = \"Invalid name 'pla.sh': platform-owned domains under 'pla.sh' cannot be used as custom domains.\"\n", |
480 | 481 | " _get_client = lambda: _FakeClient(httpx.Response(422, text=msg))\n", |
481 | | - " test_fail(deploy, args=(td,), kwargs={'name': 'pla.sh'}, contains='platform-owned domains', exc=PlashError)\n", |
| 482 | + " with expect_fail(PlashError, 'platform-owned domains'): deploy(td, name='pla.sh')\n", |
482 | 483 | " finally: _get_client = orig_get_client" |
483 | 484 | ] |
484 | 485 | }, |
|
494 | 495 | "def _deploy(\n", |
495 | 496 | " path:Path='.', # Path to project\n", |
496 | 497 | " name:str=None, # Overrides the .plash file in project root if provided\n", |
497 | | - " force_data:bool=False): # Overwrite data/ directory during deployment\n", |
| 498 | + " force_data:bool=False # Overwrite data/ directory during deployment\n", |
| 499 | + "):\n", |
498 | 500 | " print('Initializing deployment...')\n", |
499 | 501 | " try: res = deploy(path=path, name=name, _force_data=force_data)\n", |
500 | 502 | " except PlashError as e: return str(e)\n", |
|
635 | 637 | "#| export\n", |
636 | 638 | "def delete_app(\n", |
637 | 639 | " path:Path='.', # Path to project\n", |
638 | | - " name:str=None): # Overrides the .plash file in project root if provided\n", |
| 640 | + " name:str=None # Overrides the .plash file in project root if provided\n", |
| 641 | + "):\n", |
639 | 642 | " 'Delete your deployed app'\n", |
640 | 643 | " name = _prep(path, name)\n", |
641 | 644 | " _mk_auth_req(_endpoint(rt=f\"/delete?name={name}\"), \"delete\")\n", |
642 | 645 | " return f\"App '{name}' deleted successfully\"\n", |
643 | 646 | "\n", |
644 | 647 | "@call_parse\n", |
645 | 648 | "@delegates(delete_app)\n", |
646 | | - "def _delete(force:bool=False, # Skip confirmation prompt\n", |
647 | | - " **kwargs):\n", |
| 649 | + "def _delete(\n", |
| 650 | + " force:bool=False, # Skip confirmation prompt\n", |
| 651 | + " **kwargs\n", |
| 652 | + "):\n", |
648 | 653 | " 'Delete your deployed app'\n", |
649 | 654 | " if not force:\n", |
650 | 655 | " confirm = input(\"Are you sure you want to delete the app? [y/N]: \")\n", |
|
720 | 725 | "#| export\n", |
721 | 726 | "def start_app(\n", |
722 | 727 | " path:Path='.', # Path to project\n", |
723 | | - " name:str=None): # Overrides the .plash file in project root if provided\n", |
| 728 | + " name:str=None # Overrides the .plash file in project root if provided\n", |
| 729 | + "):\n", |
724 | 730 | " 'Start your deployed app'\n", |
725 | 731 | " name = _prep(path, name)\n", |
726 | 732 | " _mk_auth_req(_endpoint(rt=f\"/start?name={name}\"))\n", |
|
790 | 796 | "#| export\n", |
791 | 797 | "def stop_app(\n", |
792 | 798 | " path:Path='.', # Path to project\n", |
793 | | - " name:str=None): # Overrides the .plash file in project root if provided\n", |
| 799 | + " name:str=None # Overrides the .plash file in project root if provided\n", |
| 800 | + "):\n", |
794 | 801 | " 'Stop your deployed app'\n", |
795 | 802 | " name = _prep(path, name)\n", |
796 | 803 | " _mk_auth_req(_endpoint(rt=f\"/stop?name={name}\"))\n", |
|
872 | 879 | "def logs(\n", |
873 | 880 | " path:Path='.', # Path to project\n", |
874 | 881 | " name:str=None, # Overrides the .plash file in project root if provided\n", |
875 | | - " mode:log_modes='build'): # Choose between build or app logs\n", |
| 882 | + " mode:log_modes='build' # Choose between build or app logs\n", |
| 883 | + "):\n", |
876 | 884 | " 'Get logs for your deployed app'\n", |
877 | 885 | " name = _prep(path, name)\n", |
878 | 886 | " r = _mk_auth_req(_endpoint(rt=f\"/logs?name={name}&mode={mode}\"))\n", |
879 | 887 | " return r.text\n", |
880 | 888 | "\n", |
881 | 889 | "@call_parse\n", |
882 | 890 | "@delegates(logs)\n", |
883 | | - "def _logs(tail:bool=False, # Tail the logs\n", |
884 | | - " **kwargs):\n", |
| 891 | + "def _logs(\n", |
| 892 | + " tail:bool=False, # Tail the logs\n", |
| 893 | + " **kwargs\n", |
| 894 | + "):\n", |
885 | 895 | " try:\n", |
886 | 896 | " if not tail: return print(logs(**kwargs))\n", |
887 | 897 | " text = ''\n", |
|
1013 | 1023 | "def download_app(\n", |
1014 | 1024 | " path:Path='.', # Path to project\n", |
1015 | 1025 | " name:str=None, # Overrides the .plash file in project root if provided\n", |
1016 | | - " save_path:Path=\"./download/\"): # Save path (optional)\n", |
| 1026 | + " save_path:Path=\"./download/\" # Save path (optional)\n", |
| 1027 | + "):\n", |
1017 | 1028 | " \"Download deployed app to save_path.\"\n", |
1018 | 1029 | " name = _prep(path, name)\n", |
1019 | 1030 | " save_path = Path(save_path)\n", |
|
0 commit comments