Kaydet (Commit) 272c1f86 authored tarafından Michael Merickel's avatar Michael Merickel

support specifying location of temp folders

TestWithBinds was failing when shared folders are used because /tmp was
not shared from OS X to my VM. This fix allows the location of the temp
folders to be changed via:

    TMPDIR=$(pwd) env/bin/python setup.py test

This also properly cleans up temp folders which were sticking around
before.
üst b5e75c40
...@@ -17,6 +17,7 @@ import base64 ...@@ -17,6 +17,7 @@ import base64
import json import json
import io import io
import os import os
import shutil
import signal import signal
import tempfile import tempfile
import unittest import unittest
...@@ -31,11 +32,13 @@ import six ...@@ -31,11 +32,13 @@ import six
class BaseTestCase(unittest.TestCase): class BaseTestCase(unittest.TestCase):
tmp_imgs = [] tmp_imgs = []
tmp_containers = [] tmp_containers = []
tmp_folders = []
def setUp(self): def setUp(self):
self.client = docker.Client(timeout=5) self.client = docker.Client(timeout=5)
self.tmp_imgs = [] self.tmp_imgs = []
self.tmp_containers = [] self.tmp_containers = []
self.tmp_folders = []
def tearDown(self): def tearDown(self):
for img in self.tmp_imgs: for img in self.tmp_imgs:
...@@ -49,6 +52,8 @@ class BaseTestCase(unittest.TestCase): ...@@ -49,6 +52,8 @@ class BaseTestCase(unittest.TestCase):
self.client.remove_container(container) self.client.remove_container(container)
except docker.errors.APIError: except docker.errors.APIError:
pass pass
for folder in self.tmp_folders:
shutil.rmtree(folder)
######################### #########################
# INFORMATION TESTS # # INFORMATION TESTS #
...@@ -138,7 +143,8 @@ class TestCreateContainer(BaseTestCase): ...@@ -138,7 +143,8 @@ class TestCreateContainer(BaseTestCase):
class TestCreateContainerWithBinds(BaseTestCase): class TestCreateContainerWithBinds(BaseTestCase):
def runTest(self): def runTest(self):
mount_dest = '/mnt' mount_dest = '/mnt'
mount_origin = '/tmp' mount_origin = tempfile.mkdtemp()
self.tmp_folders.append(mount_origin)
filename = 'shared.txt' filename = 'shared.txt'
shared_file = os.path.join(mount_origin, filename) shared_file = os.path.join(mount_origin, filename)
...@@ -850,6 +856,7 @@ class TestRunShlex(BaseTestCase): ...@@ -850,6 +856,7 @@ class TestRunShlex(BaseTestCase):
class TestLoadConfig(BaseTestCase): class TestLoadConfig(BaseTestCase):
def runTest(self): def runTest(self):
folder = tempfile.mkdtemp() folder = tempfile.mkdtemp()
self.tmp_folders.append(folder)
f = open(os.path.join(folder, '.dockercfg'), 'w') f = open(os.path.join(folder, '.dockercfg'), 'w')
auth_ = base64.b64encode(b'sakuya:izayoi').decode('ascii') auth_ = base64.b64encode(b'sakuya:izayoi').decode('ascii')
f.write('auth = {0}\n'.format(auth_)) f.write('auth = {0}\n'.format(auth_))
...@@ -867,6 +874,7 @@ class TestLoadConfig(BaseTestCase): ...@@ -867,6 +874,7 @@ class TestLoadConfig(BaseTestCase):
class TestLoadJSONConfig(BaseTestCase): class TestLoadJSONConfig(BaseTestCase):
def runTest(self): def runTest(self):
folder = tempfile.mkdtemp() folder = tempfile.mkdtemp()
self.tmp_folders.append(folder)
f = open(os.path.join(folder, '.dockercfg'), 'w') f = open(os.path.join(folder, '.dockercfg'), 'w')
auth_ = base64.b64encode(b'sakuya:izayoi').decode('ascii') auth_ = base64.b64encode(b'sakuya:izayoi').decode('ascii')
email_ = 'sakuya@scarlet.net' email_ = 'sakuya@scarlet.net'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment