Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance: Improve CI/GHA, satisfy link checker, improve code style #351

Merged
merged 10 commits into from
Apr 12, 2022
9 changes: 7 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ on: push

jobs:
test:
name: Test python-${{ matrix.python-version }} on ${{ matrix.os }}
name: Python ${{ matrix.python-version }}, CrateDB ${{ matrix.cratedb-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, macos-latest, windows-2019]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that using windows-2019 instead of windows-2022, which happened to become windows-latest just recently, significantly improves runtime, so I also submitted crate/crate#12344.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^ Doesn't help on the CrateDB test suite. 😞

python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
cratedb-version: ['3.3.6', '4.7.1']
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
CRATEDB_VERSION: ${{ matrix.cratedb-version }}

steps:
- uses: actions/checkout@v2
Expand Down
8 changes: 6 additions & 2 deletions DEVELOP.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ Afterwards you can launch crash::
Running Tests
=============

The tests are run using the `unittest`_::
The tests are run using the `unittest`_ module::

$ venv/bin/python -m unittest -v

In order to adjust the CrateDB version used for running the tests, amend the
environment variable ``CRATEDB_VERSION`` like::

$ export CRATEDB_VERSION=4.8.0

If you install tox_, you can also run tests against multiple Python interpreters::

$ venv/bin/python -m pip install tox
$ venv/bin/tox

But this requires you to have the python interpreters available in ``$PATH``.
This requires you to have the python interpreters available in ``$PATH``.

To run against a single interpreter, you can also do::

Expand Down
3 changes: 1 addition & 2 deletions crate/crash/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from collections import namedtuple
from distutils.version import StrictVersion
from getpass import getpass
from logging import NullHandler
from operator import itemgetter

import urllib3
Expand All @@ -50,7 +49,7 @@
from .sysinfo import SysInfoCommand

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
logging.getLogger('crate').addHandler(NullHandler())
logging.getLogger('crate').addHandler(logging.NullHandler())

USER_DATA_DIR = user_data_dir("Crate", "Crate")
HISTORY_FILE_NAME = 'crash_history'
Expand Down
8 changes: 4 additions & 4 deletions crate/crash/tabulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _latex_line_begin_tabular(colwidths, colaligns, booktabs=False):
alignment = {"left": "l", "right": "r", "center": "c", "decimal": "r"}
tabular_columns_fmt = "".join([alignment.get(a, "l") for a in colaligns])
return "\n".join(["\\begin{tabular}{" + tabular_columns_fmt + "}",
"\\toprule" if booktabs else "\hline"])
"\\toprule" if booktabs else r"\hline"])


LATEX_ESCAPE_RULES = {r"&": r"\&", r"%": r"\%", r"$": r"\$", r"#": r"\#",
Expand Down Expand Up @@ -275,7 +275,7 @@ def escape_char(c):
_multiline_codes = re.compile(r"\r|\n|\r\n")
_multiline_codes_bytes = re.compile(b"\r|\n|\r\n")
_invisible_codes = re.compile(r"\x1b\[\d*m|\x1b\[\d*\;\d*\;\d*m") # ANSI color codes
_invisible_codes_bytes = re.compile(b"\x1b\[\d*m|\x1b\[\d*\;\d*\;\d*m") # ANSI color codes
_invisible_codes_bytes = re.compile(rb"\x1b\[\d*m|\x1b\[\d*\;\d*\;\d*m") # ANSI color codes


def simple_separated_format(separator):
Expand All @@ -294,7 +294,7 @@ def simple_separated_format(separator):

def _isconvertible(conv, string):
try:
n = conv(string)
conv(string)
return True
except (ValueError, TypeError):
return False
Expand Down Expand Up @@ -1008,7 +1008,7 @@ def tabulate(tabular_data, headers=(), tablefmt="simple",
spam & 41.9999 \\\\
eggs & 451 \\\\
\\bottomrule
\end{tabular}
\\end{tabular}
"""
if tabular_data is None:
tabular_data = []
Expand Down
11 changes: 2 additions & 9 deletions docs/appendices/compatibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,11 @@ Consult the following table for CrateDB compatibility notes:
| | | |
| | | The default CrateDB user is ``crate`` and |
| | | has no password is set. |
| | | |
| | | The `enterprise edition`_ of CrateDB |
| | | allows you to `create your own users`_. |
| | | |
| | | Prior versions of CrateDB do not support |
| | | this feature. |
+----------------+-----------------+-------------------------------------------+

.. _array constructors: https://crate.io/docs/crate/reference/en/latest/general/ddl/data-types.html#array-constructor
.. _array constructors: https://crate.io/docs/crate/reference/en/latest/general/ddl/data-types.html#data-types-array-literals
.. _client library: https://crate.io/docs/crate/clients-tools/en/latest/
.. _CrateDB REST endpoint: https://crate.io/docs/crate/reference/en/latest/interfaces/http.html
.. _create your own users: https://crate.io/docs/crate/reference/en/latest/admin/user-management.html
.. _enterprise edition: https://crate.io/docs/crate/reference/en/latest/editions.html#enterprise-features
.. _object literals: https://crate.io/docs/crate/reference/en/latest/general/ddl/data-types.html#object-literals
.. _object literals: https://crate.io/docs/crate/reference/en/latest/general/ddl/data-types.html#data-types-object-literals
.. _pip: https://pypi.org/project/pip/
2 changes: 1 addition & 1 deletion docs/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ This is an interactive `shell`_. You can type any CrateDB SQL query at the
Queries are autocompleted as you type:

.. image:: autocomplete.png
:alt: A screenshot of Crash after executing a query
:alt: A screenshot of Crash while typing a query

Once you have entered your query, hit :kbd:`Enter` to run.

Expand Down
5 changes: 1 addition & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ The CrateDB Shell (aka *Crash*) is an interactive `command-line interface`_

.. image:: startup.png
:alt: A screenshot of Crash after startup
:target: getting-started.html#query

.. image:: autocomplete.png
:alt: A screenshot of Crash after executing a query
:target: getting-started.html#query
:alt: A screenshot of Crash while typing a query

.. image:: query.png
:alt: A screenshot of Crash after executing a query
:target: getting-started.html#query

.. rubric:: Table of contents

Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_create_config(self):
conf = Configuration(path)
self.assertTrue(os.path.exists(path))
self.assertTrue(os.path.exists(conf.path))
self.assertTrue('crash' in conf.cfg.sections())
self.assertIn('crash', conf.cfg.sections())

def test_init_doesnt_override(self):
path = os.path.join(self.tmp_dir, 'bar.cfg')
Expand Down
39 changes: 21 additions & 18 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import os
import re
import ssl
import sys
import tempfile
from doctest import testfile
from io import StringIO, TextIOWrapper
from unittest import TestCase
from unittest.mock import DEFAULT, Mock, patch
from unittest import SkipTest, TestCase
from unittest.mock import Mock, patch

from urllib3.exceptions import LocationParseError

Expand All @@ -25,6 +24,10 @@
from crate.crash.printer import ColorPrinter
from crate.testing.layer import CrateLayer

if sys.platform != "linux":
raise SkipTest("Integration tests only supported on Linux")

crate_version = os.getenv("CRATEDB_VERSION", "4.7.1")
crate_http_port = 44209
crate_transport_port = 44309
crate_settings = {
Expand All @@ -36,7 +39,7 @@
'transport.tcp.port': crate_transport_port
}
node = CrateLayer.from_uri(
'https://cdn.crate.io/downloads/releases/crate-4.2.0.tar.gz',
f'https://cdn.crate.io/downloads/releases/crate-{crate_version}.tar.gz',
'crate',
settings=crate_settings
)
Expand Down Expand Up @@ -120,16 +123,16 @@ def assert_func(self, e, output, err):
exception_code = e.code
self.assertEqual(exception_code, 0)
output = output.getvalue()
self.assertTrue('| name |' in output)
self.assertTrue('| Testing44209 |' in output)
self.assertIn('| name |', output)
self.assertIn('| Testing44209 |', output)
self._output_format('tabular', assert_func)

def test_json_output(self):
def assert_func(self, e, output, err):
exception_code = e.code
self.assertEqual(exception_code, 0)
output = output.getvalue()
self.assertTrue('"name": "Testing44209"' in output)
self.assertIn('"name": "Testing44209"', output)
self._output_format('json', assert_func)

def test_json_row_output(self):
Expand All @@ -139,7 +142,7 @@ def assert_func(self, e, output, err):
exception_code = e.code
self.assertEqual(exception_code, 0)
output = output.getvalue()
self.assertTrue('{"table_name": "cluster"}' in output)
self.assertIn('{"table_name": "cluster"}', output)
self._output_format('json_row', assert_func, query)

def test_csv_obj_output(self):
Expand All @@ -149,7 +152,7 @@ def assert_func(self, e, output, err):
exception_code = e.code
self.assertEqual(exception_code, 0)
output = output.getvalue()
self.assertTrue("""crate,'{"http": 44209, "psql": 45441, "transport": 44309}'""" in output)
self.assertIn("""crate,'{"http": 44209, "psql": 45441, "transport": 44309}'""", output)

self._output_format('csv', assert_func, query)

Expand All @@ -160,7 +163,7 @@ def assert_func(self, e, output, err):
exception_code = e.code
self.assertEqual(exception_code, 0)
output = output.getvalue()
self.assertTrue('["/dev/' in output)
self.assertIn('["/dev/', output)

self._output_format('csv', assert_func, query)

Expand All @@ -169,18 +172,18 @@ def assert_func(self, e, output, err):
exception_code = e.code
self.assertEqual(exception_code, 0)
output = output.getvalue()
self.assertTrue('"duration":' in output)
self.assertTrue('"rowcount":' in output)
self.assertTrue('"rows":' in output)
self.assertTrue('"cols":' in output)
self.assertIn('"duration":', output)
self.assertIn('"rowcount":', output)
self.assertIn('"rows":', output)
self.assertIn('"cols":', output)
self._output_format('raw', assert_func)

def test_mixed_output(self):
def assert_func(self, e, output, err):
exception_code = e.code
self.assertEqual(exception_code, 0)
output = output.getvalue()
self.assertTrue("name | Testing44209" in output)
self.assertIn("name | Testing44209", output)
self._output_format('mixed', assert_func)

def test_pprint_duplicate_keys(self):
Expand Down Expand Up @@ -222,7 +225,7 @@ def test_stdin_cmd(self):
exception_code = e.code
self.assertEqual(exception_code, 0)
output = output.getvalue()
self.assertTrue('via-stdin' in output)
self.assertIn('via-stdin', output)
finally:
try:
os.remove(tmphistory)
Expand Down Expand Up @@ -252,8 +255,8 @@ def test_cmd_precedence(self):
exception_code = e.code
self.assertEqual(exception_code, 0)
output = output.getvalue()
self.assertTrue('via-command' in output)
self.assertFalse('via-stdin' in output)
self.assertIn('via-command', output)
self.assertNotIn('via-stdin', output)
finally:
try:
os.remove(tmphistory)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_keybinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ def test_bindings(self):
kb = KeyBindings()
bind_keys(Buffer(), kb)

self.assertTrue('on_backspace' in handlers_for_key(kb, Keys.Backspace))
self.assertTrue('on_tab' in handlers_for_key(kb, Keys.Tab))
self.assertIn('on_backspace', handlers_for_key(kb, Keys.Backspace))
self.assertIn('on_tab', handlers_for_key(kb, Keys.Tab))