瀏覽代碼

added pipenv env and unit tests

Shiro 2 年之前
父節點
當前提交
fe5885cdc0
共有 7 個文件被更改,包括 131 次插入14 次删除
  1. 26 0
      .gitignore
  2. 17 0
      Pipfile
  3. 6 2
      setup.py
  4. 8 7
      src/taipy/__init__.py
  5. 7 5
      src/taipy/_run.py
  6. 12 0
      tests/__init__.py
  7. 55 0
      tests/test_run.py

+ 26 - 0
.gitignore

@@ -1,3 +1,29 @@
 .idea
 .venv
 __pycache__
+
+# Distribution / packaging
+Pipfile.lock
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# IDE settings
+.vscode/
+.idea/
+.idea/taipy.iml
+.DS_Store

+ 17 - 0
Pipfile

@@ -0,0 +1,17 @@
+[[source]]
+url = "https://pypi.org/simple"
+verify_ssl = true
+name = "pypi"
+
+[packages]
+taipy-gui = {git = "https://git@github.com/Avaiga/taipy-gui.git@develop"}
+taipy-rest = {git = "https://git@github.com/Avaiga/taipy-rest.git@develop"}
+
+[dev-packages]
+pytest = "*"
+
+[requires]
+python_version >= "3.8"
+
+[pipenv]
+allow_prereleases = true

+ 6 - 2
setup.py

@@ -13,7 +13,7 @@
 
 """The setup script."""
 
-from setuptools import find_packages, setup
+from setuptools import find_packages, find_namespace_packages, setup
 
 with open("README.md") as readme_file:
     readme = readme_file.read()
@@ -23,6 +23,8 @@ requirements = [
     "taipy-rest@git+https://git@github.com/Avaiga/taipy-rest.git@develop",
 ]
 
+test_requirements = ["pytest>=3.8"]
+
 extras_require = {
     "ngrok": ["pyngrok>=5"],
     "image": ["python-magic;platform_system!='Windows'", "python-magic-bin;platform_system=='Windows'"],
@@ -51,7 +53,9 @@ setup(
     long_description_content_type="text/markdown",
     keywords="taipy",
     name="taipy",
-    packages=find_packages(include=['taipy']),
+    package_dir={"": "src"},
+    packages=find_namespace_packages(where="src") + find_packages(include=["taipy"]),
+    test_suite="tests",
     url="https://github.com/avaiga/taipy",
     version="1.2.0.dev",
     zip_safe=False,

+ 8 - 7
taipy/__init__.py → src/taipy/__init__.py

@@ -11,24 +11,25 @@
 
 from importlib.util import find_spec
 
-if find_spec('taipy'):
-    if find_spec('taipy.config'):
+if find_spec("taipy"):
+
+    if find_spec("taipy.config"):
         from taipy.config import *
         from taipy.logger import *
 
-    if find_spec('taipy.core'):
+    if find_spec("taipy.core"):
         from taipy.core import *
 
-    if find_spec('taipy.gui'):
+    if find_spec("taipy.gui"):
         from taipy.gui import Gui
 
-        if find_spec('taipy.enterprise') and find_spec('taipy.enterprise.gui'):
+        if find_spec("taipy.enterprise") and find_spec("taipy.enterprise.gui"):
             from taipy.enterprise.gui import _init_gui_enterprise
 
             _init_gui_enterprise(Gui)
 
-    if find_spec('taipy.rest'):
+    if find_spec("taipy.rest"):
         from taipy.rest import Rest
 
-    if find_spec('taipy._run'):
+    if find_spec("taipy._run"):
         from taipy._run import _run as run

+ 7 - 5
taipy/_run.py → src/taipy/_run.py

@@ -11,18 +11,18 @@
 
 import typing as t
 
-from .gui import Gui
-from .rest import Rest
-from .core import Core
+from . import Gui
+from . import Rest
+from . import Core
 
 
-def _run(*apps: t.List[t.Union[Gui, Rest]], **kwargs) -> t.Optional[t.Union[Gui, Rest]]:
+def _run(*apps: t.List[t.Union[Gui, Rest, Core]], **kwargs) -> t.Optional[t.Union[Gui, Rest, Core]]:
     """Run one or multiple Taipy services.
 
     A Taipy service is an instance of a class that runs code as a Web application.
 
     Parameters:
-        *args (List[Union[`Gui^`, `Rest^`]]): Services to run. If several services are provided, all the services run simultaneously. If this is empty or set to None, this method does nothing.
+        *args (List[Union[`Gui^`, `Rest^`, `Core^`]]): Services to run. If several services are provided, all the services run simultaneously. If this is empty or set to None, this method does nothing.
         **kwargs: Other parameters to provide to the services.
     """
     gui = __typing_get(apps, Gui)
@@ -30,6 +30,8 @@ def _run(*apps: t.List[t.Union[Gui, Rest]], **kwargs) -> t.Optional[t.Union[Gui,
     core = __typing_get(apps, Core)
 
     if rest or core:
+        if not core:
+            core = Core()
         core.run()
 
     if not rest and not gui:

+ 12 - 0
tests/__init__.py

@@ -0,0 +1,12 @@
+# Copyright 2022 Avaiga Private Limited
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations under the License.
+
+"""Unit test package for taipy."""

+ 55 - 0
tests/test_run.py

@@ -0,0 +1,55 @@
+# Copyright 2022 Avaiga Private Limited
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations under the License.
+
+from unittest import mock
+
+from src.taipy._run import _run
+from taipy.gui import Gui
+from taipy.rest import Rest
+from taipy.core import Core
+
+
+@mock.patch("taipy.gui.Gui.run")
+def test_run_pass_with_gui(gui_run):
+    _run(Gui())
+    gui_run.assert_called_once()
+
+
+@mock.patch("taipy.core.Core.run")
+def test_run_pass_with_core(core_run):
+    _run(Core())
+    core_run.assert_called_once()
+
+
+@mock.patch("taipy.rest.Rest.run")
+@mock.patch("taipy.core.Core.run")
+def test_run_pass_with_rest(rest_run, core_run):
+    _run(Rest())
+    rest_run.assert_called_once()
+    core_run.assert_called_once()
+
+
+@mock.patch("taipy.rest.Rest.run")
+@mock.patch("taipy.core.Core.run")
+def test_run_pass_with_core_and_rest(core_run, rest_run):
+    _run(Core(), Rest())
+    core_run.assert_called_once()
+    rest_run.assert_called_once()
+
+
+@mock.patch("taipy.gui.Gui.run")
+@mock.patch("taipy.rest.Rest.run")
+@mock.patch("taipy.core.Core.run")
+def test_run_pass_with_gui_and_rest(core_run, rest_run, gui_run):
+    _run(Gui(), Rest())
+    gui_run.assert_called_once()
+    core_run.assert_called_once()
+    rest_run.assert_not_called()