|
1 |
| -It gives basic examples on how to write unit tests in external projects which depend on PyFlink. |
| 1 | +It gives a basic example on how to write unit tests in an external project which depends on PyFlink. |
| 2 | + |
| 3 | +You could execute the unit tests according to the following steps: |
| 4 | +- Create a Python virtual environment and install PyFlink |
| 5 | +```shell |
| 6 | +cd testing |
| 7 | +python3 -m venv .venv |
| 8 | +source .venv/bin/activate |
| 9 | +pip install . |
| 10 | +``` |
| 11 | + |
| 12 | +- Check that PyFlink is installed successfully |
| 13 | +```shell |
| 14 | +python -c "import pyflink;import os;print(os.path.dirname(os.path.abspath(pyflink.__file__))+'/log')" |
| 15 | +``` |
| 16 | + |
| 17 | +It will print something like the following: |
| 18 | +```shell |
| 19 | +/Users/dianfu/code/src/github/pyflink-faq/testing/.venv/lib/python3.8/site-packages/pyflink/log |
| 20 | +``` |
| 21 | + |
| 22 | +Execute the following command: |
| 23 | +```shell |
| 24 | +ls -lh /Users/dianfu/code/src/github/pyflink-faq/testing/.venv/lib/python3.8/site-packages/pyflink/ |
| 25 | +``` |
| 26 | + |
| 27 | +The structure should be as following: |
| 28 | +``` |
| 29 | +total 136 |
| 30 | +-rw-r--r-- 1 dianfu staff 1.3K Apr 25 09:26 README.txt |
| 31 | +-rw-r--r-- 1 dianfu staff 1.9K Apr 25 09:26 __init__.py |
| 32 | +drwxr-xr-x 11 dianfu staff 352B Apr 25 09:26 __pycache__ |
| 33 | +drwxr-xr-x 25 dianfu staff 800B Apr 25 09:26 bin |
| 34 | +drwxr-xr-x 21 dianfu staff 672B Apr 25 09:26 common |
| 35 | +drwxr-xr-x 13 dianfu staff 416B Apr 25 09:26 conf |
| 36 | +drwxr-xr-x 20 dianfu staff 640B Apr 25 09:26 datastream |
| 37 | +drwxr-xr-x 4 dianfu staff 128B Apr 25 09:26 examples |
| 38 | +-rw-r--r-- 1 dianfu staff 3.2K Apr 25 09:26 find_flink_home.py |
| 39 | +drwxr-xr-x 25 dianfu staff 800B Apr 25 09:26 fn_execution |
| 40 | +-rw-r--r-- 1 dianfu staff 9.1K Apr 25 09:26 gen_protos.py |
| 41 | +-rw-r--r-- 1 dianfu staff 7.6K Apr 25 09:26 java_gateway.py |
| 42 | +drwxr-xr-x 11 dianfu staff 352B Apr 25 09:26 lib |
| 43 | +drwxr-xr-x 28 dianfu staff 896B Apr 25 09:26 licenses |
| 44 | +drwxr-xr-x 4 dianfu staff 128B Apr 25 09:26 log |
| 45 | +drwxr-xr-x 5 dianfu staff 160B Apr 25 09:26 metrics |
| 46 | +drwxr-xr-x 4 dianfu staff 128B Apr 25 09:26 opt |
| 47 | +drwxr-xr-x 11 dianfu staff 352B Apr 25 09:26 plugins |
| 48 | +-rw-r--r-- 1 dianfu staff 1.3K Apr 25 09:26 pyflink_callback_server.py |
| 49 | +-rw-r--r-- 1 dianfu staff 12K Apr 25 09:26 pyflink_gateway_server.py |
| 50 | +-rw-r--r-- 1 dianfu staff 5.3K Apr 25 09:26 serializers.py |
| 51 | +-rw-r--r-- 1 dianfu staff 7.9K Apr 25 09:26 shell.py |
| 52 | +drwxr-xr-x 31 dianfu staff 992B Apr 25 09:26 table |
| 53 | +drwxr-xr-x 6 dianfu staff 192B Apr 25 09:26 util |
| 54 | +-rw-r--r-- 1 dianfu staff 1.1K Apr 25 09:26 version.py |
| 55 | +``` |
| 56 | +Please checks that the directory `lib`, `opt`, `plugins` should be available. |
| 57 | + |
| 58 | +- Execute command `python3 -m unittest test_table_api.TableTests.test_scalar_function` to run the unit test |
| 59 | + |
| 60 | +You will see the following output, which means that the test has run successfully: |
| 61 | +``` |
| 62 | +(.venv) (base) dianfu@B-7174MD6R-1908 testing % python3 -m unittest test_table_api.TableTests.test_scalar_function |
| 63 | +Using %s as FLINK_HOME... /Users/dianfu/code/src/github/pyflink-faq/testing/.venv/lib/python3.8/site-packages/pyflink |
| 64 | +Skipped download /Users/dianfu/code/src/github/pyflink-faq/testing/flink-python_2.11-1.14.4-tests.jar since it already exists. |
| 65 | +/Users/dianfu/miniconda3/lib/python3.8/subprocess.py:946: ResourceWarning: subprocess 71018 is still running |
| 66 | + _warn("subprocess %s is still running" % self.pid, |
| 67 | +ResourceWarning: Enable tracemalloc to get the object allocation traceback |
| 68 | +Downloading jar org.apache.flink:flink-table-planner_2.11:1.14.4:jar:tests |
| 69 | +/Users/dianfu/code/src/github/pyflink-faq/testing/.venv/lib/python3.8/site-packages/pyflink/table/table_environment.py:538: DeprecationWarning: Deprecated in 1.10. Use create_table instead. |
| 70 | + warnings.warn("Deprecated in 1.10. Use create_table instead.", DeprecationWarning) |
| 71 | +. |
| 72 | +---------------------------------------------------------------------- |
| 73 | +Ran 1 test in 32.746s |
| 74 | +
|
| 75 | +OK |
| 76 | +``` |
0 commit comments