Skip to content

Commit c6710c2

Browse files
committed
Satisfy testing on macOS
1 parent 80295e9 commit c6710c2

File tree

9 files changed

+196
-86
lines changed

9 files changed

+196
-86
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 61 deletions
This file was deleted.

.github/workflows/nightly.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Nightly
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 2 * * *'
7+
8+
9+
jobs:
10+
nightly:
11+
name: "Python: ${{ matrix.python-version }}
12+
SQLA: ${{ matrix.sqla-version }}
13+
CrateDB: ${{ matrix.cratedb-version }}
14+
on ${{ matrix.os }}"
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
os: [ubuntu-latest]
19+
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
20+
cratedb-version: ['nightly']
21+
sqla-version: ['1.1.18', '1.2.19', '1.3.23']
22+
fail-fast: false
23+
24+
steps:
25+
- uses: actions/checkout@master
26+
- name: Set up Python ${{ matrix.python-version }}
27+
uses: actions/setup-python@v2
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
31+
- name: Install dependencies
32+
run: |
33+
./devtools/setup_ci.sh --cratedb-version=${{ matrix.cratedb-version }} --sqlalchemy-version=${{ matrix.sqla-version }}
34+
35+
- name: Invoke tests
36+
run: |
37+
bin/flake8
38+
bin/coverage run bin/test -vv1

.github/workflows/tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
workflow_dispatch:
9+
10+
11+
jobs:
12+
test:
13+
name: "Python: ${{ matrix.python-version }}
14+
SQLA: ${{ matrix.sqla-version }}
15+
CrateDB: ${{ matrix.cratedb-version }}
16+
on ${{ matrix.os }}"
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
os: [ubuntu-latest, macos-latest]
21+
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
22+
cratedb-version: ['4.5.0']
23+
sqla-version: ['1.1.18', '1.2.19', '1.3.23']
24+
fail-fast: false
25+
26+
steps:
27+
- uses: actions/checkout@master
28+
- name: Set up Python ${{ matrix.python-version }}
29+
uses: actions/setup-python@v2
30+
with:
31+
python-version: ${{ matrix.python-version }}
32+
33+
- name: Adjust environment for macOS
34+
if: matrix.os == 'macos-latest'
35+
run: |
36+
brew install gnu-getopt
37+
echo "/usr/local/opt/gnu-getopt/bin" >> $GITHUB_PATH
38+
39+
- name: Install dependencies
40+
run: |
41+
./devtools/setup_ci.sh --cratedb-version=${{ matrix.cratedb-version }} --sqlalchemy-version=${{ matrix.sqla-version }}
42+
43+
- name: Invoke tests
44+
run: |
45+
bin/flake8
46+
bin/coverage run bin/test -vv1

base.cfg

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,21 @@ eggs = crate
1919
recipe = zc.recipe.egg
2020
eggs = createcoverage
2121

22-
[crate]
22+
[crate:linux]
2323
recipe = hexagonit.recipe.download
2424
url = https://cdn.crate.io/downloads/releases/crate-${versions:crate_server}.tar.gz
2525
strip-top-level-dir = true
2626

27+
[crate:macosx]
28+
recipe = hexagonit.recipe.download
29+
url = https://cdn.crate.io/downloads/releases/cratedb/x64_mac/crate-${versions:crate_server}.tar.gz
30+
strip-top-level-dir = true
31+
32+
[crate:windows]
33+
recipe = hexagonit.recipe.download
34+
url = https://cdn.crate.io/downloads/releases/cratedb/x64_windows/crate-${versions:crate_server}.zip
35+
strip-top-level-dir = true
36+
2737
[test]
2838
relative-paths = true
2939
recipe = zc.recipe.testrunner

devtools/setup_ci.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
function args() {
6+
options=$(getopt --long cratedb-version: --long sqlalchemy-version: -- "$@")
7+
[ $? -eq 0 ] || {
8+
echo "Incorrect options provided"
9+
exit 1
10+
}
11+
eval set -- "$options"
12+
while true; do
13+
case "$1" in
14+
--cratedb-version)
15+
shift;
16+
cratedb_version=$1
17+
;;
18+
--sqlalchemy-version)
19+
shift;
20+
sqlalchemy_version=$1
21+
;;
22+
--)
23+
shift
24+
break
25+
;;
26+
esac
27+
shift
28+
done
29+
}
30+
31+
function main() {
32+
33+
# Read command line arguments.
34+
args $0 "$@"
35+
36+
# Sanity checks.
37+
[ -z ${cratedb_version} ] && {
38+
echo "--cratedb-version must be given"
39+
exit 1
40+
}
41+
[ -z ${sqlalchemy_version} ] && {
42+
echo "--sqlalchemy-version must be given"
43+
exit 1
44+
}
45+
46+
# Let's go.
47+
echo "Invoking tests with CrateDB ${cratedb_version} and SQLAlchemy ${sqlalchemy_version}"
48+
49+
python -m pip install --upgrade pip
50+
51+
# Workaround needed for Python 3.5
52+
python -m pip install --upgrade "setuptools>=31,<51"
53+
54+
pip install zc.buildout==2.13.4
55+
56+
# Replace SQLAlchemy version.
57+
sed -ir "s/SQLAlchemy.*/SQLAlchemy = ${sqlalchemy_version}/g" versions.cfg
58+
59+
# Replace CrateDB version.
60+
if [ ${cratedb_version} = "nightly" ]; then
61+
sed -ir "s/releases/releases\/nightly/g" base.cfg
62+
sed -ir "s/crate_server.*/crate_server = latest/g" versions.cfg
63+
else
64+
sed -ir "s/crate_server.*/crate_server = ${cratedb_version}/g" versions.cfg
65+
fi
66+
67+
buildout -n -c base.cfg
68+
69+
}
70+
71+
main "$@"

src/crate/testing/doctests/layer.txt

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -225,26 +225,9 @@ We might have to wait a moment before the cluster is finally created::
225225
From Uri
226226
--------
227227

228-
The CrateLayer can also be created by providing a URI that points to a Crate
228+
The CrateLayer can also be created by providing a URI that points to a CrateDB
229229
tarball::
230230

231-
>>> import urllib.request
232-
>>> import json
233-
>>> with urllib.request.urlopen('http://crate.io/versions.json') as response:
234-
... versions = json.loads(response.read().decode())
235-
... version = versions['crate_testing']
236-
237-
>>> uri = 'https://cdn.crate.io/downloads/releases/crate-{}.tar.gz'.format(version)
238-
>>> tmpdir = tempfile.mkdtemp()
239-
>>> layer = CrateLayer.from_uri(
240-
... uri, name='crate-uri', http_port=42203, directory=tmpdir)
241-
>>> layer.setUp()
242-
243-
>>> work_dir = os.path.join(tmpdir, 'crate-' + version)
244-
>>> os.path.exists(work_dir)
245-
True
246-
247-
>>> layer.tearDown()
248-
249-
>>> os.path.exists(work_dir)
250-
False
231+
uri = 'https://cdn.crate.io/downloads/releases/crate-{}.tar.gz'.format(version)
232+
layer = CrateLayer.from_uri(
233+
uri, name='crate-uri', http_port=42203, directory=tmpdir)

src/crate/testing/layer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def prepend_http(host):
7272

7373

7474
def _download_and_extract(uri, directory):
75+
sys.stderr.write("\nINFO: Downloading CrateDB archive from {} into {}".format(uri, directory))
76+
sys.stderr.flush()
7577
with io.BytesIO(urlopen(uri).read()) as tmpfile:
7678
with tarfile.open(fileobj=tmpfile) as t:
7779
t.extractall(directory)
@@ -160,7 +162,8 @@ def from_uri(uri,
160162
crate_home = os.path.join(directory, crate_dir)
161163

162164
if os.path.exists(crate_home):
163-
sys.stderr.write('Not extracting Crate tarball because folder already exists')
165+
sys.stderr.write("\nWARNING: Not extracting Crate tarball because folder already exists")
166+
sys.stderr.flush()
164167
else:
165168
_download_and_extract(uri, directory)
166169

src/crate/testing/test_layer.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818
# However, if you have executed another commercial license agreement
1919
# with Crate these terms will supersede the license and you may use the
2020
# software solely pursuant to the terms of the relevant commercial agreement.
21-
21+
import json
2222
import os
2323
import tempfile
24+
import urllib
25+
from distutils.version import LooseVersion
2426
from unittest import TestCase, mock
2527
from io import BytesIO
28+
29+
import crate
2630
from .layer import CrateLayer, prepend_http, http_url_from_host_port, wait_for_http_url
2731

2832

@@ -58,6 +62,22 @@ def test_wait_for_http(self):
5862
addr = wait_for_http_url(log=log, timeout=1)
5963
self.assertEqual(None, addr)
6064

65+
@mock.patch.object(crate.testing.layer, "_download_and_extract", lambda uri, directory: None)
66+
def test_layer_from_uri(self):
67+
"""
68+
The CrateLayer can also be created by providing an URI that points to
69+
a CrateDB tarball.
70+
"""
71+
with urllib.request.urlopen("https://crate.io/versions.json") as response:
72+
versions = json.loads(response.read().decode())
73+
version = versions["crate_testing"]
74+
75+
self.assertGreaterEqual(LooseVersion(version), LooseVersion("4.5.0"))
76+
77+
uri = "https://cdn.crate.io/downloads/releases/crate-{}.tar.gz".format(version)
78+
layer = CrateLayer.from_uri(uri, name="crate-by-uri", http_port=42203)
79+
self.assertIsInstance(layer, CrateLayer)
80+
6181
@mock.patch.dict('os.environ', {}, clear=True)
6282
def test_java_home_env_not_set(self):
6383
with tempfile.TemporaryDirectory() as tmpdir:

versions.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
crate_server = 4.4.2
2+
crate_server = 4.5.0
33

44
flake8 = 3.7.9
55
mccabe = 0.6.1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy