Skip to content

Commit 654f666

Browse files
committed
initial commit
0 parents  commit 654f666

File tree

8 files changed

+151
-0
lines changed

8 files changed

+151
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea
2+
env
3+
.pytest_cache
4+
build
5+
dist
6+
*.egg-info

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Dmitry Maslennikov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Testcontainers-python for InterSystems IRIS
2+
3+
[testcontainers-python](https://testcontainers-python.readthedocs.io/en/latest/README.html) facilitates the use of Docker containers for functional and integration testing.
4+
5+
## Other implementations
6+
7+
* [testcontainers-iris-java](https://github.com/caretdev/testcontainers-iris-java)
8+
9+
## Basic usage
10+
11+
```
12+
>>> from testcontainers.iris import IRISContainer
13+
>>> import sqlalchemy
14+
15+
>>> iris_container = IRISContainer("intersystemsdc/iris-community:latest")
16+
>>> with iris_container as iris:
17+
... engine = sqlalchemy.create_engine(iris.get_connection_url())
18+
... with engine.begin() as connection:
19+
... result = connection.execute(sqlalchemy.text("select $zversion"))
20+
... version, = result.fetchone()
21+
>>> version
22+
'IRIS for UNIX (Ubuntu Server LTS for ARM64 Containers) 2023.2 (Build 227U) Mon Jul 31 2023 17:43:25 EDT'
23+
```
24+
25+
The snippet above will spin up a InterSystems IRIS database in a container. The get_connection_url() convenience method returns a sqlalchemy compatible url we use to connect to the database and retrieve the database version.
26+
27+
More extensive documentation can be found at [Read The Docs](https://testcontainers-python.readthedocs.io/).

demo.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from testcontainers.iris import IRISContainer
2+
import sqlalchemy
3+
4+
iris_container = IRISContainer("intersystemsdc/iris-community:latest")
5+
with iris_container as iris:
6+
engine = sqlalchemy.create_engine(iris.get_connection_url())
7+
with engine.begin() as connection:
8+
result = connection.execute(sqlalchemy.text("select $zversion"))
9+
version, = result.fetchone()
10+
print(version)

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pytest
2+
wheel
3+
twine

setup.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from setuptools import setup, find_namespace_packages
2+
3+
description = "InterSystems IRIS component of testcontainers-python."
4+
5+
setup(
6+
name="testcontainers-iris",
7+
version="1.0.1",
8+
packages=find_namespace_packages(),
9+
description=description,
10+
long_description=description,
11+
long_description_content_type="text/markdown",
12+
url="https://github.com/caretdev/testcontainers-iris-python",
13+
install_requires=[
14+
"testcontainers-core",
15+
"sqlalchemy",
16+
"sqlalchemy-iris",
17+
],
18+
python_requires=">=3.7",
19+
)

testcontainers/iris/__init__.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os
2+
from typing import Optional
3+
from testcontainers.core.generic import DbContainer
4+
# from testcontainers.core.utils import raise_for_deprecated_parameter
5+
6+
7+
class IRISContainer(DbContainer):
8+
"""
9+
InterSystems IRIS database container.
10+
11+
Example:
12+
13+
The example spins up a IRIS database and connects to it using the :code:`intersystems-iris`
14+
driver.
15+
16+
.. doctest::
17+
18+
>>> from testcontainers.iris import IRISContainer
19+
>>> import sqlalchemy
20+
21+
>>> iris_container = IRISContainer("intersystemsdc/iris-community:latest")
22+
>>> with iris_container as iris:
23+
... engine = sqlalchemy.create_engine(iris.get_connection_url())
24+
... with engine.begin() as connection:
25+
... result = connection.execute(sqlalchemy.text("select $zversion"))
26+
... version, = result.fetchone()
27+
>>> version
28+
'IRIS for UNIX (Ubuntu Server LTS for ARM64 Containers) 2023.2 (Build 227U) Mon Jul 31 2023 17:43:25 EDT'
29+
"""
30+
def __init__(self, image: str = "intersystemsdc/iris-community:latest", port: int = 1972,
31+
username: Optional[str] = None, password: Optional[str] = None,
32+
dbname: Optional[str] = None, driver: str = "iris", **kwargs) -> None:
33+
# raise_for_deprecated_parameter(kwargs, "user", "username")
34+
super(IRISContainer, self).__init__(image=image, **kwargs)
35+
self.username = username or os.environ.get("IRIS_USERNAME", "test")
36+
self.password = password or os.environ.get("IRIS_PASSWORD", "test")
37+
self.dbname = dbname or os.environ.get("IRIS_NAMESPACE", "USER")
38+
self.port = port
39+
self.driver = driver
40+
41+
self.with_exposed_ports(self.port)
42+
43+
def _configure(self) -> None:
44+
self.with_env("IRIS_USERNAME", self.username)
45+
self.with_env("IRIS_PASSWORD", self.password)
46+
self.with_env("IRIS_NAMESPACE", self.dbname)
47+
48+
def get_connection_url(self, host=None) -> str:
49+
return super()._create_connection_url(
50+
dialect=f"iris", username=self.username,
51+
password=self.password, db_name=self.dbname, host=host,
52+
port=self.port,
53+
)

tests/test_iris.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sqlalchemy
2+
from testcontainers.iris import IRISContainer
3+
4+
5+
def test_docker_run_iris():
6+
iris_container = IRISContainer("intersystemsdc/iris-community:2023.1.1.380.0-zpm")
7+
with iris_container as iris:
8+
engine = sqlalchemy.create_engine(iris.get_connection_url())
9+
with engine.begin() as connection:
10+
result = connection.execute(sqlalchemy.text("select $zversion"))
11+
for row in result:
12+
assert "2023.1.1 (Build 380U)" in row[0]

0 commit comments

Comments
 (0)