Skip to content

Commit

Permalink
Fixed test for Python3.11 and Python3.12
Browse files Browse the repository at this point in the history
Generalized implementation
  • Loading branch information
tomuben committed Jun 7, 2024
1 parent 0b04de9 commit 1901ed8
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 157 deletions.
19 changes: 0 additions & 19 deletions exasol_python_test_framework/environment_info/__init__.py

This file was deleted.

23 changes: 22 additions & 1 deletion exasol_python_test_framework/exatest/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

import json
from contextlib import contextmanager
import os
import shutil
import tempfile
from typing import Union


@contextmanager
def tempdir():
Expand All @@ -21,5 +23,24 @@ def chdir(newdir):
finally:
os.chdir(olddir)


class InfoObject:
"""
Recursive class which converts a given dictionary to attributes of the instance.
This is just a convenience class.
"""
def __init__(self, d):
for k, v in d.items():
if isinstance(k, (list, tuple)):
setattr(self, k, [InfoObject(x) if isinstance(x, dict) else x for x in v])
else:
setattr(self, k, InfoObject(v) if isinstance(v, dict) else v)


def obj_from_json_file(json_file_path: Union[str, bytes, os.PathLike]) -> InfoObject:
with open(json_file_path, "r") as f:
env_info_dict = json.load(f)
return InfoObject(env_info_dict)

# vim: ts=4:sts=4:sw=4:et:fdm=indent

222 changes: 116 additions & 106 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ scipy = "^1.13.0"
# non windows platforms.
docker = { version = ">=5.0.3", markers = "sys_platform != 'win32'"}
pyftpdlib = ">=1.5.6"
pyasyncore = ">=1.0.4" #Asyncore is still used in the project, but was removed in Python3.12 from the Python standard library.

[tool.poetry.dev-dependencies]
toml = ">=0.10.2"
Expand Down
3 changes: 1 addition & 2 deletions scripts/test/run_locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,4 @@ SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
TEST_DIR="$SCRIPT_DIR/../../tests"
run_tests_in_folder "$TEST_DIR/exatest" "$server" "$odbc_driver"
run_tests_in_folder "$TEST_DIR/udf" "$server" "$odbc_driver" --lang foo --lang-path "$TEST_DIR/udf/lang"
run_tests_in_folder "$TEST_DIR/docker_db_environment" "$server" "$odbc_driver"
run_tests_in_folder "$TEST_DIR/environment_info" "$server" "$odbc_driver"
run_tests_in_folder "$TEST_DIR/docker_db_environment" "$server" "$odbc_driver"
23 changes: 0 additions & 23 deletions tests/environment_info/environment_info.py

This file was deleted.

30 changes: 24 additions & 6 deletions tests/exatest/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,14 @@ def test_2(self): self.fail()
def test_3(self): pass

with selftest(Module) as result:
self.assertIn('\ntest_2 (__main__.ConditionalTestCaseTest.test_expectedFailure_tests.<locals>.Module.Test) ... expected failure', result.output)
self.assertIn('\ntest_3 (__main__.ConditionalTestCaseTest.test_expectedFailure_tests.<locals>.Module.Test) ... unexpected success', result.output)
expected_out_python3_10_and_before = "\ntest_2 (__main__.ConditionalTestCaseTest.test_expectedFailure_tests.<locals>.Module.Test) ... expected failure"
expected_out_python3_11_and_later = "\ntest_2 (__main__.ConditionalTestCaseTest.test_expectedFailure_tests.<locals>.Module.Test.test_2) ... expected failure"
if expected_out_python3_10_and_before not in result.output and expected_out_python3_11_and_later not in result.output:
self.fail("Did not find expected output.")
expected_out_python3_10_and_before = "\ntest_3 (__main__.ConditionalTestCaseTest.test_expectedFailure_tests.<locals>.Module.Test) ... unexpected success"
expected_out_python3_11_and_later = "\ntest_3 (__main__.ConditionalTestCaseTest.test_expectedFailure_tests.<locals>.Module.Test.test_3) ... unexpected success"
if expected_out_python3_10_and_before not in result.output and expected_out_python3_11_and_later not in result.output:
self.fail("Did not find expected output.")
self.assertEqual(1, len(result.expectedFailures))
self.assertEqual(1, len(result.unexpectedSuccesses))

Expand All @@ -180,8 +186,14 @@ def test_2(self): self.fail()
def test_3(self): pass

with selftest(Module) as result:
self.assertIn('\ntest_2 (__main__.ConditionalTestCaseTest.test_expectedFailureIf_True_tests.<locals>.Module.Test) ... expected failure', result.output)
self.assertIn('\ntest_3 (__main__.ConditionalTestCaseTest.test_expectedFailureIf_True_tests.<locals>.Module.Test) ... unexpected success', result.output)
expected_out_python3_10_and_before = "\ntest_2 (__main__.ConditionalTestCaseTest.test_expectedFailureIf_True_tests.<locals>.Module.Test) ... expected failure"
expected_out_python3_11_and_later = "\ntest_2 (__main__.ConditionalTestCaseTest.test_expectedFailureIf_True_tests.<locals>.Module.Test.test_2) ... expected failure"
if expected_out_python3_10_and_before not in result.output and expected_out_python3_11_and_later not in result.output:
self.fail("Did not find expected output.")
expected_out_python3_10_and_before = "\ntest_3 (__main__.ConditionalTestCaseTest.test_expectedFailureIf_True_tests.<locals>.Module.Test) ... unexpected success"
expected_out_python3_11_and_later = "\ntest_3 (__main__.ConditionalTestCaseTest.test_expectedFailureIf_True_tests.<locals>.Module.Test.test_3) ... unexpected success"
if expected_out_python3_10_and_before not in result.output and expected_out_python3_11_and_later not in result.output:
self.fail("Did not find expected output.")
self.assertEqual(1, len(result.expectedFailures))
self.assertEqual(1, len(result.unexpectedSuccesses))

Expand All @@ -195,8 +207,14 @@ def test_2(self): self.fail()
def test_3(self): pass

with selftest(Module) as result:
self.assertIn('\ntest_2 (__main__.ConditionalTestCaseTest.test_expectedFailureIf_False_tests.<locals>.Module.Test) ... FAIL', result.output)
self.assertIn('\ntest_3 (__main__.ConditionalTestCaseTest.test_expectedFailureIf_False_tests.<locals>.Module.Test) ... ok', result.output)
expected_out_python3_10_and_before = "\ntest_2 (__main__.ConditionalTestCaseTest.test_expectedFailureIf_False_tests.<locals>.Module.Test) ... FAIL"
expected_out_python3_11_and_later = "\ntest_2 (__main__.ConditionalTestCaseTest.test_expectedFailureIf_False_tests.<locals>.Module.Test.test_2) ... FAIL"
if expected_out_python3_10_and_before not in result.output and expected_out_python3_11_and_later not in result.output:
self.fail("Did not find expected output.")
expected_out_python3_10_and_before = "\ntest_3 (__main__.ConditionalTestCaseTest.test_expectedFailureIf_False_tests.<locals>.Module.Test) ... ok"
expected_out_python3_11_and_later = "\ntest_3 (__main__.ConditionalTestCaseTest.test_expectedFailureIf_False_tests.<locals>.Module.Test.test_3) ... ok"
if expected_out_python3_10_and_before not in result.output and expected_out_python3_11_and_later not in result.output:
self.fail("Did not find expected output.")
self.assertEqual(1, len(result.failures))
self.assertEqual(0, len(result.expectedFailures))
self.assertEqual(0, len(result.unexpectedSuccesses))
Expand Down
25 changes: 25 additions & 0 deletions tests/exatest/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python3

import json
import tempfile
import unittest
from pathlib import Path


from exasol_python_test_framework.exatest.utils import obj_from_json_file
from exasol_python_test_framework.exatest.test import run_selftest


class UtilsTest(unittest.TestCase):
def test_info_object(self):
with tempfile.TemporaryDirectory() as tmpdirname:
sample_dict = {"a": {"b": {"c": 100}}}
tmp_file = Path(tmpdirname) / "tmp.json"
with open (tmp_file, "w") as f:
json.dump(sample_dict, f)
o = obj_from_json_file(tmp_file)
self.assertEqual(o.a.b.c, 100)


if __name__ == '__main__':
run_selftest()

0 comments on commit 1901ed8

Please sign in to comment.