|
3 | 3 | Contributions are welcome and are greatly appreciated! Every
|
4 | 4 | little bit helps, and credit will always be given.
|
5 | 5 |
|
6 |
| -## Table of Contents |
7 |
| - |
8 |
| -- [TOC](#table-of-contents) |
9 |
| -- [Types of Contributions](#types-of-contributions) |
10 |
| - - [Report Bugs](#report-bugs) |
11 |
| - - [Fix Bugs](#fix-bugs) |
12 |
| - - [Implement Features](#implement-features) |
13 |
| - - [Improve Documentation](#improve-documentation) |
14 |
| - - [Submit Feedback](#submit-feedback) |
15 |
| -- [Documentation](#documentation) |
16 |
| -- [Development and Testing](#development-and-testing) |
17 |
| - - [Setting up a development environment](#setting-up-a-development-environment) |
18 |
| - - [Pull requests guidelines](#pull-request-guidelines) |
19 |
| - - [Testing on Travis CI](#testing-on-travis-ci) |
20 |
| - - [Testing Locally](#testing-locally) |
21 |
| -- [Changing the Metadata Database](#changing-the-metadata-database) |
| 6 | +# Table of Contents |
| 7 | + * [TOC](#table-of-contents) |
| 8 | + * [Types of Contributions](#types-of-contributions) |
| 9 | + - [Report Bugs](#report-bugs) |
| 10 | + - [Fix Bugs](#fix-bugs) |
| 11 | + - [Implement Features](#implement-features) |
| 12 | + - [Improve Documentation](#improve-documentation) |
| 13 | + - [Submit Feedback](#submit-feedback) |
| 14 | + * [Documentation](#documentation) |
| 15 | + * [Development and Testing](#development-and-testing) |
| 16 | + - [Setting up a development environment](#setting-up-a-development-environment) |
| 17 | + - [Running unit tests](#running-unit-tests) |
| 18 | + * [Pull requests guidelines](#pull-request-guidelines) |
| 19 | + * [Changing the Metadata Database](#changing-the-metadata-database) |
22 | 20 |
|
23 | 21 | ## Types of Contributions
|
24 | 22 |
|
@@ -83,57 +81,110 @@ extras to build the full API reference.
|
83 | 81 |
|
84 | 82 | ## Development and Testing
|
85 | 83 |
|
86 |
| -### Set up a development env using Docker |
| 84 | +### Set up a development environment |
87 | 85 |
|
88 |
| -Go to your Airflow directory and start a new docker container. You can choose between Python 2 or 3, whatever you prefer. |
| 86 | +There are three ways to setup an Apache Airflow development environment. |
89 | 87 |
|
90 |
| -``` |
91 |
| -# Start docker in your Airflow directory |
92 |
| -docker run -t -i -v `pwd`:/airflow/ -w /airflow/ -e SLUGIFY_USES_TEXT_UNIDECODE=yes python:2 bash |
| 88 | +1. Using tools and libraries installed directly on your system. |
| 89 | + |
| 90 | + Install Python (2.7.x or 3.4.x), MySQL, and libxml by using system-level package |
| 91 | + managers like yum, apt-get for Linux, or Homebrew for Mac OS at first. Refer to the [base CI Dockerfile](https://github.com/apache/incubator-airflow-ci/blob/master/Dockerfile.base) for |
| 92 | + a comprehensive list of required packages. |
| 93 | + |
| 94 | + Then install python development requirements. It is usually best to work in a virtualenv: |
| 95 | + |
| 96 | + ```bash |
| 97 | + cd $AIRFLOW_HOME |
| 98 | + virtualenv env |
| 99 | + source env/bin/activate |
| 100 | + pip install -e .[devel] |
| 101 | + ``` |
| 102 | + |
| 103 | +2. Using a Docker container |
| 104 | + |
| 105 | + Go to your Airflow directory and start a new docker container. You can choose between Python 2 or 3, whatever you prefer. |
| 106 | + |
| 107 | + ``` |
| 108 | + # Start docker in your Airflow directory |
| 109 | + docker run -t -i -v `pwd`:/airflow/ -w /airflow/ -e SLUGIFY_USES_TEXT_UNIDECODE=yes python:2 bash |
| 110 | +
|
| 111 | + # Go to the Airflow directory |
| 112 | + cd /airflow/ |
| 113 | +
|
| 114 | + # Install Airflow with all the required dependencies, |
| 115 | + # including the devel which will provide the development tools |
| 116 | + pip install -e ".[hdfs,hive,druid,devel]" |
| 117 | +
|
| 118 | + # Init the database |
| 119 | + airflow initdb |
| 120 | +
|
| 121 | + nosetests -v tests/hooks/test_druid_hook.py |
| 122 | +
|
| 123 | + test_get_first_record (tests.hooks.test_druid_hook.TestDruidDbApiHook) ... ok |
| 124 | + test_get_records (tests.hooks.test_druid_hook.TestDruidDbApiHook) ... ok |
| 125 | + test_get_uri (tests.hooks.test_druid_hook.TestDruidDbApiHook) ... ok |
| 126 | + test_get_conn_url (tests.hooks.test_druid_hook.TestDruidHook) ... ok |
| 127 | + test_submit_gone_wrong (tests.hooks.test_druid_hook.TestDruidHook) ... ok |
| 128 | + test_submit_ok (tests.hooks.test_druid_hook.TestDruidHook) ... ok |
| 129 | + test_submit_timeout (tests.hooks.test_druid_hook.TestDruidHook) ... ok |
| 130 | + test_submit_unknown_response (tests.hooks.test_druid_hook.TestDruidHook) ... ok |
| 131 | +
|
| 132 | + ---------------------------------------------------------------------- |
| 133 | + Ran 8 tests in 3.036s |
| 134 | +
|
| 135 | + OK |
| 136 | + ``` |
| 137 | + |
| 138 | + The Airflow code is mounted inside of the Docker container, so if you change something using your favorite IDE, you can directly test is in the container. |
| 139 | + |
| 140 | +3. Using [Docker Compose](https://docs.docker.com/compose/) and Airflow's CI scripts. |
93 | 141 |
|
94 |
| -# Install Airflow with all the required dependencies, |
95 |
| -# including the devel which will provide the development tools |
96 |
| -pip install -e .[devel,druid,hdfs,hive] |
| 142 | + Start a docker container through Compose for development to avoid installing the packages directly on your system. The following will give you a shell inside a container, run all required service containers (MySQL, PostgresSQL, krb5 and so on) and install all the dependencies: |
97 | 143 |
|
98 |
| -# Init the database |
99 |
| -airflow initdb |
| 144 | + ```bash |
| 145 | + docker-compose -f scripts/ci/docker-compose.yml run airflow-testing bash |
| 146 | + # From the container |
| 147 | + pip install -e .[devel] |
| 148 | + # Run all the tests with python and mysql through tox |
| 149 | + tox -e py35-backend_mysql |
| 150 | + ``` |
100 | 151 |
|
101 |
| -nosetests -v tests/hooks/test_druid_hook.py |
| 152 | +### Running unit tests |
102 | 153 |
|
103 |
| - test_get_first_record (tests.hooks.test_druid_hook.TestDruidDbApiHook) ... ok |
104 |
| - test_get_records (tests.hooks.test_druid_hook.TestDruidDbApiHook) ... ok |
105 |
| - test_get_uri (tests.hooks.test_druid_hook.TestDruidDbApiHook) ... ok |
106 |
| - test_get_conn_url (tests.hooks.test_druid_hook.TestDruidHook) ... ok |
107 |
| - test_submit_gone_wrong (tests.hooks.test_druid_hook.TestDruidHook) ... ok |
108 |
| - test_submit_ok (tests.hooks.test_druid_hook.TestDruidHook) ... ok |
109 |
| - test_submit_timeout (tests.hooks.test_druid_hook.TestDruidHook) ... ok |
110 |
| - test_submit_unknown_response (tests.hooks.test_druid_hook.TestDruidHook) ... ok |
| 154 | +To run tests locally, once your unit test environment is setup (directly on your |
| 155 | +system or through our Docker setup) you should be able to simply run |
| 156 | +``./run_unit_tests.sh`` at will. |
111 | 157 |
|
112 |
| - ---------------------------------------------------------------------- |
113 |
| - Ran 8 tests in 3.036s |
| 158 | +For example, in order to just execute the "core" unit tests, run the following: |
114 | 159 |
|
115 |
| - OK |
| 160 | +``` |
| 161 | +./run_unit_tests.sh tests.core:CoreTest -s --logging-level=DEBUG |
116 | 162 | ```
|
117 | 163 |
|
118 |
| -The Airflow code is mounted inside of the Docker container, so if you change something using your favorite IDE, you can directly test is in the container. |
| 164 | +or a single test method: |
119 | 165 |
|
120 |
| -### Set up a development env using Virtualenv |
| 166 | +``` |
| 167 | +./run_unit_tests.sh tests.core:CoreTest.test_check_operators -s --logging-level=DEBUG |
| 168 | +``` |
121 | 169 |
|
122 |
| -Please install python(2.7.x or 3.4.x), mysql, and libxml by using system-level package |
123 |
| -managers like yum, apt-get for Linux, or homebrew for Mac OS at first. |
124 |
| -It is usually best to work in a virtualenv and tox. Install development requirements: |
| 170 | +To run the whole test suite with Docker Compose, do: |
125 | 171 |
|
126 | 172 | ```
|
127 |
| -cd $AIRFLOW_HOME |
128 |
| -virtualenv env |
129 |
| -source env/bin/activate |
130 |
| -pip install -e .[devel] |
131 |
| -tox |
| 173 | +# Install Docker Compose first, then this will run the tests |
| 174 | +docker-compose -f scripts/ci/docker-compose.yml run airflow-testing /app/scripts/ci/run-ci.sh |
132 | 175 | ```
|
133 | 176 |
|
| 177 | +Alternatively can also set up [Travis CI](https://travis-ci.org/) on your repo to automate this. |
| 178 | +It is free for open source projects. |
| 179 | + |
| 180 | +For more information on how to run a subset of the tests, take a look at the |
| 181 | +nosetests docs. |
| 182 | + |
| 183 | +See also the list of test classes and methods in `tests/core.py`. |
| 184 | + |
134 | 185 | Feel free to customize based on the extras available in [setup.py](./setup.py)
|
135 | 186 |
|
136 |
| -### Pull Request Guidelines |
| 187 | +## Pull Request Guidelines |
137 | 188 |
|
138 | 189 | Before you submit a pull request from your forked repo, check that it
|
139 | 190 | meets these guidelines:
|
@@ -213,64 +264,6 @@ More information:
|
213 | 264 | [travis-ci-open-source]: https://docs.travis-ci.com/user/open-source-on-travis-ci-com/
|
214 | 265 | [travis-ci-org-vs-com]: https://devops.stackexchange.com/a/4305/8830
|
215 | 266 |
|
216 |
| -### Testing locally |
217 |
| - |
218 |
| -#### TL;DR |
219 |
| - |
220 |
| -Tests can then be run with (see also the [Running unit tests](#running-unit-tests) section below): |
221 |
| - |
222 |
| -``` |
223 |
| -./run_unit_tests.sh |
224 |
| -``` |
225 |
| - |
226 |
| -Individual test files can be run with: |
227 |
| - |
228 |
| -``` |
229 |
| -nosetests [path to file] |
230 |
| -``` |
231 |
| - |
232 |
| -#### Running unit tests |
233 |
| - |
234 |
| -We *highly* recommend setting up [Travis CI](https://travis-ci.org/) on |
235 |
| -your repo to automate this. It is free for open source projects. If for |
236 |
| -some reason you cannot, you can use the steps below to run tests. |
237 |
| - |
238 |
| -Here are loose guidelines on how to get your environment to run the unit tests. |
239 |
| -We do understand that no one out there can run the full test suite since |
240 |
| -Airflow is meant to connect to virtually any external system and that you most |
241 |
| -likely have only a subset of these in your environment. You should run the |
242 |
| -CoreTests and tests related to things you touched in your PR. |
243 |
| - |
244 |
| -To set up a unit test environment, first take a look at `run_unit_tests.sh` and |
245 |
| -understand that your ``AIRFLOW_CONFIG`` points to an alternate config file |
246 |
| -while running the tests. You shouldn't have to alter this config file but |
247 |
| -you may if need be. |
248 |
| - |
249 |
| -From that point, you can actually export these same environment variables in |
250 |
| -your shell, start an Airflow webserver ``airflow webserver -d`` and go and |
251 |
| -configure your connection. Default connections that are used in the tests |
252 |
| -should already have been created, you just need to point them to the systems |
253 |
| -where you want your tests to run. |
254 |
| - |
255 |
| -Once your unit test environment is setup, you should be able to simply run |
256 |
| -``./run_unit_tests.sh`` at will. |
257 |
| - |
258 |
| -For example, in order to just execute the "core" unit tests, run the following: |
259 |
| - |
260 |
| -``` |
261 |
| -./run_unit_tests.sh tests.core:CoreTest -s --logging-level=DEBUG |
262 |
| -``` |
263 |
| - |
264 |
| -or a single test method: |
265 |
| - |
266 |
| -``` |
267 |
| -./run_unit_tests.sh tests.core:CoreTest.test_check_operators -s --logging-level=DEBUG |
268 |
| -``` |
269 |
| - |
270 |
| -For more information on how to run a subset of the tests, take a look at the |
271 |
| -nosetests docs. |
272 |
| - |
273 |
| -See also the list of test classes and methods in `tests/core.py`. |
274 | 267 |
|
275 | 268 | ### Changing the Metadata Database
|
276 | 269 |
|
|
0 commit comments