Skip to content

Commit

Permalink
Merge branch 'master' into test/convert-examples-cXY-to-test-cases-pt5
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoretti committed Jun 19, 2024
2 parents f3002bc + 38cb6f1 commit 5a3813d
Show file tree
Hide file tree
Showing 7 changed files with 401 additions and 68 deletions.
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def start_db():
session.run(
"itde",
"spawn-test-environment",
"--create-certificates",
"--environment-name",
"test",
"--database-port-forward",
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
xfail_strict = true
markers = [
"smoke: smoke tests which always should pass.",
"basic: basic driver tests.",
Expand All @@ -84,6 +85,9 @@ markers = [
"json: tests related to json serialization in pyexasol.",
"dbapi2: tests related to dbapi2 compatibility.",
"configuration: tests related to pyexasol settings and configuration.",
"udf: tests related to user defined functions."
"edge_cases: tests related to pyexasol and exasol edge cases scenarios.",
"tls: tests related to tls.",
"udf: tests related to user defined functions.",
"misc: miscellaneous tests which did not fit in the other categories."
]

58 changes: 58 additions & 0 deletions test/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import uuid
import pytest
import decimal
import pyexasol
import subprocess
from inspect import cleandoc
from pathlib import Path

import logging
Expand Down Expand Up @@ -69,6 +71,62 @@ def prepare_database(dsn, user, password):
loader.load()


@pytest.fixture
def edge_case_ddl():
table_name = "edge_case"
ddl = cleandoc(
f"""CREATE OR REPLACE TABLE {table_name}
(
dec36_0 DECIMAL(36,0),
dec36_36 DECIMAL(36,36),
dbl DOUBLE,
bl BOOLEAN,
dt DATE,
ts TIMESTAMP,
var100 VARCHAR(100),
var2000000 VARCHAR(2000000)
)
"""
)
yield table_name, ddl


@pytest.fixture
def edge_cases():
return {
"Biggest-Values": {
"DEC36_0": decimal.Decimal("+" + ("9" * 36)),
"DEC36_36": decimal.Decimal("+0." + ("9" * 36)),
"DBL": 1.7e308,
"BL": True,
"DT": "9999-12-31",
"TS": "9999-12-31 23:59:59.999",
"VAR100": "ひ" * 100,
"VAR2000000": "ひ" * 2000000,
},
"Smallest-Values": {
"DEC36_0": decimal.Decimal("-" + ("9" * 36)),
"DEC36_36": decimal.Decimal("-0." + ("9" * 36)),
"DBL": -1.7e308,
"BL": False,
"DT": "0001-01-01",
"TS": "0001-01-01 00:00:00",
"VAR100": "",
"VAR2000000": "ひ",
},
"All-Nulls": {
"DEC36_0": None,
"DEC36_36": None,
"DBL": None,
"BL": None,
"DT": None,
"TS": None,
"VAR100": None,
"VAR2000000": None,
},
}


class DockerDataLoader:
"""Data loader for docker based Exasol DB"""

Expand Down
82 changes: 82 additions & 0 deletions test/integration/edge_cases_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import pytest


@pytest.fixture
def empty_table(connection, edge_case_ddl):
table_name, ddl = edge_case_ddl
connection.execute(ddl)
connection.commit()

yield table_name

delete_stmt = f"DROP TABLE IF EXISTS {table_name};"
connection.execute(delete_stmt)
connection.commit()


@pytest.fixture
def poplulate_edge_case_table(connection, empty_table, edge_cases):
table = "edge_case"
stmt = (
f"INSERT INTO {table} VALUES ({{DEC36_0!d}}, {{DEC36_36!d}}, {{DBL!f}}, "
"{BL}, {DT}, {TS}, {VAR100}, {VAR2000000})"
)
for case in edge_cases.values():
connection.execute(stmt, dict(case))

connection.commit()

yield table


@pytest.mark.edge_case
def test_insert(connection, empty_table, edge_cases):
stmt = (
f"INSERT INTO {empty_table} VALUES ({{DEC36_0!d}}, {{DEC36_36!d}}, {{DBL!f}}, "
"{BL}, {DT}, {TS}, {VAR100}, {VAR2000000})"
)
for case in edge_cases.values():
connection.execute(stmt, dict(case))

expected = len(edge_cases)
actual = connection.execute(f"SELECT COUNT(*) FROM {empty_table};").fetchval()

assert actual == expected


@pytest.mark.edge_case
def test_select_and_fetch(connection, edge_cases, poplulate_edge_case_table):
query = (
"SELECT DEC36_0, DEC36_36, DBL, BL, DT, TS, VAR100, "
"LENGTH(var2000000) AS len_var FROM edge_case"
)

result = connection.execute(query).fetchall()

expected = len(edge_cases.values())
actual = len(result)

assert actual == expected


@pytest.mark.edge_case
def test_very_long_query(connection, edge_cases):
query = (
"SELECT {VAL1} AS VAL1, {VAL2} AS VAL2, "
"{VAL3} AS VAL3, {VAL4} AS VAL4, {VAL5} AS VAL5"
)
case = "Biggest-Values"
params = {
"VAL1": edge_cases[case]["VAR2000000"],
"VAL2": edge_cases[case]["VAR2000000"],
"VAL3": edge_cases[case]["VAR2000000"],
"VAL4": edge_cases[case]["VAR2000000"],
"VAL5": edge_cases[case]["VAR2000000"],
}

result = connection.execute(query, params)

expected = 10000065
actual = len(result.query)

assert actual == expected
96 changes: 29 additions & 67 deletions test/integration/json_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import pytest
import pyexasol
import decimal

from inspect import cleandoc


@pytest.fixture
Expand All @@ -27,98 +24,45 @@ def factory(json_lib):


@pytest.fixture
def table(connection):
name = "edge_case"
ddl = cleandoc(
f"""CREATE OR REPLACE TABLE {name}
(
dec36_0 DECIMAL(36,0),
dec36_36 DECIMAL(36,36),
dbl DOUBLE,
bl BOOLEAN,
dt DATE,
ts TIMESTAMP,
var100 VARCHAR(100),
var2000000 VARCHAR(2000000)
)
"""
)
def empty_table(connection, edge_case_ddl):
table_name, ddl = edge_case_ddl
connection.execute(ddl)
connection.commit()

yield name
yield table_name

delete_stmt = f"DROP TABLE IF EXISTS {name};"
delete_stmt = f"DROP TABLE IF EXISTS {table_name};"
connection.execute(delete_stmt)
connection.commit()


@pytest.fixture
def edge_cases():
return [
# Biggest values
{
"DEC36_0": decimal.Decimal("+" + ("9" * 36)),
"DEC36_36": decimal.Decimal("+0." + ("9" * 36)),
"DBL": 1.7e308,
"BL": True,
"DT": "9999-12-31",
"TS": "9999-12-31 23:59:59.999",
"VAR100": "ひ" * 100,
"VAR2000000": "ひ" * 2000000,
},
# Smallest values
{
"DEC36_0": decimal.Decimal("-" + ("9" * 36)),
"DEC36_36": decimal.Decimal("-0." + ("9" * 36)),
"DBL": -1.7e308,
"BL": False,
"DT": "0001-01-01",
"TS": "0001-01-01 00:00:00",
"VAR100": "",
"VAR2000000": "ひ",
},
# All nulls
{
"DEC36_0": None,
"DEC36_36": None,
"DBL": None,
"BL": None,
"DT": None,
"TS": None,
"VAR100": None,
"VAR2000000": None,
},
]


@pytest.mark.json
@pytest.mark.parametrize("json_lib", ["orjson", "ujson", "rapidjson"])
def test_insert(table, connection_factory, edge_cases, json_lib):
def test_insert(empty_table, connection_factory, edge_cases, json_lib):
connection = connection_factory(json_lib)
insert_stmt = (
"INSERT INTO edge_case VALUES"
"({DEC36_0!d}, {DEC36_36!d}, {DBL!f}, {BL}, {DT}, {TS}, {VAR100}, {VAR2000000})"
)
for edge_case in edge_cases:
for edge_case in edge_cases.values():
connection.execute(insert_stmt, edge_case)

expected = len(edge_cases)
actual = connection.execute(f"SELECT COUNT(*) FROM {table};").fetchval()
actual = connection.execute(f"SELECT COUNT(*) FROM {empty_table};").fetchval()

assert actual == expected


@pytest.mark.json
@pytest.mark.parametrize("json_lib", ["orjson", "ujson", "rapidjson"])
def test_select(table, connection_factory, edge_cases, json_lib):
def test_select(empty_table, connection_factory, edge_cases, json_lib):
connection = connection_factory(json_lib)

insert_stmt = (
"INSERT INTO edge_case VALUES"
"({DEC36_0!d}, {DEC36_36!d}, {DBL!f}, {BL}, {DT}, {TS}, {VAR100}, {VAR2000000})"
)
for edge_case in edge_cases:
for edge_case in edge_cases.values():
connection.execute(insert_stmt, edge_case)

select_stmt = (
Expand All @@ -128,9 +72,27 @@ def test_select(table, connection_factory, edge_cases, json_lib):

expected = {
# Biggest values
("9" * 36, f"0.{'9' * 36}", 1.7e308, True, "9999-12-31", "9999-12-31 23:59:59.999000", "ひ" * 100, 2000000),
(
"9" * 36,
f"0.{'9' * 36}",
1.7e308,
True,
"9999-12-31",
"9999-12-31 23:59:59.999000",
"ひ" * 100,
2000000,
),
# Smallest values
(f"-{'9' * 36}", f"-0.{'9' * 36}", -1.7e308, False, "0001-01-01", "0001-01-01 00:00:00.000000", None, 1),
(
f"-{'9' * 36}",
f"-0.{'9' * 36}",
-1.7e308,
False,
"0001-01-01",
"0001-01-01 00:00:00.000000",
None,
1,
),
# All nulls
(None, None, None, None, None, None, None, None),
}
Expand Down
Loading

0 comments on commit 5a3813d

Please sign in to comment.