Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions requirements/3.5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ alabaster==0.7.12 # via sphinx
attrs==19.3.0 # via jsonschema, pytest
babel==2.8.0 # via sphinx
bcrypt==3.1.7 # via paramiko
blindspin==2.0.1 # via testcontainers
cached-property==1.5.1 # via docker-compose
cachetools==4.1.1 # via google-auth
certifi==2020.6.20 # via requests
cffi==1.14.2 # via bcrypt, cryptography, pynacl
chardet==3.0.4 # via requests
codecov==2.1.8 # via -r requirements.in
colorama==0.4.3 # via crayons
coverage==5.2.1 # via codecov, pytest-cov
crayons==0.3.1 # via testcontainers
cryptography==3.0 # via paramiko
cx-oracle==8.0.0 # via testcontainers
deprecation==2.1.0 # via testcontainers
Expand Down
3 changes: 0 additions & 3 deletions requirements/3.6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ alabaster==0.7.12 # via sphinx
attrs==19.3.0 # via jsonschema, pytest
babel==2.8.0 # via sphinx
bcrypt==3.2.0 # via paramiko
blindspin==2.0.1 # via testcontainers
cached-property==1.5.1 # via docker-compose
cachetools==4.1.1 # via google-auth
certifi==2020.6.20 # via requests
cffi==1.14.2 # via bcrypt, cryptography, pynacl
chardet==3.0.4 # via requests
codecov==2.1.8 # via -r requirements.in
colorama==0.4.3 # via crayons
coverage==5.2.1 # via codecov, pytest-cov
crayons==0.3.1 # via testcontainers
cryptography==3.0 # via paramiko
cx-oracle==8.0.0 # via testcontainers
deprecation==2.1.0 # via testcontainers
Expand Down
3 changes: 0 additions & 3 deletions requirements/3.7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ alabaster==0.7.12 # via sphinx
attrs==19.3.0 # via jsonschema, pytest
babel==2.8.0 # via sphinx
bcrypt==3.2.0 # via paramiko
blindspin==2.0.1 # via testcontainers
cached-property==1.5.1 # via docker-compose
cachetools==4.1.1 # via google-auth
certifi==2020.6.20 # via requests
cffi==1.14.2 # via bcrypt, cryptography, pynacl
chardet==3.0.4 # via requests
codecov==2.1.8 # via -r requirements.in
colorama==0.4.3 # via crayons
coverage==5.2.1 # via codecov, pytest-cov
crayons==0.3.1 # via testcontainers
cryptography==3.0 # via paramiko
cx-oracle==8.0.0 # via testcontainers
deprecation==2.1.0 # via testcontainers
Expand Down
3 changes: 0 additions & 3 deletions requirements/3.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ alabaster==0.7.12 # via sphinx
attrs==19.3.0 # via jsonschema, pytest
babel==2.8.0 # via sphinx
bcrypt==3.2.0 # via paramiko
blindspin==2.0.1 # via testcontainers
cached-property==1.5.1 # via docker-compose
cachetools==4.1.1 # via google-auth
certifi==2020.6.20 # via requests
cffi==1.14.2 # via bcrypt, cryptography, pynacl
chardet==3.0.4 # via requests
codecov==2.1.8 # via -r requirements.in
colorama==0.4.3 # via crayons
coverage==5.2.1 # via codecov, pytest-cov
crayons==0.3.1 # via testcontainers
cryptography==3.0 # via paramiko
cx-oracle==8.0.0 # via testcontainers
deprecation==2.1.0 # via testcontainers
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
install_requires=[
'docker',
'wrapt',
'crayons',
'blindspin',
'deprecation',
],
extras_require={
Expand Down
32 changes: 14 additions & 18 deletions testcontainers/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import subprocess

import blindspin
import requests

from testcontainers.core.waiting_utils import wait_container_is_ready
Expand Down Expand Up @@ -81,28 +80,25 @@ def docker_compose_command(self):
return docker_compose_cmd

def start(self):
with blindspin.spinner():
if self.pull:
pull_cmd = self.docker_compose_command() + ['pull']
subprocess.call(pull_cmd, cwd=self.filepath)
up_cmd = self.docker_compose_command() + ['up', '-d']
subprocess.call(up_cmd, cwd=self.filepath)
if self.pull:
pull_cmd = self.docker_compose_command() + ['pull']
subprocess.call(pull_cmd, cwd=self.filepath)
up_cmd = self.docker_compose_command() + ['up', '-d']
subprocess.call(up_cmd, cwd=self.filepath)

def stop(self):
with blindspin.spinner():
down_cmd = self.docker_compose_command() + ['down', '-v']
subprocess.call(down_cmd, cwd=self.filepath)
down_cmd = self.docker_compose_command() + ['down', '-v']
subprocess.call(down_cmd, cwd=self.filepath)

def get_logs(self):
logs_cmd = self.docker_compose_command() + ["logs"]
with blindspin.spinner():
result = subprocess.run(
logs_cmd,
cwd=self.filepath,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
return result.stdout, result.stderr
result = subprocess.run(
logs_cmd,
cwd=self.filepath,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
return result.stdout, result.stderr

def get_service_port(self, service_name, port):
return self._get_service_info(service_name, port)[1]
Expand Down
35 changes: 15 additions & 20 deletions testcontainers/core/container.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import blindspin
import crayons
from docker.models.containers import Container

from testcontainers.core.docker_client import DockerClient
from testcontainers.core.exceptions import ContainerStartException
from testcontainers.core.utils import inside_container
from testcontainers.core.utils import setup_logger, inside_container

logger = setup_logger(__name__)


class DockerContainer(object):
Expand Down Expand Up @@ -38,23 +38,18 @@ def with_kargs(self, **kargs) -> 'DockerContainer':
return self

def start(self):
print("")
print("{} {}".format(crayons.yellow("Pulling image"),
crayons.red(self.image)))
with blindspin.spinner():
docker_client = self.get_docker_client()
self._container = docker_client.run(self.image,
command=self._command,
detach=True,
environment=self.env,
ports=self.ports,
name=self._name,
volumes=self.volumes,
**self._kargs
)
print("")
print("Container started: ",
crayons.yellow(self._container.short_id, bold=True))
logger.info("Pulling image %s", self.image)
docker_client = self.get_docker_client()
self._container = docker_client.run(self.image,
command=self._command,
detach=True,
environment=self.env,
ports=self.ports,
name=self._name,
volumes=self.volumes,
**self._kargs
)
logger.info("Container started: %s", self._container.short_id)
return self

def stop(self, force=True, delete_volume=True):
Expand Down
10 changes: 10 additions & 0 deletions testcontainers/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import os
import sys
import subprocess
import logging

LINUX = "linux"
MAC = "mac"
WIN = "win"


def setup_logger(name):
logger = logging.getLogger(name)
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
logger.addHandler(handler)
return logger


def os_name():
pl = sys.platform
if pl == "linux" or pl == "linux2":
Expand Down
32 changes: 16 additions & 16 deletions testcontainers/core/waiting_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
import re
import time

import blindspin
import crayons
import wrapt

from testcontainers.core import config
from testcontainers.core.exceptions import TimeoutException
from testcontainers.core.utils import setup_logger

logger = setup_logger(__name__)


def wait_container_is_ready():
Expand All @@ -35,20 +36,19 @@ def wait_container_is_ready():
@wrapt.decorator
def wrapper(wrapped, instance, args, kwargs):
exception = None
print(crayons.yellow("Waiting to be ready..."))
with blindspin.spinner():
for _ in range(0, config.MAX_TRIES):
try:
return wrapped(*args, **kwargs)
except Exception as e:
time.sleep(config.SLEEP_TIME)
exception = e
raise TimeoutException(
"""Wait time exceeded {0} sec.
Method {1}, args {2} , kwargs {3}.
Exception {4}""".format(config.MAX_TRIES,
wrapped.__name__,
args, kwargs, exception))
logger.info("Waiting to be ready...")
for _ in range(0, config.MAX_TRIES):
try:
return wrapped(*args, **kwargs)
except Exception as e:
time.sleep(config.SLEEP_TIME)
exception = e
raise TimeoutException(
"""Wait time exceeded {0} sec.
Method {1}, args {2} , kwargs {3}.
Exception {4}""".format(config.MAX_TRIES,
wrapped.__name__,
args, kwargs, exception))

return wrapper

Expand Down