|
8 | 8 | import tempfile
|
9 | 9 | import pytest
|
10 | 10 | from unittest import TestCase
|
11 |
| -from os.path import dirname, join, basename |
| 11 | +from os.path import dirname, join, basename, abspath |
12 | 12 |
|
13 | 13 | from rsconnect.bundle import (
|
14 | 14 | _default_title,
|
|
28 | 28 | validate_entry_point,
|
29 | 29 | validate_extra_files,
|
30 | 30 | which_python,
|
| 31 | + guess_deploy_dir, |
| 32 | + Manifest, |
| 33 | + create_voila_manifest, |
31 | 34 | )
|
32 | 35 | import rsconnect.bundle
|
33 | 36 | from rsconnect.exception import RSConnectException
|
@@ -801,3 +804,214 @@ def test_is_not_executable(self):
|
801 | 804 | with tempfile.NamedTemporaryFile() as tmpfile:
|
802 | 805 | with self.assertRaises(RSConnectException):
|
803 | 806 | which_python(tmpfile.name)
|
| 807 | + |
| 808 | + |
| 809 | +cur_dir = os.path.dirname(__file__) |
| 810 | +bqplot_dir = os.path.join(cur_dir, "./testdata/voila/bqplot/") |
| 811 | +bqplot_ipynb = os.path.join(bqplot_dir, "bqplot.ipynb") |
| 812 | +multivoila_dir = os.path.join(cur_dir, "./testdata/voila/multi-voila/") |
| 813 | + |
| 814 | + |
| 815 | +class Test_guess_deploy_dir(TestCase): |
| 816 | + def test_guess_deploy_dir(self): |
| 817 | + with self.assertRaises(RSConnectException): |
| 818 | + guess_deploy_dir(None, None) |
| 819 | + with self.assertRaises(RSConnectException): |
| 820 | + guess_deploy_dir(None, bqplot_dir) |
| 821 | + with self.assertRaises(RSConnectException): |
| 822 | + guess_deploy_dir(bqplot_dir, bqplot_dir) |
| 823 | + self.assertEqual(abspath(bqplot_dir), guess_deploy_dir(bqplot_dir, None)) |
| 824 | + self.assertEqual(abspath(bqplot_dir), guess_deploy_dir(bqplot_ipynb, None)) |
| 825 | + self.assertEqual(abspath(bqplot_dir), guess_deploy_dir(bqplot_ipynb, bqplot_ipynb)) |
| 826 | + self.assertEqual(abspath(bqplot_dir), guess_deploy_dir(bqplot_dir, "bqplot.ipynb")) |
| 827 | + |
| 828 | + |
| 829 | +@pytest.mark.parametrize( |
| 830 | + ( |
| 831 | + "path", |
| 832 | + "entrypoint", |
| 833 | + ), |
| 834 | + [ |
| 835 | + ( |
| 836 | + None, |
| 837 | + None, |
| 838 | + ), |
| 839 | + ( |
| 840 | + None, |
| 841 | + bqplot_ipynb, |
| 842 | + ), |
| 843 | + ( |
| 844 | + bqplot_dir, |
| 845 | + bqplot_dir, |
| 846 | + ), |
| 847 | + ( |
| 848 | + bqplot_dir, |
| 849 | + None, |
| 850 | + ), |
| 851 | + ( |
| 852 | + bqplot_ipynb, |
| 853 | + None, |
| 854 | + ), |
| 855 | + ( |
| 856 | + bqplot_ipynb, |
| 857 | + bqplot_ipynb, |
| 858 | + ), |
| 859 | + ( |
| 860 | + bqplot_dir, |
| 861 | + bqplot_ipynb, |
| 862 | + ), |
| 863 | + ], |
| 864 | +) |
| 865 | +def test_create_voila_manifest(path, entrypoint): |
| 866 | + environment = Environment( |
| 867 | + conda=None, |
| 868 | + contents="bqplot\n", |
| 869 | + error=None, |
| 870 | + filename="requirements.txt", |
| 871 | + locale="en_US.UTF-8", |
| 872 | + package_manager="pip", |
| 873 | + pip="23.0", |
| 874 | + python="3.8.12", |
| 875 | + source="file", |
| 876 | + ) |
| 877 | + ans = { |
| 878 | + "version": 1, |
| 879 | + "locale": "en_US.UTF-8", |
| 880 | + "metadata": {"appmode": "jupyter-voila", "entrypoint": "bqplot.ipynb"}, |
| 881 | + "python": { |
| 882 | + "version": "3.8.12", |
| 883 | + "package_manager": {"name": "pip", "version": "23.0", "package_file": "requirements.txt"}, |
| 884 | + }, |
| 885 | + "files": { |
| 886 | + "requirements.txt": {"checksum": "9cce1aac313043abd5690f67f84338ed"}, |
| 887 | + "bqplot.ipynb": {"checksum": "79f8622228eded646a3038848de5ffd9"}, |
| 888 | + }, |
| 889 | + } |
| 890 | + manifest = Manifest() |
| 891 | + if (path, entrypoint) in ( |
| 892 | + (None, None), |
| 893 | + (None, bqplot_ipynb), |
| 894 | + (bqplot_dir, bqplot_dir), |
| 895 | + ): |
| 896 | + with pytest.raises(RSConnectException) as _: |
| 897 | + manifest = create_voila_manifest( |
| 898 | + path, |
| 899 | + entrypoint, |
| 900 | + environment, |
| 901 | + app_mode=AppModes.JUPYTER_VOILA, |
| 902 | + extra_files=None, |
| 903 | + excludes=None, |
| 904 | + force_generate=True, |
| 905 | + image=None, |
| 906 | + multi_notebook=False, |
| 907 | + ) |
| 908 | + else: |
| 909 | + manifest = create_voila_manifest( |
| 910 | + path, |
| 911 | + entrypoint, |
| 912 | + environment, |
| 913 | + app_mode=AppModes.JUPYTER_VOILA, |
| 914 | + extra_files=None, |
| 915 | + excludes=None, |
| 916 | + force_generate=True, |
| 917 | + image=None, |
| 918 | + multi_notebook=False, |
| 919 | + ) |
| 920 | + assert ans == json.loads(manifest.flattened_copy.json) |
| 921 | + |
| 922 | + |
| 923 | +@pytest.mark.parametrize( |
| 924 | + ( |
| 925 | + "path", |
| 926 | + "entrypoint", |
| 927 | + ), |
| 928 | + [ |
| 929 | + ( |
| 930 | + None, |
| 931 | + None, |
| 932 | + ), |
| 933 | + ( |
| 934 | + None, |
| 935 | + bqplot_ipynb, |
| 936 | + ), |
| 937 | + ( |
| 938 | + multivoila_dir, |
| 939 | + multivoila_dir, |
| 940 | + ), |
| 941 | + ( |
| 942 | + multivoila_dir, |
| 943 | + None, |
| 944 | + ), |
| 945 | + ( |
| 946 | + bqplot_ipynb, |
| 947 | + None, |
| 948 | + ), |
| 949 | + ( |
| 950 | + bqplot_ipynb, |
| 951 | + bqplot_ipynb, |
| 952 | + ), |
| 953 | + ( |
| 954 | + multivoila_dir, |
| 955 | + bqplot_ipynb, |
| 956 | + ), |
| 957 | + ], |
| 958 | +) |
| 959 | +def test_create_voila_manifest_multi_notebook(path, entrypoint): |
| 960 | + environment = Environment( |
| 961 | + conda=None, |
| 962 | + contents="bqplot\n", |
| 963 | + error=None, |
| 964 | + filename="requirements.txt", |
| 965 | + locale="en_US.UTF-8", |
| 966 | + package_manager="pip", |
| 967 | + pip="23.0", |
| 968 | + python="3.8.12", |
| 969 | + source="file", |
| 970 | + ) |
| 971 | + ans = { |
| 972 | + "version": 1, |
| 973 | + "locale": "en_US.UTF-8", |
| 974 | + "metadata": {"appmode": "jupyter-voila", "entrypoint": "multi-voila"}, |
| 975 | + "python": { |
| 976 | + "version": "3.8.12", |
| 977 | + "package_manager": {"name": "pip", "version": "23.0", "package_file": "requirements.txt"}, |
| 978 | + }, |
| 979 | + "files": { |
| 980 | + "requirements.txt": {"checksum": "9cce1aac313043abd5690f67f84338ed"}, |
| 981 | + "bqplot/bqplot.ipynb": {"checksum": "9f283b29889500e6c78e83ad1257e03f"}, |
| 982 | + "dashboard/dashboard.ipynb": {"checksum": "6b42a0730d61e5344a3e734f5bbeec25"}, |
| 983 | + }, |
| 984 | + } |
| 985 | + manifest = Manifest() |
| 986 | + if (path, entrypoint) in ( |
| 987 | + (None, None), |
| 988 | + (None, bqplot_ipynb), |
| 989 | + (multivoila_dir, multivoila_dir), |
| 990 | + (bqplot_ipynb, None), |
| 991 | + (bqplot_ipynb, bqplot_ipynb), |
| 992 | + ): |
| 993 | + with pytest.raises(RSConnectException) as _: |
| 994 | + manifest = create_voila_manifest( |
| 995 | + path, |
| 996 | + entrypoint, |
| 997 | + environment, |
| 998 | + app_mode=AppModes.JUPYTER_VOILA, |
| 999 | + extra_files=None, |
| 1000 | + excludes=None, |
| 1001 | + force_generate=True, |
| 1002 | + image=None, |
| 1003 | + multi_notebook=True, |
| 1004 | + ) |
| 1005 | + else: |
| 1006 | + manifest = create_voila_manifest( |
| 1007 | + path, |
| 1008 | + entrypoint, |
| 1009 | + environment, |
| 1010 | + app_mode=AppModes.JUPYTER_VOILA, |
| 1011 | + extra_files=None, |
| 1012 | + excludes=None, |
| 1013 | + force_generate=True, |
| 1014 | + image=None, |
| 1015 | + multi_notebook=True, |
| 1016 | + ) |
| 1017 | + assert ans == json.loads(manifest.flattened_copy.json) |
0 commit comments