Commit 235109d3 authored by Philip ABBET's avatar Philip ABBET

[unittests] Fix: The new docker version break a test

parent 0403717b
......@@ -26,6 +26,8 @@
###############################################################################
from beat.backend.python.data import getAllFilenames
from beat.backend.python.data import CachedFileLoader
from beat.backend.python.data import DataSource
from beat.backend.python.data import DataSink
from beat.backend.python.data import CachedDataSource
......
......@@ -33,7 +33,11 @@ import tempfile
import six
import numpy
from ..data import CachedDataSink, CachedDataSource, foundSplitRanges
from ..data import CachedFileLoader
from ..data import CachedDataSink
from ..data import CachedDataSource
from ..data import getAllFilenames
from ..data import foundSplitRanges
from ..hash import hashFileContents
from ..dataformat import DataFormat
......@@ -86,6 +90,194 @@ class TestCachedDataBase(unittest.TestCase):
#----------------------------------------------------------
class TestGetAllFilenames(TestCachedDataBase):
def test_one_complete_data_file(self):
self.writeData('user/integers/1', 0, 9)
(data_filenames, indices_filenames, data_checksum_filenames, indices_checksum_filenames) = \
getAllFilenames(self.filename)
self.assertEqual(1, len(data_filenames))
self.assertEqual(1, len(indices_filenames))
self.assertEqual(1, len(data_checksum_filenames))
self.assertEqual(1, len(indices_checksum_filenames))
def test_three_complete_data_files(self):
self.writeData('user/integers/1', 0, 9)
self.writeData('user/integers/1', 10, 19)
self.writeData('user/integers/1', 20, 29)
(data_filenames, indices_filenames, data_checksum_filenames, indices_checksum_filenames) = \
getAllFilenames(self.filename)
self.assertEqual(3, len(data_filenames))
self.assertEqual(3, len(indices_filenames))
self.assertEqual(3, len(data_checksum_filenames))
self.assertEqual(3, len(indices_checksum_filenames))
def test_one_partial_data_file(self):
self.writeData('user/integers/1', 0, 9)
(data_filenames, indices_filenames, data_checksum_filenames, indices_checksum_filenames) = \
getAllFilenames(self.filename, 2, 6)
self.assertEqual(1, len(data_filenames))
self.assertEqual(1, len(indices_filenames))
self.assertEqual(1, len(data_checksum_filenames))
self.assertEqual(1, len(indices_checksum_filenames))
def test_three_partial_data_files_1(self):
self.writeData('user/integers/1', 0, 9)
self.writeData('user/integers/1', 10, 19)
self.writeData('user/integers/1', 20, 29)
(data_filenames, indices_filenames, data_checksum_filenames, indices_checksum_filenames) = \
getAllFilenames(self.filename, 14, 18)
self.assertEqual(1, len(data_filenames))
self.assertEqual(1, len(indices_filenames))
self.assertEqual(1, len(data_checksum_filenames))
self.assertEqual(1, len(indices_checksum_filenames))
def test_three_partial_data_files_2(self):
self.writeData('user/integers/1', 0, 9)
self.writeData('user/integers/1', 10, 19)
self.writeData('user/integers/1', 20, 29)
(data_filenames, indices_filenames, data_checksum_filenames, indices_checksum_filenames) = \
getAllFilenames(self.filename, 4, 18)
self.assertEqual(2, len(data_filenames))
self.assertEqual(2, len(indices_filenames))
self.assertEqual(2, len(data_checksum_filenames))
self.assertEqual(2, len(indices_checksum_filenames))
def test_three_partial_data_files_3(self):
self.writeData('user/integers/1', 0, 9)
self.writeData('user/integers/1', 10, 19)
self.writeData('user/integers/1', 20, 29)
(data_filenames, indices_filenames, data_checksum_filenames, indices_checksum_filenames) = \
getAllFilenames(self.filename, 4, 28)
self.assertEqual(3, len(data_filenames))
self.assertEqual(3, len(indices_filenames))
self.assertEqual(3, len(data_checksum_filenames))
self.assertEqual(3, len(indices_checksum_filenames))
#----------------------------------------------------------
class TestCachedFileLoader(TestCachedDataBase):
def test_one_complete_data_file(self):
self.writeData('user/integers/1', 0, 9)
cached_file = CachedFileLoader()
cached_file.setup(self.filename, prefix)
self.assertEqual(10, len(cached_file))
for i in range(0, len(cached_file)):
(data, start_index, end_index) = cached_file[i]
self.assertTrue(data is not None)
self.assertEqual(i, start_index)
self.assertEqual(i, end_index)
def test_three_complete_data_files(self):
self.writeData('user/integers/1', 0, 9)
self.writeData('user/integers/1', 10, 19)
self.writeData('user/integers/1', 20, 29)
cached_file = CachedFileLoader()
cached_file.setup(self.filename, prefix)
self.assertEqual(30, len(cached_file))
for i in range(0, len(cached_file)):
(data, start_index, end_index) = cached_file[i]
self.assertTrue(data is not None)
self.assertEqual(i, start_index)
self.assertEqual(i, end_index)
def test_one_partial_data_file(self):
self.writeData('user/integers/1', 0, 9)
cached_file = CachedFileLoader()
cached_file.setup(self.filename, prefix, 2, 6)
self.assertEqual(5, len(cached_file))
for i in range(0, len(cached_file)):
(data, start_index, end_index) = cached_file[i]
self.assertTrue(data is not None)
self.assertEqual(i + 2, start_index)
self.assertEqual(i + 2, end_index)
def test_three_partial_data_files_1(self):
self.writeData('user/integers/1', 0, 9)
self.writeData('user/integers/1', 10, 19)
self.writeData('user/integers/1', 20, 29)
cached_file = CachedFileLoader()
cached_file.setup(self.filename, prefix, 14, 18)
self.assertEqual(5, len(cached_file))
for i in range(0, len(cached_file)):
(data, start_index, end_index) = cached_file[i]
self.assertTrue(data is not None)
self.assertEqual(i + 14, start_index)
self.assertEqual(i + 14, end_index)
def test_three_partial_data_files_2(self):
self.writeData('user/integers/1', 0, 9)
self.writeData('user/integers/1', 10, 19)
self.writeData('user/integers/1', 20, 29)
cached_file = CachedFileLoader()
cached_file.setup(self.filename, prefix, 4, 18)
self.assertEqual(15, len(cached_file))
for i in range(0, len(cached_file)):
(data, start_index, end_index) = cached_file[i]
self.assertTrue(data is not None)
self.assertEqual(i + 4, start_index)
self.assertEqual(i + 4, end_index)
def test_three_partial_data_files_3(self):
self.writeData('user/integers/1', 0, 9)
self.writeData('user/integers/1', 10, 19)
self.writeData('user/integers/1', 20, 29)
cached_file = CachedFileLoader()
cached_file.setup(self.filename, prefix, 4, 28)
self.assertEqual(25, len(cached_file))
for i in range(0, len(cached_file)):
(data, start_index, end_index) = cached_file[i]
self.assertTrue(data is not None)
self.assertEqual(i + 4, start_index)
self.assertEqual(i + 4, end_index)
#----------------------------------------------------------
class TestDataSink(TestCachedDataBase):
def test_creation(self):
......@@ -119,7 +311,7 @@ class TestDataSource(TestCachedDataBase):
data_source = CachedDataSource()
self.assertTrue(data_source.setup(self.filename, prefix,
force_start_index=start_index, force_end_index=end_index))
start_index=start_index, end_index=end_index))
self.assertTrue(data_source.dataformat.valid)
......
......@@ -81,9 +81,16 @@ class AsyncTest(unittest.TestCase):
container = self.host.create_container('debian:8.4', ["sdfsdfdsf329909092"])
self.assertRaises(docker.errors.NotFound, self.host.start, container)
assert not self.host.containers # All containers are gone
try:
self.host.start(container)
except Exception, e:
# The type of the exception depends on the docker version...
exc_type = type(e)
exc_type_name = exc_type.__module__ + '.' + exc_type.__name__
self.assertTrue((exc_type_name == 'docker.errors.APIError') or \
(exc_type_name == 'docker.errors.NotFound'))
self.assertFalse(self.host.containers) # All containers are gone
@slow
......
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