diff --git a/dcase_util/__init__.py b/dcase_util/__init__.py
index 28da58b6..c8f515b6 100644
--- a/dcase_util/__init__.py
+++ b/dcase_util/__init__.py
@@ -24,11 +24,49 @@ def check_installation():
"""Utility function to check package installation.
"""
- import pkg_resources
import os
- import sys
import platform
import subprocess
+ import sys
+ from importlib import metadata as importlib_metadata
+
+ from packaging.requirements import Requirement
+ from packaging.utils import canonicalize_name
+
+ def _parse_requirements(requirement_lines):
+ parsed_requirements = []
+ for requirement_line in requirement_lines:
+ line = requirement_line.strip()
+ if not line or line.startswith('#'):
+ continue
+
+ requirement = Requirement(line)
+ if requirement.marker is None or requirement.marker.evaluate():
+ parsed_requirements.append(requirement)
+
+ return parsed_requirements
+
+ def _requirements_from_file(filename):
+ if filename and os.path.isfile(filename):
+ with open(filename) as file_handle:
+ return _parse_requirements(file_handle.readlines())
+ return []
+
+ def _requirement_spec(requirement):
+ if requirement.specifier:
+ return str(requirement.specifier)
+ return '-'
+
+ def _installed_status(requirement):
+ try:
+ installed_version = importlib_metadata.version(requirement.name)
+ except importlib_metadata.PackageNotFoundError:
+ return 'N/A', 'MISSING'
+
+ if requirement.specifier and not requirement.specifier.contains(installed_version, prereleases=True):
+ return installed_version, 'CHECK'
+
+ return installed_version, 'OK'
log = ui.FancyPrinter()
@@ -53,55 +91,72 @@ def check_installation():
log.data(field='Version', value=__version__)
log.line()
- package = pkg_resources.require('dcase_util')[0]
+ package_distribution = None
+ core_requirements = []
+ requirements_filename = os.path.abspath(
+ os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'requirements.txt')
+ )
+
+ try:
+ package_distribution = importlib_metadata.distribution('dcase_util')
+ except importlib_metadata.PackageNotFoundError:
+ package_distribution = None
- # Get core requirements
- core_requirements = package.requires()
+ if package_distribution is not None:
+ core_requirements = _parse_requirements(package_distribution.requires or [])
+ package_requirements_filename = os.path.abspath(str(package_distribution.locate_file('requirements.txt')))
+ if os.path.isfile(package_requirements_filename):
+ requirements_filename = package_requirements_filename
- # Load requirements.txt
- requirements_filename = os.path.join(package.location, 'requirements.txt')
- with open(requirements_filename) as fp:
- requirements_file = fp.read()
+ if not core_requirements:
+ core_requirements = _requirements_from_file(requirements_filename)
- # Get all requirements
- all_requirements = []
- for r in pkg_resources.parse_requirements(requirements_file):
- if r.marker:
- raise ValueError("environment markers are not supported, in '%s'" % r)
- all_requirements.append(r)
+ all_requirements = _requirements_from_file(requirements_filename)
+ if not all_requirements:
+ all_requirements = list(core_requirements)
- processed = []
+ processed = set()
log.line('Core requirements')
log.row('Package', 'Required', 'Installed', 'Status', widths=[25, 15, 15, 15])
log.row_sep()
for requirement in core_requirements:
- if requirement.key not in processed:
+ requirement_name = canonicalize_name(requirement.name)
+ if requirement_name not in processed:
+ installed, status = _installed_status(requirement)
log.row(
- requirement.key,
- ''.join(requirement.specs[0]),
- pkg_resources.get_distribution(requirement.key).version,
- 'OK' if requirement.__contains__(pkg_resources.get_distribution(requirement.key)) else 'CHECK'
+ requirement.name,
+ _requirement_spec(requirement),
+ installed,
+ status
)
- processed.append(requirement.key)
+ processed.add(requirement_name)
log.line()
log.line('Extra requirements')
log.row('Package', 'Required', 'Installed', 'Status', widths=[25, 15, 15, 15])
log.row_sep()
for requirement in all_requirements:
- if requirement.key not in processed:
+ requirement_name = canonicalize_name(requirement.name)
+ if requirement_name not in processed:
+ installed, status = _installed_status(requirement)
log.row(
- requirement.key,
- ''.join(requirement.specs[0]),
- pkg_resources.get_distribution(requirement.key).version,
- 'OK' if requirement.__contains__(pkg_resources.get_distribution(requirement.key)) else 'CHECK'
+ requirement.name,
+ _requirement_spec(requirement),
+ installed,
+ status
)
- processed.append(requirement.key)
+ processed.add(requirement_name)
log.line()
# Get system level requirements
log.line('System')
- ffmpeg_info = subprocess.check_output(['ffmpeg', '-version']).decode('utf-8')
+ try:
+ ffmpeg_info = subprocess.check_output(
+ ['ffmpeg', '-version'],
+ stderr=subprocess.STDOUT
+ ).decode('utf-8')
+ except (subprocess.CalledProcessError, OSError) as error:
+ ffmpeg_info = str(error)
log.data(field='FFMPEG', value=ffmpeg_info)
diff --git a/dcase_util/containers/mapping.py b/dcase_util/containers/mapping.py
index 7f775ea7..e0d919a2 100644
--- a/dcase_util/containers/mapping.py
+++ b/dcase_util/containers/mapping.py
@@ -51,7 +51,7 @@ def load(self, filename=None):
if self.format == FileFormat.TXT or self.format == FileFormat.CSV:
map_data = {}
- with open(self.filename, 'rtU') as f:
+ with open(self.filename, 'r', newline='') as f:
for row in csv.reader(f, delimiter=self.delimiter()):
if len(row) == 2:
map_data[row[0]] = row[1]
diff --git a/dcase_util/data/manipulators.py b/dcase_util/data/manipulators.py
index 191db72b..4bb27d02 100644
--- a/dcase_util/data/manipulators.py
+++ b/dcase_util/data/manipulators.py
@@ -849,10 +849,12 @@ def aggregate(self, data=None, **kwargs):
aggregated_frame.append(numpy.cov(current_frame).flatten())
if 'kurtosis' in self.recipe:
- aggregated_frame.append(scipy.stats.kurtosis(current_frame, axis=data.time_axis))
+ kurtosis_values = scipy.stats.kurtosis(current_frame, axis=data.time_axis)
+ aggregated_frame.append(numpy.nan_to_num(kurtosis_values, nan=-3.0))
if 'skew' in self.recipe:
- aggregated_frame.append(scipy.stats.skew(current_frame, axis=data.time_axis))
+ skew_values = scipy.stats.skew(current_frame, axis=data.time_axis)
+ aggregated_frame.append(numpy.nan_to_num(skew_values, nan=0.0))
if 'flatten' in self.recipe:
if data.time_axis == 0:
diff --git a/dcase_util/datasets/datasets.py b/dcase_util/datasets/datasets.py
index a2da1217..551cb36b 100644
--- a/dcase_util/datasets/datasets.py
+++ b/dcase_util/datasets/datasets.py
@@ -1977,7 +1977,7 @@ def validation_files_random(self,
training_meta = self.train(fold=fold)
training_files = training_meta.unique_files
- random.shuffle(training_files, random.random)
+ random.shuffle(training_files)
validation_split_index = int(numpy.ceil(validation_amount * len(training_files)))
validation_files = training_files[0:validation_split_index]
@@ -2421,7 +2421,7 @@ def validation_files_balanced(self,
for scene_id, scene_label in enumerate(training_meta.unique_scene_labels):
scene_files = training_meta.filter(scene_label=scene_label).unique_files
- random.shuffle(scene_files, random.random)
+ random.shuffle(scene_files)
validation_split_index = int(numpy.ceil(validation_amount * len(scene_files)))
current_validation_files = scene_files[0:validation_split_index]
current_training_files = scene_files[validation_split_index:]
@@ -2466,7 +2466,7 @@ def validation_files_balanced(self,
for i in iteration_progress:
current_locations = list(data.keys())
- random.shuffle(current_locations, random.random)
+ random.shuffle(current_locations)
validation_split_index = int(numpy.ceil(validation_amount * len(data)))
current_validation_identifiers = current_locations[0:validation_split_index]
current_training_identifiers = current_locations[validation_split_index:]
@@ -2561,7 +2561,7 @@ def validation_files_balanced(self,
current_validation_identifiers2 = 0
for identifier1 in identifier_first_level:
current_ids = list(data[identifier1].keys())
- random.shuffle(current_ids, random.random)
+ random.shuffle(current_ids)
validation_split_index = int(numpy.ceil(validation_amount * len(current_ids)))
current_validation = current_ids[0:validation_split_index]
current_training = current_ids[validation_split_index:]
@@ -3300,7 +3300,7 @@ def validation_files_random(self,
scene_labels = self.scene_labels()
training_files = training_meta.unique_files
- random.shuffle(training_files, random.random)
+ random.shuffle(training_files)
validation_split_index = int(numpy.ceil(validation_amount * len(training_files)))
validation_files = training_files[0:validation_split_index]
@@ -3503,7 +3503,7 @@ def validation_files_balanced(self,
for i in iteration_progress:
item_ids = list(range(0, len(data[scene_label])))
- random.shuffle(item_ids, random.random)
+ random.shuffle(item_ids)
valid_percentage_index = int(numpy.ceil(validation_amount * len(item_ids)))
@@ -3604,7 +3604,7 @@ def validation_files_balanced(self,
for i in iteration_progress:
identifiers = list(data[scene_label].keys())
- random.shuffle(identifiers, random.random)
+ random.shuffle(identifiers)
valid_percentage_index = int(numpy.ceil(validation_amount * len(identifiers)))
@@ -3811,7 +3811,7 @@ def validation_files_random(self,
scene_labels = self.scene_labels()
training_files = training_meta.unique_files
- random.shuffle(training_files, random.random)
+ random.shuffle(training_files)
validation_split_index = int(numpy.ceil(validation_amount * len(training_files)))
validation_files = training_files[0:validation_split_index]
@@ -3965,7 +3965,7 @@ def validation_files_balanced(self,
for i in iteration_progress:
identifiers = list(data[scene_label].keys())
- random.shuffle(identifiers, random.random)
+ random.shuffle(identifiers)
valid_percentage_index = int(numpy.ceil(validation_amount * len(identifiers)))
@@ -4061,7 +4061,7 @@ def validation_files_balanced(self,
for i in iteration_progress:
items_id = list(range(0, len(data[scene_label])))
- random.shuffle(items_id, random.random)
+ random.shuffle(items_id)
valid_percentage_index = int(numpy.ceil(validation_amount * len(items_id)))
diff --git a/dcase_util/features/features.py b/dcase_util/features/features.py
index 2f1fee67..ce2f590d 100644
--- a/dcase_util/features/features.py
+++ b/dcase_util/features/features.py
@@ -379,18 +379,28 @@ def get_window_function(self, n, window_type='hamming_asymmetric'):
"""
+ def _window(window_name, symmetric):
+ if hasattr(scipy.signal, 'windows') and hasattr(scipy.signal.windows, window_name):
+ return getattr(scipy.signal.windows, window_name)(n, sym=symmetric)
+
+ if hasattr(scipy.signal, window_name):
+ return getattr(scipy.signal, window_name)(n, sym=symmetric)
+
+ # Fallback for compatibility across SciPy versions.
+ return scipy.signal.get_window(window_name, n, fftbins=not symmetric)
+
# Windowing function
if window_type == 'hamming_asymmetric':
- return scipy.signal.hamming(n, sym=False)
+ return _window('hamming', symmetric=False)
elif window_type == 'hamming_symmetric' or window_type == 'hamming':
- return scipy.signal.hamming(n, sym=True)
+ return _window('hamming', symmetric=True)
elif window_type == 'hann_asymmetric':
- return scipy.signal.hann(n, sym=False)
+ return _window('hann', symmetric=False)
elif window_type == 'hann_symmetric' or window_type == 'hann':
- return scipy.signal.hann(n, sym=True)
+ return _window('hann', symmetric=True)
else:
message = '{name}: Unknown window type [{window_type}]'.format(
diff --git a/dcase_util/files/serialization.py b/dcase_util/files/serialization.py
index 8602a3c5..8ee393f6 100644
--- a/dcase_util/files/serialization.py
+++ b/dcase_util/files/serialization.py
@@ -176,14 +176,28 @@ def load_msgpack(cls, filename):
import msgpack
except ImportError:
- message = '{name}: Unable to import msgpack module. You can install it with `pip install msgpack-python`.'.format(
+ message = '{name}: Unable to import msgpack module. You can install it with `pip install msgpack`.'.format(
name=cls.__class__.__name__
)
cls.logger().exception(message)
raise ImportError(message)
- return msgpack.load(open(filename, "rb"), encoding='utf-8')
+ with open(filename, 'rb') as file_handle:
+ # Keep compatibility with both modern msgpack and older environments.
+ try:
+ return msgpack.load(file_handle, raw=False, strict_map_key=False)
+ except TypeError:
+ file_handle.seek(0)
+ try:
+ return msgpack.load(file_handle, raw=False)
+ except TypeError:
+ file_handle.seek(0)
+ try:
+ return msgpack.load(file_handle, encoding='utf-8')
+ except TypeError:
+ file_handle.seek(0)
+ return msgpack.load(file_handle)
@classmethod
def load_marshal(cls, filename):
@@ -339,14 +353,15 @@ def save_msgpack(cls, filename, data):
import msgpack
except ImportError:
- message = '{name}: Unable to import msgpack module. You can install it with `pip install msgpack-python`.'.format(
+ message = '{name}: Unable to import msgpack module. You can install it with `pip install msgpack`.'.format(
name=cls.__class__.__name__
)
cls.logger().exception(message)
raise ImportError(message)
- msgpack.dump(data, open(filename, 'wb'), use_bin_type=True)
+ with open(filename, 'wb') as file_handle:
+ msgpack.dump(data, file_handle, use_bin_type=True)
@classmethod
def save_marshal(cls, filename, data):
diff --git a/dcase_util/utils/examples.py b/dcase_util/utils/examples.py
index f1836b8a..c032d20e 100644
--- a/dcase_util/utils/examples.py
+++ b/dcase_util/utils/examples.py
@@ -3,8 +3,7 @@
from __future__ import print_function, absolute_import
-import os
-import pkg_resources
+from importlib import resources
import numpy
@@ -15,21 +14,25 @@ class Example(object):
def __init__(self):
pass
+ @classmethod
+ def _resource_filename(cls, filename):
+ return str(resources.files(__package__).joinpath(cls.example_folder, filename))
+
@classmethod
def audio_filename(cls):
- return pkg_resources.resource_filename(__name__, os.path.join(cls.example_folder, 'acoustic_scene.wav'))
+ return cls._resource_filename('acoustic_scene.wav')
@classmethod
def acoustic_scene_audio_filename(cls):
- return pkg_resources.resource_filename(__name__, os.path.join(cls.example_folder, 'acoustic_scene.wav'))
+ return cls._resource_filename('acoustic_scene.wav')
@classmethod
def audio_filename_mp3(cls):
- return pkg_resources.resource_filename(__name__, os.path.join(cls.example_folder, 'acoustic_scene.mp3'))
+ return cls._resource_filename('acoustic_scene.mp3')
@classmethod
def acoustic_scene_audio_filename_mp3(cls):
- return pkg_resources.resource_filename(__name__, os.path.join(cls.example_folder, 'acoustic_scene.mp3'))
+ return cls._resource_filename('acoustic_scene.mp3')
@classmethod
def audio_container(cls):
@@ -207,4 +210,4 @@ def feature_repository(cls, filename=None):
}
}
])
- return chain.process(filename=filename)
\ No newline at end of file
+ return chain.process(filename=filename)
diff --git a/dcase_util/utils/math.py b/dcase_util/utils/math.py
index bd819f9d..c451525b 100644
--- a/dcase_util/utils/math.py
+++ b/dcase_util/utils/math.py
@@ -14,29 +14,42 @@ class SimpleMathStringEvaluator(object):
"""
def __init__(self):
+ use_legacy_pyparsing_api = False
try:
- from pyparsing import Word, nums, alphas, Combine, oneOf, opAssoc, operatorPrecedence
+ from pyparsing import Word, nums, alphas, Combine, opAssoc, one_of, infix_notation
except ImportError:
- message = '{name}: Unable to import pyparsing module. You can install it with `pip install pyparsing`.'.format(
- name=self.__class__.__name__
- )
+ try:
+ from pyparsing import Word, nums, alphas, Combine, oneOf, opAssoc, operatorPrecedence
+ one_of = oneOf
+ infix_notation = operatorPrecedence
+ use_legacy_pyparsing_api = True
- self.logger.exception(message)
- raise ImportError(message)
+ except ImportError:
+ message = '{name}: Unable to import pyparsing module. You can install it with `pip install pyparsing`.'.format(
+ name=self.__class__.__name__
+ )
+
+ self.logger.exception(message)
+ raise ImportError(message)
# Define the parser
- integer = Word(nums).setParseAction(lambda t: int(t[0]))
+ integer = Word(nums)
+ if use_legacy_pyparsing_api:
+ integer = integer.setParseAction(lambda t: int(t[0]))
+ else:
+ integer = integer.set_parse_action(lambda t: int(t[0]))
+
real = Combine(Word(nums) + "." + Word(nums))
variable = Word(alphas, exact=1)
operand = real | integer | variable
# Operators
self.operators = {
- 'sign': oneOf('+ -'),
- 'multiply': oneOf('* /'),
- 'plus': oneOf('+ -'),
- 'comparision': oneOf('< <= > >= != = <> LT GT LE GE EQ NE'),
+ 'sign': one_of('+ -'),
+ 'multiply': one_of('* /'),
+ 'plus': one_of('+ -'),
+ 'comparision': one_of('< <= > >= != = <> LT GT LE GE EQ NE'),
}
def operator_operands(token_list):
@@ -141,8 +154,12 @@ def eval(self, vars):
return True
return False
- operand.setParseAction(EvalConstant)
- self.arith_expr = operatorPrecedence(
+ if use_legacy_pyparsing_api:
+ operand.setParseAction(EvalConstant)
+ else:
+ operand.set_parse_action(EvalConstant)
+
+ self.arith_expr = infix_notation(
operand,
[
(self.operators['sign'], 1, opAssoc.RIGHT, EvalSignOp),
@@ -190,7 +207,10 @@ def eval(self, string):
except ValueError:
try:
- ret = self.arith_expr.parseString(string, parseAll=True)[0]
+ if hasattr(self.arith_expr, 'parse_string'):
+ ret = self.arith_expr.parse_string(string, parse_all=True)[0]
+ else:
+ ret = self.arith_expr.parseString(string, parseAll=True)[0]
result = ret.eval([])
return result
diff --git a/dcase_util/utils/utils.py b/dcase_util/utils/utils.py
index 417feb6f..3baca83c 100644
--- a/dcase_util/utils/utils.py
+++ b/dcase_util/utils/utils.py
@@ -9,7 +9,9 @@
import locale
import logging
import logging.config
-import pkg_resources
+from importlib import metadata as importlib_metadata
+
+from packaging.requirements import Requirement
def get_class_inheritors(klass):
@@ -104,28 +106,33 @@ def get_byte_string(num_bytes, show_bytes=True):
def check_pkg_resources(package_requirement, logger=None):
- working_set = pkg_resources.WorkingSet()
if logger is None:
logger = logging.getLogger(__name__)
- try:
- working_set.require(package_requirement)
+ requirement = Requirement(package_requirement)
+ if requirement.marker is not None and not requirement.marker.evaluate():
+ return
- except pkg_resources.VersionConflict:
- message = '{name}: Version conflict, update package [pip install {package_requirement}]'.format(
+ try:
+ installed_version = importlib_metadata.version(requirement.name)
+ except importlib_metadata.PackageNotFoundError as error:
+ message = '{name}: Package not found, install package [pip install {package_requirement}]'.format(
name=__name__,
package_requirement=package_requirement
)
logger.exception(message)
- raise
+ raise ModuleNotFoundError(message) from error
- except pkg_resources.DistributionNotFound:
- message = '{name}: Package not found, install package [pip install {package_requirement}]'.format(
+ if requirement.specifier and not requirement.specifier.contains(installed_version, prereleases=True):
+ message = '{name}: Version conflict, update package [pip install {package_requirement}]'.format(
name=__name__,
package_requirement=package_requirement
)
- logger.exception(message)
- raise
+ try:
+ raise RuntimeError(message)
+ except RuntimeError:
+ logger.exception(message)
+ raise
def is_int(value):
diff --git a/documentation/source/library.rst b/documentation/source/library.rst
index d4ed37a9..f66d806b 100644
--- a/documentation/source/library.rst
+++ b/documentation/source/library.rst
@@ -39,10 +39,10 @@ If you fix a bug, you should also add a unit test that exposes the bug to avoid
To run the tests, use::
- python setup.py nosetests
+ python -m pytest tests
-After running tests, the coverage report is located at `tests/cover/index.html`
+After running tests with coverage, the HTML report is located at `htmlcov/index.html`.
Tests are located in directory `tests`.
@@ -60,4 +60,4 @@ To create the HTML pages, use::
python setup.py build_sphinx
-The generated files will be available in the directory `docs`
\ No newline at end of file
+The generated files will be available in the directory `docs`
diff --git a/requirements.txt b/requirements.txt
index 7618385c..09ff6cbf 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,12 +1,13 @@
numpy>=1.9.2
-scipy>=0.19.1
+scipy>=1.8.0
matplotlib>=2.0.0
-librosa>=0.7.0
+librosa>=0.10.0
+resampy>=0.4.3
six>=1.10.0
future>=0.16.0
soundfile>=0.9.0
pyyaml>=5.1
-msgpack-python>=0.4.8
+msgpack>=1.0.0
ujson>=1.35
requests>=2.12.4
tqdm>=4.11.2
@@ -14,9 +15,10 @@ pydot-ng>=1.0.0
pafy>=0.5.5
youtube-dl>=2021.6.6
validators>=0.12.0
-pyparsing>=2.2.0
+pyparsing>=3.0.0
titlecase>=0.12.0
colorama>=0.3.7
python-magic>=0.4.13
markdown>=2.6.9
-jinja2>=2.6.9
\ No newline at end of file
+jinja2>=2.6.9
+packaging>=20.0
diff --git a/setup.cfg b/setup.cfg
index 86cc886e..fe959fa9 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,15 +1,6 @@
-[aliases]
-test = nosetests
-
-[nosetests]
-verbosity=0
-detailed-errors=1
-with-coverage=1
-cover-package=dcase_util
-debug=nose.loader
-pdb = 1
-pdb-failures = 1
-nocapture = 1
+[tool:pytest]
+testpaths = tests
+addopts = -ra
[build_sphinx]
source-dir = documentation/source
@@ -17,4 +8,4 @@ build-dir = docs
all_files = 1
[upload_sphinx]
-upload-dir = docs
\ No newline at end of file
+upload-dir = docs
diff --git a/setup.py b/setup.py
index c5937261..6a4f6bdb 100644
--- a/setup.py
+++ b/setup.py
@@ -2,18 +2,22 @@
requirements = [
'numpy>=1.9.2',
- 'scipy>=0.19.1',
+ 'scipy>=1.8.0',
'matplotlib>=2.0.0',
- 'librosa>=0.7.0',
+ 'librosa>=0.10.0',
+ 'resampy>=0.4.3',
'six>=1.10.0',
'future>=0.16.0',
'soundfile>=0.9.0',
'pyyaml>=3.11',
+ 'msgpack>=1.0.0',
'requests>=2.12.4',
'tqdm>=4.11.2',
'pydot-ng>= 1.0.0',
'validators>=0.12.0',
- 'python-magic>=0.4.13'
+ 'pyparsing>=3.0.0',
+ 'python-magic>=0.4.13',
+ 'packaging>=20.0'
]
try:
@@ -49,5 +53,4 @@
keywords='audio sound',
license='MIT',
install_requires=requirements,
- setup_requires=['nose>=1.3'],
)
diff --git a/tests/README.md b/tests/README.md
index 7178ed1f..73e135c7 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -3,8 +3,12 @@ Unit tests
This directory contains unit tests.
-Run ``nosetests -v`` to perform tests.
+Run ``pytest -v`` to perform tests.
With coverage run
-``nosetests -v --with-coverage --cover-erase --cover-html --cover-package=dcase_util --nocapture``
+``coverage run -m pytest -v``
+
+and then generate the report with
+
+``coverage html``
diff --git a/tests/containers/test_AppParameterContainer.py b/tests/containers/test_AppParameterContainer.py
index ef4370a2..7f4f65c9 100644
--- a/tests/containers/test_AppParameterContainer.py
+++ b/tests/containers/test_AppParameterContainer.py
@@ -1,11 +1,8 @@
""" Unit tests for AppParameterContainer """
-
-import nose.tools
import dcase_util
import tempfile
import os
-
def test_container():
# 1
param = dcase_util.containers.AppParameterContainer(
@@ -32,10 +29,10 @@ def test_container():
app_base=os.path.join(tempfile.gettempdir(), 'dcase_util_app'),
)
param.process()
- nose.tools.eq_(param['_hash'], 'fa21fe5962a01a67d7e7e4d8f5536c7c')
- nose.tools.eq_(param['feature_extraction']['_hash'], 'ef0a20431310a36b05ef942f3f5b6a5a')
+ assert param['_hash'] == 'fa21fe5962a01a67d7e7e4d8f5536c7c'
+ assert param['feature_extraction']['_hash'] == 'ef0a20431310a36b05ef942f3f5b6a5a'
- nose.tools.eq_(param['feature_extraction']['stacking_recipe'][0]['label'], 'mel')
+ assert param['feature_extraction']['stacking_recipe'][0]['label'] == 'mel'
# 2
param = dcase_util.containers.AppParameterContainer(
@@ -61,10 +58,10 @@ def test_container():
}
)
param.process()
- nose.tools.eq_(param['_hash'], 'fa21fe5962a01a67d7e7e4d8f5536c7c')
- nose.tools.eq_(param['feature_extraction']['_hash'], 'ef0a20431310a36b05ef942f3f5b6a5a')
+ assert param['_hash'] == 'fa21fe5962a01a67d7e7e4d8f5536c7c'
+ assert param['feature_extraction']['_hash'] == 'ef0a20431310a36b05ef942f3f5b6a5a'
- nose.tools.eq_(param['feature_extraction']['stacking_recipe'][0]['label'], 'mel')
+ assert param['feature_extraction']['stacking_recipe'][0]['label'] == 'mel'
# 3
param = dcase_util.containers.AppParameterContainer(
@@ -97,14 +94,11 @@ def test_container():
},
)
param.process()
- nose.tools.eq_(param['_hash'], '74501e81cabe55b4f05f001b502e5e3d')
- nose.tools.eq_(param['feature_extraction']['_hash'], '7e5e46979cd59e83662703686acd8b82')
+ assert param['_hash'] == '74501e81cabe55b4f05f001b502e5e3d'
+ assert param['feature_extraction']['_hash'] == '7e5e46979cd59e83662703686acd8b82'
- nose.tools.eq_(param['feature_extraction']['stacking_formula'][0]['label'], 'mel')
- nose.tools.eq_(
- param['directories']['external']['log'],
- os.path.join(tempfile.gettempdir(), 'dcase_util_app', 'test')
- )
+ assert param['feature_extraction']['stacking_formula'][0]['label'] == 'mel'
+ assert param['directories']['external']['log'] == os.path.join(tempfile.gettempdir(), 'dcase_util_app', 'test')
# 4
param = dcase_util.containers.AppParameterContainer(
@@ -131,9 +125,9 @@ def test_container():
app_base=os.path.join(tempfile.gettempdir(), 'dcase_util_app')
)
param.process()
- nose.tools.eq_(param['_hash'], '99914b932bd37a50b983c5e7c90ae93b')
- nose.tools.eq_(param['field1'], 100)
- nose.tools.eq_(param['set_id'], 'set1')
+ assert param['_hash'] == '99914b932bd37a50b983c5e7c90ae93b'
+ assert param['field1'] == 100
+ assert param['set_id'] == 'set1'
# 5
param = dcase_util.containers.AppParameterContainer(
@@ -210,23 +204,17 @@ def test_container():
)
param.process(create_paths=True)
- nose.tools.eq_(param['general']['field1'], 100)
- nose.tools.eq_(
- param['path']['application']['base'],
- os.path.join(tempfile.gettempdir(), 'dcase_util_app', 'system')
- )
+ assert param['general']['field1'] == 100
+ assert param['path']['application']['base'] == os.path.join(tempfile.gettempdir(), 'dcase_util_app', 'system')
- nose.tools.eq_(
- param['path']['application']['feature_extractor'],
- os.path.join(tempfile.gettempdir(), 'dcase_util_app', 'system', 'feature_extractor')
- )
+ assert param['path']['application']['feature_extractor'] == os.path.join(tempfile.gettempdir(), 'dcase_util_app', 'system', 'feature_extractor')
- nose.tools.eq_(param['feature_extractor2']['parameters']['n_mels'], 40)
+ assert param['feature_extractor2']['parameters']['n_mels'] == 40
- nose.tools.eq_(param['feature_extractor']['parameters']['mel']['n_mels'], 40)
- nose.tools.eq_(param['feature_extractor']['parameters']['mfcc']['n_mfccs'], 20)
- nose.tools.eq_(param['feature_extractor']['parameters']['mfcc']['dependency_method'], 'mel')
- nose.tools.eq_(param['feature_extractor']['parameters']['mfcc']['dependency_parameters']['n_mels'], 40)
+ assert param['feature_extractor']['parameters']['mel']['n_mels'] == 40
+ assert param['feature_extractor']['parameters']['mfcc']['n_mfccs'] == 20
+ assert param['feature_extractor']['parameters']['mfcc']['dependency_method'] == 'mel'
+ assert param['feature_extractor']['parameters']['mfcc']['dependency_parameters']['n_mels'] == 40
# 6
param = dcase_util.containers.AppParameterContainer(
@@ -274,9 +262,8 @@ def test_container():
}
}
)
- nose.tools.eq_(param['field1'], 1000)
- nose.tools.eq_(param['field2']['field3'], 222)
-
+ assert param['field1'] == 1000
+ assert param['field2']['field3'] == 222
def test_sets():
param = dcase_util.containers.AppParameterContainer(
@@ -313,17 +300,17 @@ def test_sets():
)
param.process()
- nose.tools.eq_(param['set_id'], 'set1')
- nose.tools.eq_(param['section1']['field1'], 100)
- nose.tools.eq_(param['section1']['field2'], 100)
- nose.tools.eq_(param['_hash'], '0afad0d180c377ea63b085bb6de7a9ee')
+ assert param['set_id'] == 'set1'
+ assert param['section1']['field1'] == 100
+ assert param['section1']['field2'] == 100
+ assert param['_hash'] == '0afad0d180c377ea63b085bb6de7a9ee'
- nose.tools.eq_(param.set_ids(), ['set1', 'set2', 'set3'])
+ assert param.set_ids() == ['set1', 'set2', 'set3']
param.update_parameter_set(set_id='set2')
- nose.tools.eq_(param['set_id'], 'set2')
- nose.tools.eq_(param['section1']['field1'], 200)
- nose.tools.eq_(param['section1']['field3'], 200)
- nose.tools.eq_(param['_hash'], 'd350d91259caa812c7eb363c8c065c39')
+ assert param['set_id'] == 'set2'
+ assert param['section1']['field1'] == 200
+ assert param['section1']['field3'] == 200
+ assert param['_hash'] == 'd350d91259caa812c7eb363c8c065c39'
diff --git a/tests/containers/test_AudioContainer.py b/tests/containers/test_AudioContainer.py
index caf59e1c..c140ef51 100644
--- a/tests/containers/test_AudioContainer.py
+++ b/tests/containers/test_AudioContainer.py
@@ -1,12 +1,11 @@
""" Unit tests for AudioContainer """
-import nose.tools
+import pytest
import dcase_util
import os
import numpy
import tempfile
-
def test_load():
# Mono
audio = dcase_util.containers.AudioContainer(
@@ -15,9 +14,9 @@ def test_load():
mono=True
)
- nose.tools.eq_(audio.fs, 44100)
- nose.tools.eq_(len(audio.data.shape), 1)
- nose.tools.eq_(audio.data.shape[0], 441001)
+ assert audio.fs == 44100
+ assert len(audio.data.shape) == 1
+ assert audio.data.shape[0] == 441001
# Stereo
audio = dcase_util.containers.AudioContainer(
@@ -26,9 +25,9 @@ def test_load():
mono=False
)
- nose.tools.eq_(audio.fs, 44100)
- nose.tools.eq_(audio.data.shape[0], 2)
- nose.tools.eq_(audio.data.shape[1], 441001)
+ assert audio.fs == 44100
+ assert audio.data.shape[0] == 2
+ assert audio.data.shape[1] == 441001
# Re-sampling
audio = dcase_util.containers.AudioContainer(
@@ -38,9 +37,9 @@ def test_load():
mono=True
)
- nose.tools.eq_(audio.fs, 16000)
- nose.tools.eq_(len(audio.data.shape), 1)
- nose.tools.eq_(audio.data.shape[0], 160001)
+ assert audio.fs == 16000
+ assert len(audio.data.shape) == 1
+ assert audio.data.shape[0] == 160001
# Segment
audio = dcase_util.containers.AudioContainer(
@@ -51,10 +50,9 @@ def test_load():
stop=6.0
)
- nose.tools.eq_(audio.fs, 44100)
- nose.tools.eq_(len(audio.data.shape), 1)
- nose.tools.eq_(audio.data.shape[0], 88200)
-
+ assert audio.fs == 44100
+ assert len(audio.data.shape) == 1
+ assert audio.data.shape[0] == 88200
#def test_load_youtube():
# with dcase_util.utils.DisableLogger():
@@ -64,206 +62,205 @@ def test_load():
# stop=5
# )
#
-# nose.tools.eq_(audio_container.fs, 44100)
-# nose.tools.eq_(len(audio_container.data.shape), 2)
-# nose.tools.eq_(audio_container.streams, 2)
-# nose.tools.eq_(audio_container.shape, (2, 176400))
-
+# assert audio_container.fs == 44100
+# assert len(audio_container.data.shape) == 2
+# assert audio_container.streams == 2
+# assert audio_container.shape == (2, 176400)
def test_container():
# Empty
a = dcase_util.utils.Example.audio_container()
if a:
pass
- nose.tools.eq_(a.empty, False)
- nose.tools.eq_(dcase_util.containers.AudioContainer().empty, True)
+ assert a.empty == False
+ assert dcase_util.containers.AudioContainer().empty == True
# Basic info
a = dcase_util.utils.Example.audio_container()
- nose.tools.eq_(a.fs, 44100)
- nose.tools.eq_(len(a.data.shape), 2)
- nose.tools.eq_(a.data.shape, a.shape)
- nose.tools.eq_(a.duration_ms, 2000)
- nose.tools.eq_(a.duration_sec, 2)
- nose.tools.eq_(a.duration_samples, 2*44100)
- nose.tools.eq_(a.channels, 2)
+ assert a.fs == 44100
+ assert len(a.data.shape) == 2
+ assert a.data.shape == a.shape
+ assert a.duration_ms == 2000
+ assert a.duration_sec == 2
+ assert a.duration_samples == 2*44100
+ assert a.channels == 2
# Focus #1.1
a = dcase_util.utils.Example.audio_container()
a.set_focus(start_seconds=0.5, stop_seconds=0.8)
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 2)
- nose.tools.eq_(a_focused.shape, (2, 13230))
+ assert len(a_focused.shape) == 2
+ assert a_focused.shape == (2, 13230)
# Focus #1.2
a = dcase_util.utils.Example.audio_container()
a.set_focus(start_seconds=0.5, duration_seconds=0.3)
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 2)
- nose.tools.eq_(a_focused.shape, (2, 13230))
+ assert len(a_focused.shape) == 2
+ assert a_focused.shape == (2, 13230)
# Focus #1.3
a = dcase_util.utils.Example.audio_container()
a.set_focus(start=0, duration=44100)
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 2)
- nose.tools.eq_(a_focused.shape, (2, 44100))
+ assert len(a_focused.shape) == 2
+ assert a_focused.shape == (2, 44100)
# Focus #1.4
a = dcase_util.utils.Example.audio_container()
a.set_focus(start=0, stop=44100)
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 2)
- nose.tools.eq_(a_focused.shape, (2, 44100))
+ assert len(a_focused.shape) == 2
+ assert a_focused.shape == (2, 44100)
# Focus #1.5
a = dcase_util.utils.Example.audio_container()
a.set_focus()
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 2)
- nose.tools.eq_(a_focused.shape, (2, 2*44100))
+ assert len(a_focused.shape) == 2
+ assert a_focused.shape == (2, 2*44100)
# Focus #2.1
a = dcase_util.utils.Example.audio_container()
a.focus_start_samples = int(0.2 * 44100)
a.focus_stop_samples = int(0.5 * 44100)
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 2)
- nose.tools.eq_(a_focused.shape, (2, 0.3 * 44100))
+ assert len(a_focused.shape) == 2
+ assert a_focused.shape == (2, 0.3 * 44100)
# Focus #2.2
a = dcase_util.utils.Example.audio_container()
a.focus_start_samples = 0.2 * 44100
a.focus_stop_samples = 0.5 * 44100
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 2)
- nose.tools.eq_(a_focused.shape, (2, 0.3 * 44100))
+ assert len(a_focused.shape) == 2
+ assert a_focused.shape == (2, 0.3 * 44100)
# Focus #2.3
a = dcase_util.utils.Example.audio_container()
a.focus_start_samples = 0.5 * 44100
a.focus_stop_samples = 0.2 * 44100
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 2)
- nose.tools.eq_(a_focused.shape, (2, 0.3 * 44100))
+ assert len(a_focused.shape) == 2
+ assert a_focused.shape == (2, 0.3 * 44100)
# Focus #2.4
a = dcase_util.utils.Example.audio_container()
a.focus_stop_samples = 0.2 * 44100
a.focus_start_samples = 0.5 * 44100
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 2)
- nose.tools.eq_(a_focused.shape, (2, 0.3 * 44100))
+ assert len(a_focused.shape) == 2
+ assert a_focused.shape == (2, 0.3 * 44100)
# Focus #2.5
a = dcase_util.utils.Example.audio_container()
a.focus_start_samples = 0.5 * 44100
a.focus_stop_samples = None
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 2)
- nose.tools.eq_(a_focused.shape, (2, 1.5 * 44100))
+ assert len(a_focused.shape) == 2
+ assert a_focused.shape == (2, 1.5 * 44100)
# Focus #2.6
a = dcase_util.utils.Example.audio_container()
a.focus_start_samples = None
a.focus_stop_samples = 0.5 * 44100
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 2)
- nose.tools.eq_(a_focused.shape, (2, 0.5 * 44100))
+ assert len(a_focused.shape) == 2
+ assert a_focused.shape == (2, 0.5 * 44100)
# Focus #2.7
a = dcase_util.utils.Example.audio_container()
a.focus_start_samples = 0
a.focus_stop_samples = 30 * 44100
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 2)
- nose.tools.eq_(a_focused.shape, (2, a.length))
+ assert len(a_focused.shape) == 2
+ assert a_focused.shape == (2, a.length)
# Focus #3.1
a = dcase_util.utils.Example.audio_container()
a.focus_start_seconds = 1.0
a.focus_stop_seconds = 2.0
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 2)
- nose.tools.eq_(a_focused.shape, (2, 1 * 44100))
+ assert len(a_focused.shape) == 2
+ assert a_focused.shape == (2, 1 * 44100)
# Focus #4.1
a = dcase_util.utils.Example.audio_container()
a.focus_channel = 0
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 1)
- nose.tools.eq_(a_focused.shape, (a.length, ))
+ assert len(a_focused.shape) == 1
+ assert a_focused.shape == (a.length, )
numpy.testing.assert_array_almost_equal(a_focused, a.data[0, :])
# Focus #4.2
a = dcase_util.utils.Example.audio_container()
a.focus_channel = 1
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 1)
- nose.tools.eq_(a_focused.shape, (a.length, ))
+ assert len(a_focused.shape) == 1
+ assert a_focused.shape == (a.length, )
numpy.testing.assert_array_almost_equal(a_focused, a.data[1, :])
# Focus #4.3
a = dcase_util.utils.Example.audio_container()
a.focus_channel = 'left'
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 1)
- nose.tools.eq_(a_focused.shape, (a.length, ))
+ assert len(a_focused.shape) == 1
+ assert a_focused.shape == (a.length, )
numpy.testing.assert_array_almost_equal(a_focused, a.data[0, :])
# Focus #4.4
a = dcase_util.utils.Example.audio_container()
a.focus_channel = 'right'
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 1)
- nose.tools.eq_(a_focused.shape, (a.length, ))
+ assert len(a_focused.shape) == 1
+ assert a_focused.shape == (a.length, )
numpy.testing.assert_array_almost_equal(a_focused, a.data[1, :])
# Focus #4.5
a = dcase_util.utils.Example.audio_container()
a.focus_channel = 123
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 2)
- nose.tools.eq_(a_focused.shape, (2, a.length))
+ assert len(a_focused.shape) == 2
+ assert a_focused.shape == (2, a.length)
# Focus #4.6
a = dcase_util.utils.Example.audio_container()
a.focus_channel = 0
a_focused = a.get_focused()
- nose.tools.eq_(len(a_focused.shape), 1)
- nose.tools.eq_(a_focused.shape, (a.length, ))
+ assert len(a_focused.shape) == 1
+ assert a_focused.shape == (a.length, )
# Channel average
a = dcase_util.utils.Example.audio_container()
a.mixdown()
- nose.tools.eq_(a.channels, 1)
- nose.tools.eq_(a.duration_ms, 2000)
- nose.tools.eq_(a.duration_sec, 2)
- nose.tools.eq_(a.duration_samples, 2*44100)
+ assert a.channels == 1
+ assert a.duration_ms == 2000
+ assert a.duration_sec == 2
+ assert a.duration_samples == 2*44100
# Normalization
a = dcase_util.utils.Example.audio_container()
a.normalize(headroom=0.5)
- nose.tools.eq_(a.duration_ms, 2000)
- nose.tools.eq_(a.duration_sec, 2)
- nose.tools.eq_(a.duration_samples, 2*44100)
- nose.tools.assert_almost_equal(numpy.max(numpy.abs(a.data)), 0.66666661027952101, places=6)
+ assert a.duration_ms == 2000
+ assert a.duration_sec == 2
+ assert a.duration_samples == 2*44100
+ assert numpy.max(numpy.abs(a.data)) == pytest.approx(0.66666661027952101, abs=10 ** (-(6)))
# Normalization / Mono
a = dcase_util.utils.Example.audio_container().mixdown()
a.normalize(headroom=0.5)
- nose.tools.eq_(a.duration_ms, 2000)
- nose.tools.eq_(a.duration_sec, 2)
- nose.tools.eq_(a.duration_samples, 2*44100)
- nose.tools.assert_almost_equal(numpy.max(numpy.abs(a.data)), 0.63770331161958482, places=6)
+ assert a.duration_ms == 2000
+ assert a.duration_sec == 2
+ assert a.duration_samples == 2*44100
+ assert numpy.max(numpy.abs(a.data)) == pytest.approx(0.63770331161958482, abs=10 ** (-(6)))
# Re-sampling
a = dcase_util.utils.Example.audio_container()
a.resample(target_fs=16000)
- nose.tools.eq_(a.fs, 16000)
- nose.tools.eq_(a.duration_ms, 2000)
- nose.tools.eq_(a.duration_sec, 2)
- nose.tools.eq_(a.duration_samples, 2*16000)
+ assert a.fs == 16000
+ assert a.duration_ms == 2000
+ assert a.duration_sec == 2
+ assert a.duration_samples == 2*16000
# Select channel
@@ -273,14 +270,13 @@ def test_container():
x2 = a.data[1, :]
a.mixdown()
- nose.tools.eq_(a.fs, 44100)
- nose.tools.eq_(len(a.data.shape), 1)
- nose.tools.eq_(a.data.shape, a.shape)
- nose.tools.eq_(a.duration_ms, 2000)
- nose.tools.eq_(a.duration_sec, 2)
- nose.tools.eq_(a.duration_samples, 2*44100)
- nose.tools.eq_(a.channels, 1)
-
+ assert a.fs == 44100
+ assert len(a.data.shape) == 1
+ assert a.data.shape == a.shape
+ assert a.duration_ms == 2000
+ assert a.duration_sec == 2
+ assert a.duration_samples == 2*44100
+ assert a.channels == 1
def test_save():
a_out = dcase_util.utils.Example.audio_container()
@@ -290,7 +286,7 @@ def test_save():
try:
a_out.save(filename=tmp.name, bit_depth=16)
a_in = dcase_util.containers.AudioContainer().load(filename=tmp.name)
- nose.tools.eq_(a_out.shape, a_in.shape)
+ assert a_out.shape == a_in.shape
numpy.testing.assert_array_almost_equal(a_out.data, a_in.data, decimal=4)
finally:
try:
@@ -304,7 +300,7 @@ def test_save():
try:
a_out.save(filename=tmp.name, bit_depth=24)
a_in = dcase_util.containers.AudioContainer().load(filename=tmp.name)
- nose.tools.eq_(a_out.shape, a_in.shape)
+ assert a_out.shape == a_in.shape
numpy.testing.assert_array_almost_equal(a_out.data, a_in.data, decimal=5)
finally:
try:
@@ -318,7 +314,7 @@ def test_save():
try:
a_out.save(filename=tmp.name, bit_depth=32)
a_in = dcase_util.containers.AudioContainer().load(filename=tmp.name)
- nose.tools.eq_(a_out.shape, a_in.shape)
+ assert a_out.shape == a_in.shape
numpy.testing.assert_array_almost_equal(a_out.data, a_in.data, decimal=6)
finally:
try:
@@ -327,7 +323,6 @@ def test_save():
except:
pass
-
def test_log():
with dcase_util.utils.DisableLogger():
a = dcase_util.utils.Example.audio_container()
@@ -343,40 +338,38 @@ def test_log():
a.focus_channel = 'left'
a.log()
-
def test_pad():
a = dcase_util.utils.Example.audio_container().mixdown()
a.pad(length_seconds=10)
- nose.tools.eq_(a.duration_sec, 10)
+ assert a.duration_sec == 10
a = dcase_util.utils.Example.audio_container()
a.pad(length_seconds=10)
- nose.tools.eq_(a.duration_sec, 10)
+ assert a.duration_sec == 10
a = dcase_util.utils.Example.audio_container_ch4()
a.pad(length_seconds=10)
- nose.tools.eq_(a.duration_sec, 10)
-
+ assert a.duration_sec == 10
def test_segments():
a = dcase_util.utils.Example.audio_container().mixdown()
segments, segment_meta = a.segments(segment_length=1000)
- nose.tools.eq_(len(segments), 88)
- nose.tools.eq_(len(segments), len(segment_meta))
+ assert len(segments) == 88
+ assert len(segments) == len(segment_meta)
segments, segment_meta = a.segments(segment_length_seconds=0.5)
- nose.tools.eq_(len(segments), 3)
- nose.tools.eq_(len(segments), len(segment_meta))
+ assert len(segments) == 3
+ assert len(segments) == len(segment_meta)
segments, segment_meta = a.segments(
segments=[
{'onset': 0.5, 'offset': 0.8}
]
)
- nose.tools.eq_(len(segments), 1)
- nose.tools.eq_(len(segments), len(segment_meta))
- nose.tools.eq_(segment_meta[0]['onset'], 0.5)
- nose.tools.eq_(segment_meta[0]['offset'], 0.8)
+ assert len(segments) == 1
+ assert len(segments) == len(segment_meta)
+ assert segment_meta[0]['onset'] == 0.5
+ assert segment_meta[0]['offset'] == 0.8
segments, segment_meta = a.segments(
segment_length_seconds=0.5,
@@ -387,9 +380,9 @@ def test_segments():
}
]
)
- nose.tools.eq_(len(segments), 3)
- nose.tools.eq_(len(segments), len(segment_meta))
- nose.tools.eq_(segment_meta, [
+ assert len(segments) == 3
+ assert len(segments) == len(segment_meta)
+ assert segment_meta == [
{
'onset': 0.0,
'offset': 0.5
@@ -402,37 +395,34 @@ def test_segments():
'onset': 1.3,
'offset': 1.8
}
- ])
+ ]
a = dcase_util.utils.Example.audio_container()
segments, segment_meta = a.segments(segment_length=1000)
- nose.tools.eq_(len(segments), 88)
- nose.tools.eq_(len(segments), len(segment_meta))
-
+ assert len(segments) == 88
+ assert len(segments) == len(segment_meta)
def test_frames():
a = dcase_util.utils.Example.audio_container().mixdown()
frames = a.frames(frame_length=1000, hop_length=1000)
- nose.tools.eq_(frames.shape[0], 1000)
- nose.tools.eq_(frames.shape[1], 88)
+ assert frames.shape[0] == 1000
+ assert frames.shape[1] == 88
a = dcase_util.utils.Example.audio_container()
frames = a.frames(frame_length=1000, hop_length=1000)
- nose.tools.eq_(frames.shape[0], 2)
- nose.tools.eq_(frames.shape[1], 1000)
- nose.tools.eq_(frames.shape[2], 88)
-
+ assert frames.shape[0] == 2
+ assert frames.shape[1] == 1000
+ assert frames.shape[2] == 88
-@nose.tools.raises(ValueError)
def test_focus_channel():
- with dcase_util.utils.DisableLogger():
- a = dcase_util.utils.Example.audio_container()
- a.focus_channel = 'wrong'
-
+ with pytest.raises(ValueError):
+ with dcase_util.utils.DisableLogger():
+ a = dcase_util.utils.Example.audio_container()
+ a.focus_channel = 'wrong'
-@nose.tools.raises(IOError)
def test_load_error():
- with dcase_util.utils.DisableLogger():
- dcase_util.containers.AudioContainer(
- filename='Test.test'
- ).load()
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ dcase_util.containers.AudioContainer(
+ filename='Test.test'
+ ).load()
diff --git a/tests/containers/test_Containers.py b/tests/containers/test_Containers.py
index 37709dbd..87ad8c71 100644
--- a/tests/containers/test_Containers.py
+++ b/tests/containers/test_Containers.py
@@ -1,6 +1,4 @@
""" Unit tests for Containers """
-
-import nose.tools
import tempfile
import os
from dcase_util.containers import DictContainer, ListDictContainer, OneToOneMappingContainer, FileMixin
diff --git a/tests/containers/test_DCASEAppParameterContainer.py b/tests/containers/test_DCASEAppParameterContainer.py
index 66a6f5dc..800544e0 100644
--- a/tests/containers/test_DCASEAppParameterContainer.py
+++ b/tests/containers/test_DCASEAppParameterContainer.py
@@ -1,11 +1,8 @@
""" Unit tests for AppParameterContainer """
-
-import nose.tools
import dcase_util
import tempfile
import os
-
def test_container():
param = dcase_util.containers.DCASEAppParameterContainer(
{
@@ -120,31 +117,24 @@ def test_container():
app_base=os.path.join(tempfile.gettempdir(), 'dcase_util_app'),
)
param.process()
- nose.tools.eq_(param['general']['field1'], 100)
- nose.tools.eq_(
- param['path']['application']['base'],
- os.path.join(tempfile.gettempdir(), 'dcase_util_app', 'system')
- )
- nose.tools.eq_(
- param['path']['application']['feature_extractor']['mel'],
- os.path.join(
+ assert param['general']['field1'] == 100
+ assert param['path']['application']['base'] == os.path.join(tempfile.gettempdir(), 'dcase_util_app', 'system')
+ assert param['path']['application']['feature_extractor']['mel'] == os.path.join(
tempfile.gettempdir(),
'dcase_util_app',
'system',
'feature_extractor',
'feature_extractor_32f4f694c22356bd4529290397a41bda'
)
- )
-
- nose.tools.eq_(param['feature_extractor']['hop_length_samples'], 882)
- nose.tools.eq_(param['feature_extractor']['parameters']['mel']['n_mels'], 40)
- nose.tools.eq_(param['feature_extractor']['parameters']['mfcc']['n_mfccs'], 20)
- nose.tools.eq_(param['feature_extractor']['parameters']['mfcc_delta']['width'], 9)
- nose.tools.eq_(param['feature_extractor']['parameters']['mfcc_delta']['dependency_method'], 'mfcc')
- nose.tools.eq_(param['feature_extractor']['parameters']['mfcc_delta']['dependency_parameters']['fs'], 44100)
- nose.tools.eq_(param['learner']['parameters']['nc'], 16)
+ assert param['feature_extractor']['hop_length_samples'] == 882
+ assert param['feature_extractor']['parameters']['mel']['n_mels'] == 40
+ assert param['feature_extractor']['parameters']['mfcc']['n_mfccs'] == 20
+ assert param['feature_extractor']['parameters']['mfcc_delta']['width'] == 9
+ assert param['feature_extractor']['parameters']['mfcc_delta']['dependency_method'] == 'mfcc'
+ assert param['feature_extractor']['parameters']['mfcc_delta']['dependency_parameters']['fs'] == 44100
- nose.tools.eq_(param['feature_aggregator']['hop_length_frames'], 1)
+ assert param['learner']['parameters']['nc'] == 16
+ assert param['feature_aggregator']['hop_length_frames'] == 1
diff --git a/tests/containers/test_DataMatrix2DContainer.py b/tests/containers/test_DataMatrix2DContainer.py
index 6a03eea0..893702e8 100644
--- a/tests/containers/test_DataMatrix2DContainer.py
+++ b/tests/containers/test_DataMatrix2DContainer.py
@@ -1,68 +1,65 @@
""" Unit tests for DataMatrix2DContainer """
-
-import nose.tools
import dcase_util
import tempfile
import os
import numpy
-
def test_container():
# 1
data_container = dcase_util.containers.DataMatrix2DContainer(
data=numpy.random.rand(10, 100),
time_resolution=0.02
)
- nose.tools.eq_(data_container.shape, (10, 100))
- nose.tools.eq_(data_container.length, 100)
- nose.tools.eq_(data_container.frames, 100)
- nose.tools.eq_(data_container.vector_length, 10)
+ assert data_container.shape == (10, 100)
+ assert data_container.length == 100
+ assert data_container.frames == 100
+ assert data_container.vector_length == 10
data_container.focus_start = 20
data_container.focus_stop = 40
- nose.tools.eq_(data_container.get_focused().shape, (10, 20))
+ assert data_container.get_focused().shape == (10, 20)
data_container.reset_focus()
data_container.focus_start = 40
data_container.focus_stop = 20
- nose.tools.eq_(data_container.get_focused().shape, (10, 20))
+ assert data_container.get_focused().shape == (10, 20)
data_container.reset_focus()
- nose.tools.eq_(data_container.get_focused().shape, (10, 100))
+ assert data_container.get_focused().shape == (10, 100)
data_container.reset_focus()
data_container.set_focus(start=20, stop=40)
- nose.tools.eq_(data_container.get_focused().shape, (10, 20))
+ assert data_container.get_focused().shape == (10, 20)
data_container.reset_focus()
data_container.set_focus(start_seconds=1, stop_seconds=2)
- nose.tools.eq_(data_container.get_focused().shape, (10, 50))
+ assert data_container.get_focused().shape == (10, 50)
data_container.reset_focus()
data_container.set_focus(start_seconds=1, duration_seconds=1)
- nose.tools.eq_(data_container.get_focused().shape, (10, 50))
+ assert data_container.get_focused().shape == (10, 50)
data_container.reset_focus()
data_container.set_focus(start=20, duration=20)
- nose.tools.eq_(data_container.get_focused().shape, (10, 20))
+ assert data_container.get_focused().shape == (10, 20)
data_container.freeze()
- nose.tools.eq_(data_container.shape, (10, 20))
+ assert data_container.shape == (10, 20)
# 2
data_container = dcase_util.containers.DataMatrix2DContainer(
data=numpy.random.rand(10, 100),
time_resolution=0.02
)
- nose.tools.eq_(data_container.stats['mean'].shape, (10, ))
- nose.tools.eq_(data_container.stats['std'].shape, (10,))
- nose.tools.eq_(data_container.stats['n'], 100)
+ assert data_container.stats['mean'].shape == (10, )
+ assert data_container.stats['std'].shape == (10,)
+ assert data_container.stats['n'] == 100
- nose.tools.eq_(data_container.get_frames(frame_ids=[0, 1, 2, 3]).shape, (10, 4))
- nose.tools.eq_(data_container.get_frames(frame_ids=[0, 1, 2, 3], vector_ids=[0, 1, 2]).shape, (3, 4))
- nose.tools.eq_(data_container.get_frames(frame_hop=2).shape, (10, 50))
+ assert data_container.get_frames(frame_ids=[0, 1, 2, 3]).shape == (10, 4)
+ assert data_container.get_frames(frame_ids=[0, 1, 2, 3], vector_ids=[0, 1, 2]).shape == (3, 4)
+ assert data_container.get_frames(frame_hop=2).shape == (10, 50)
# 3
data_container = dcase_util.containers.DataMatrix2DContainer(
@@ -70,18 +67,17 @@ def test_container():
time_resolution=0.02
)
transposed = data_container.T
- nose.tools.eq_(transposed.shape, (100, 10))
+ assert transposed.shape == (100, 10)
- nose.tools.eq_(transposed.get_frames(frame_ids=[0, 1, 2, 3]).shape, (4, 10))
- nose.tools.eq_(transposed.get_frames(frame_ids=[0, 1, 2, 3], vector_ids=[0, 1, 2]).shape, (4, 3))
- nose.tools.eq_(transposed.get_frames(frame_hop=2).shape, (50, 10))
+ assert transposed.get_frames(frame_ids=[0, 1, 2, 3]).shape == (4, 10)
+ assert transposed.get_frames(frame_ids=[0, 1, 2, 3], vector_ids=[0, 1, 2]).shape == (4, 3)
+ assert transposed.get_frames(frame_hop=2).shape == (50, 10)
data_container = dcase_util.containers.DataMatrix2DContainer(time_resolution=0.02)
- nose.tools.eq_(data_container.shape, (0, 0))
- nose.tools.eq_(data_container.length, 0)
- nose.tools.eq_(data_container.frames, 0)
- nose.tools.eq_(data_container.vector_length, 0)
-
+ assert data_container.shape == (0, 0)
+ assert data_container.length == 0
+ assert data_container.frames == 0
+ assert data_container.vector_length == 0
def test_log():
with dcase_util.utils.DisableLogger():
diff --git a/tests/containers/test_DataRepository.py b/tests/containers/test_DataRepository.py
index 0cd73678..599f0e91 100644
--- a/tests/containers/test_DataRepository.py
+++ b/tests/containers/test_DataRepository.py
@@ -1,12 +1,9 @@
""" Unit tests for DataMatrix2DContainer """
-
-import nose.tools
import dcase_util
import tempfile
import os
import numpy
-
def test_container():
# 1
data_repository = dcase_util.containers.DataRepository(
@@ -29,15 +26,14 @@ def test_container():
}
}
)
- nose.tools.eq_(data_repository.labels, ['label1', 'label2'])
- nose.tools.eq_(data_repository.stream_ids('label1'), ['stream0', 'stream1'])
- nose.tools.eq_(data_repository.stream_ids('label2'), ['stream0', 'stream1'])
+ assert data_repository.labels == ['label1', 'label2']
+ assert data_repository.stream_ids('label1') == ['stream0', 'stream1']
+ assert data_repository.stream_ids('label2') == ['stream0', 'stream1']
- nose.tools.eq_(data_repository.get_container(label='label1', stream_id='stream0'), {'data': 100})
+ assert data_repository.get_container(label='label1', stream_id='stream0') == {'data': 100}
data_repository.set_container(container={'data': 123}, label='label1', stream_id='stream0')
- nose.tools.eq_(data_repository.get_container(label='label1', stream_id='stream0'), {'data': 123})
-
+ assert data_repository.get_container(label='label1', stream_id='stream0') == {'data': 123}
def test_save_load():
data_repository = dcase_util.containers.DataRepository(
@@ -66,11 +62,11 @@ def test_save_load():
try:
data_repository.save(filename=tmp.name)
data_repository_loaded = dcase_util.containers.DataRepository().load(filename=tmp.name)
- nose.tools.eq_(data_repository_loaded.labels, ['label1', 'label2'])
- nose.tools.eq_(data_repository_loaded.stream_ids('label1'), ['stream0', 'stream1'])
- nose.tools.eq_(data_repository_loaded.stream_ids('label2'), ['stream0', 'stream1'])
+ assert data_repository_loaded.labels == ['label1', 'label2']
+ assert data_repository_loaded.stream_ids('label1') == ['stream0', 'stream1']
+ assert data_repository_loaded.stream_ids('label2') == ['stream0', 'stream1']
- nose.tools.eq_(data_repository_loaded.get_container(label='label1', stream_id='stream0'), {'data': 100})
+ assert data_repository_loaded.get_container(label='label1', stream_id='stream0') == {'data': 100}
finally:
try:
@@ -79,7 +75,6 @@ def test_save_load():
except:
pass
-
def test_log():
with dcase_util.utils.DisableLogger():
data_repository = dcase_util.containers.DataRepository(
diff --git a/tests/containers/test_DictContainer.py b/tests/containers/test_DictContainer.py
index d9aef6d7..a25054b2 100644
--- a/tests/containers/test_DictContainer.py
+++ b/tests/containers/test_DictContainer.py
@@ -1,9 +1,8 @@
""" Unit tests for DictFile """
-import nose.tools
+import pytest
import dcase_util
from dcase_util.containers import DictContainer
-from nose.tools import *
import os
import tempfile
import pickle
@@ -55,21 +54,20 @@
}
}
-
def test_container():
data_container = DictContainer(data)
- nose.tools.eq_(data_container.get_path(path='level1.field1'), 1)
- nose.tools.eq_(data_container.get_path(path='level1.level2a.field2'), 2)
- nose.tools.eq_(data_container.get_path(path='level1.level2b.field3'), 3)
- nose.tools.eq_(data_container.get_path(path='level1.level2a.level3a.field1'), 1)
- nose.tools.eq_(data_container.get_path(path='level1.level2a.level3a'), {'field1': 1, 'field2': 2, 'field3': 3})
- nose.tools.eq_(data_container.get_path(path='level1.level2c.*.field1'), [1, 1])
+ assert data_container.get_path(path='level1.field1') == 1
+ assert data_container.get_path(path='level1.level2a.field2') == 2
+ assert data_container.get_path(path='level1.level2b.field3') == 3
+ assert data_container.get_path(path='level1.level2a.level3a.field1') == 1
+ assert data_container.get_path(path='level1.level2a.level3a') == {'field1': 1, 'field2': 2, 'field3': 3}
+ assert data_container.get_path(path='level1.level2c.*.field1') == [1, 1]
- nose.tools.eq_(data_container.get_path(path=['level1', 'field1']), 1)
- nose.tools.eq_(data_container.get_path(path=['level1', 'level2a', 'field2']), 2)
+ assert data_container.get_path(path=['level1', 'field1']) == 1
+ assert data_container.get_path(path=['level1', 'level2a', 'field2']) == 2
- nose.tools.eq_(data_container.get_hash(), '23ffcb8de3af794547779197397ab987')
- nose.tools.eq_(data_container.get_hash_for_path(dotted_path='level1.level2c'), 'a084001c6e49eef233a95f8996d1183c')
+ assert data_container.get_hash() == '23ffcb8de3af794547779197397ab987'
+ assert data_container.get_hash_for_path(dotted_path='level1.level2c') == 'a084001c6e49eef233a95f8996d1183c'
data_container.merge(override={
'level1': {
@@ -94,26 +92,25 @@ def test_container():
}
})
- nose.tools.eq_(data_container.get_path(path='level1.field1'), 10)
- nose.tools.eq_(data_container.get_path(path='level1.level2a.field2'), 20)
- nose.tools.eq_(data_container.get_path(path='level1.level2b.field3'), 3)
+ assert data_container.get_path(path='level1.field1') == 10
+ assert data_container.get_path(path='level1.level2a.field2') == 20
+ assert data_container.get_path(path='level1.level2b.field3') == 3
data_container.set_path(path='level1.field1', new_value=100)
- nose.tools.eq_(data_container.get_path(path='level1.field1'), 100)
+ assert data_container.get_path(path='level1.field1') == 100
data_container.set_path(path='level1.level2c.*.field1', new_value=100)
- nose.tools.eq_(data_container.get_path(path='level1.level2c.*.field1'), [100, 100])
+ assert data_container.get_path(path='level1.level2c.*.field1') == [100, 100]
- nose.tools.eq_(data_container.get_hash(), '0adb9bf0f7f579e8b297b7186b0570da')
+ assert data_container.get_hash() == '0adb9bf0f7f579e8b297b7186b0570da'
data_container['_hash'] = 'test'
- nose.tools.eq_(data_container.get_hash(), '0adb9bf0f7f579e8b297b7186b0570da')
+ assert data_container.get_hash() == '0adb9bf0f7f579e8b297b7186b0570da'
data_container.set_path(path=['level1', 'field2'], new_value=100)
- nose.tools.eq_(data_container.get_path(path='level1.field2'), 100)
+ assert data_container.get_path(path='level1.field2') == 100
data_container = DictContainer(data)
- nose.tools.eq_(data_container.get_leaf_path_list(),
- ['level1.field1',
+ assert data_container.get_leaf_path_list() == ['level1.field1',
'level1.field2',
'level1.field3',
'level1.level2a.field1',
@@ -136,20 +133,18 @@ def test_container():
'level1.level2c.level3a.field3',
'level1.level2c.level3b.field1',
'level1.level2c.level3b.field2',
- 'level1.level2c.level3b.field3'])
+ 'level1.level2c.level3b.field3']
- nose.tools.eq_(data_container.get_leaf_path_list(target_field='field1'),
- ['level1.field1',
+ assert data_container.get_leaf_path_list(target_field='field1') == ['level1.field1',
'level1.level2a.field1',
'level1.level2a.level3a.field1',
'level1.level2a.level3b.field1',
'level1.level2b.field1',
'level1.level2b.level3.field1',
'level1.level2c.level3a.field1',
- 'level1.level2c.level3b.field1'])
+ 'level1.level2c.level3b.field1']
- nose.tools.eq_(data_container.get_leaf_path_list(target_field_startswith='field'),
- ['level1.field1',
+ assert data_container.get_leaf_path_list(target_field_startswith='field') == ['level1.field1',
'level1.field2',
'level1.field3',
'level1.level2a.field1',
@@ -172,18 +167,16 @@ def test_container():
'level1.level2c.level3a.field3',
'level1.level2c.level3b.field1',
'level1.level2c.level3b.field2',
- 'level1.level2c.level3b.field3'])
+ 'level1.level2c.level3b.field3']
- nose.tools.eq_(data_container.get_leaf_path_list(target_field_endswith='d1'),
- ['level1.field1',
+ assert data_container.get_leaf_path_list(target_field_endswith='d1') == ['level1.field1',
'level1.level2a.field1',
'level1.level2a.level3a.field1',
'level1.level2a.level3b.field1',
'level1.level2b.field1',
'level1.level2b.level3.field1',
'level1.level2c.level3a.field1',
- 'level1.level2c.level3b.field1'])
-
+ 'level1.level2c.level3b.field1']
def test_load():
# YAML
@@ -196,7 +189,7 @@ def test_load():
m = DictContainer().load(filename=tmp.name)
- nose.tools.assert_dict_equal(m, {'section': {'field1': 1, 'field2': 2}})
+ assert m == {'section': {'field1': 1, 'field2': 2}}
finally:
try:
tmp.close()
@@ -212,7 +205,7 @@ def test_load():
m = DictContainer().load(filename=tmp.name)
- nose.tools.assert_dict_equal(m, {'section': {'field1': 1, 'field2': 2}})
+ assert m == {'section': {'field1': 1, 'field2': 2}}
finally:
try:
tmp.close()
@@ -234,7 +227,7 @@ def test_load():
m = DictContainer().load(filename=tmp.name)
- nose.tools.assert_dict_equal(m, {'section': {'field1': 1, 'field2': 2}})
+ assert m == {'section': {'field1': 1, 'field2': 2}}
finally:
try:
tmp.close()
@@ -256,7 +249,7 @@ def test_load():
m = DictContainer().load(filename=tmp.name)
- nose.tools.assert_dict_equal(m, {'section': {'field1': 1, 'field2': 2}})
+ assert m == {'section': {'field1': 1, 'field2': 2}}
finally:
try:
tmp.close()
@@ -274,7 +267,7 @@ def test_load():
m = DictContainer().load(filename=tmp.name)
- nose.tools.assert_dict_equal(m, {0: 'line1\n', 1: 'line2\n', 2: 'line3\n'})
+ assert m == {0: 'line1\n', 1: 'line2\n', 2: 'line3\n'}
finally:
try:
tmp.close()
@@ -282,7 +275,6 @@ def test_load():
except:
pass
-
def test_save():
# Empty content
DictContainer({}).save(filename=os.path.join(tempfile.gettempdir(), 'saved.yaml'))
@@ -303,49 +295,42 @@ def test_save():
DictContainer(data2).save(filename=os.path.join(tempfile.gettempdir(), 'saved.yaml'))
d = DictContainer().load(filename=os.path.join(tempfile.gettempdir(), 'saved.yaml'))
- nose.tools.assert_dict_equal(d, data2)
-
+ assert d == data2
def test_empty():
# Test #1
d = DictContainer({})
- nose.tools.eq_(d.empty(), True)
+ assert d.empty() == True
# Test #2
d = DictContainer({'sec': 1})
- nose.tools.eq_(d.empty(), False)
-
+ assert d.empty() == False
def test_log():
with dcase_util.utils.DisableLogger():
DictContainer(filename='test.yaml').log()
-
-@raises(ValueError)
def test_wrong_path():
- with dcase_util.utils.DisableLogger():
- DictContainer(data).get_path(path=9)
-
+ with pytest.raises(ValueError):
+ with dcase_util.utils.DisableLogger():
+ DictContainer(data).get_path(path=9)
-@raises(ValueError)
def test_wrong_path2():
- with dcase_util.utils.DisableLogger():
- DictContainer(data).set_path(path=9, new_value=1)
-
+ with pytest.raises(ValueError):
+ with dcase_util.utils.DisableLogger():
+ DictContainer(data).set_path(path=9, new_value=1)
-@raises(IOError)
def test_load_not_found():
- with dcase_util.utils.DisableLogger():
- DictContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.cpickle'))
-
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ DictContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.cpickle'))
-@raises(IOError)
def test_load_wrong_type():
- with dcase_util.utils.DisableLogger():
- DictContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.wav'))
-
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ DictContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.wav'))
-@raises(IOError)
def test_load_wrong_type2():
- with dcase_util.utils.DisableLogger():
- DictContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.abc'))
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ DictContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.abc'))
diff --git a/tests/containers/test_ListContainer.py b/tests/containers/test_ListContainer.py
index 345da571..9cf42fc2 100644
--- a/tests/containers/test_ListContainer.py
+++ b/tests/containers/test_ListContainer.py
@@ -1,13 +1,11 @@
""" Unit tests for DictFile """
-import nose.tools
+import pytest
import dcase_util
from dcase_util.containers import ListContainer
-from nose.tools import *
import tempfile
import os
-
def test_load():
# Txt
tmp = tempfile.NamedTemporaryFile('r+', suffix='.txt', prefix='prefix_', dir=tempfile.gettempdir(), delete=False)
@@ -19,7 +17,7 @@ def test_load():
m = ListContainer().load(filename=tmp.name)
- nose.tools.assert_list_equal(m, ['line1', 'line2', 'line3'])
+ assert m == ['line1', 'line2', 'line3']
finally:
try:
tmp.close()
@@ -27,32 +25,29 @@ def test_load():
except:
pass
-
def test_save():
ListContainer(['line1', 'line2', 'line3']).save(filename=os.path.join(tempfile.gettempdir(), 'saved.txt'))
d = ListContainer().load(filename=os.path.join(tempfile.gettempdir(), 'saved.txt'))
- nose.tools.assert_list_equal(d, ['line1', 'line2', 'line3'])
+ assert d == ['line1', 'line2', 'line3']
f = open(os.path.join(tempfile.gettempdir(), 'saved.txt'), 'r')
x = f.readlines()
- nose.tools.assert_list_equal(x, ['line1\n', 'line2\n', 'line3\n'])
+ assert x == ['line1\n', 'line2\n', 'line3\n']
d = ListContainer(
['line1', 'line2', 'line3'],
filename=os.path.join(tempfile.gettempdir(), 'saved.cpickle')
).save().load()
- nose.tools.assert_list_equal(d, ['line1', 'line2', 'line3'])
-
+ assert d == ['line1', 'line2', 'line3']
def test_empty():
# Test #1
d = ListContainer([])
- nose.tools.eq_(d.empty(), True)
+ assert d.empty() == True
# Test #2
d = ListContainer(['line1', 'line2'])
- nose.tools.eq_(d.empty(), False)
-
+ assert d.empty() == False
def test_log():
with dcase_util.utils.DisableLogger():
@@ -60,20 +55,17 @@ def test_log():
'test1', 'test2'
], filename='test.txt').log()
-
-@raises(IOError)
def test_load_not_found2():
- with dcase_util.utils.DisableLogger():
- ListContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.txt'))
-
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ ListContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.txt'))
-@raises(IOError)
def test_load_wrong_type():
- with dcase_util.utils.DisableLogger():
- ListContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.cpickle'))
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ ListContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.cpickle'))
-
-@raises(IOError)
def test_load_wrong_type2():
- with dcase_util.utils.DisableLogger():
- ListContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.abc'))
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ ListContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.abc'))
diff --git a/tests/containers/test_ListDictContainer.py b/tests/containers/test_ListDictContainer.py
index f5e0de1c..188fd2a9 100644
--- a/tests/containers/test_ListDictContainer.py
+++ b/tests/containers/test_ListDictContainer.py
@@ -1,13 +1,11 @@
""" Unit tests for ListDictContainer """
-import nose.tools
+import pytest
import dcase_util
from dcase_util.containers import ListDictContainer
-from nose.tools import *
import tempfile
import os
-
def test_container():
data = ListDictContainer([
{
@@ -29,14 +27,13 @@ def test_container():
])
column = data.get_field(field_name='key1')
- nose.tools.eq_(column, [100, 200, 300, 400])
+ assert column == [100, 200, 300, 400]
column = data.get_field(field_name='key2')
- nose.tools.eq_(column, [400, 300, 200, 100])
-
- nose.tools.eq_(data.search(key='key1', value=100), {'key1': 100, 'key2': 400})
- nose.tools.eq_(data.search(key='key1', value=123), None)
+ assert column == [400, 300, 200, 100]
+ assert data.search(key='key1', value=100) == {'key1': 100, 'key2': 400}
+ assert data.search(key='key1', value=123) == None
def test_save():
# Empty content
@@ -63,37 +60,34 @@ def test_save():
]
d = ListDictContainer(data, filename=os.path.join(tempfile.gettempdir(), 'saved.yaml')).save().load()
- nose.tools.assert_list_equal(d, data)
+ assert d == data
d = ListDictContainer(data, filename=os.path.join(tempfile.gettempdir(), 'saved.csv')).save().load(
fields=['key1', 'key2']
)
- nose.tools.assert_list_equal(d, data)
+ assert d == data
d = ListDictContainer(data, filename=os.path.join(tempfile.gettempdir(), 'saved.csv')).save(
fields=['key1', 'key2']
).load(
fields=['key1', 'key2']
)
- nose.tools.assert_list_equal(d, data)
+ assert d == data
d = ListDictContainer(data, filename=os.path.join(tempfile.gettempdir(), 'saved.cpickle')).save().load()
- nose.tools.assert_list_equal(d, data)
-
+ assert d == data
-@raises(IOError)
def test_load_not_found2():
- with dcase_util.utils.DisableLogger():
- ListDictContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.txt'))
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ ListDictContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.txt'))
-
-@raises(IOError)
def test_load_wrong_type():
- with dcase_util.utils.DisableLogger():
- ListDictContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.cpickle'))
-
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ ListDictContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.cpickle'))
-@raises(IOError)
def test_load_wrong_type2():
- with dcase_util.utils.DisableLogger():
- ListDictContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.abc'))
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ ListDictContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.abc'))
diff --git a/tests/containers/test_Mapping.py b/tests/containers/test_Mapping.py
index 1e5aba2a..8eb961d9 100644
--- a/tests/containers/test_Mapping.py
+++ b/tests/containers/test_Mapping.py
@@ -1,13 +1,11 @@
""" Unit tests for ListDictContainer """
-import nose.tools
+import pytest
import dcase_util
from dcase_util.containers import OneToOneMappingContainer
-from nose.tools import *
import tempfile
import os
-
def test_OneToOneMappingContainer():
m = OneToOneMappingContainer(
{
@@ -17,18 +15,18 @@ def test_OneToOneMappingContainer():
'key4': 'mapped4',
}
)
- nose.tools.eq_(m.map('key1'), 'mapped1')
- nose.tools.eq_(m.map('key2'), 'mapped2')
- nose.tools.eq_(m.map('key3'), 'mapped3')
- nose.tools.eq_(m.map('key4'), 'mapped4')
- nose.tools.eq_(m.map('key5', 'default'), 'default')
+ assert m.map('key1') == 'mapped1'
+ assert m.map('key2') == 'mapped2'
+ assert m.map('key3') == 'mapped3'
+ assert m.map('key4') == 'mapped4'
+ assert m.map('key5', 'default') == 'default'
m_ = m.flipped
- nose.tools.eq_(m_.map('mapped1'), 'key1')
- nose.tools.eq_(m_.map('mapped2'), 'key2')
- nose.tools.eq_(m_.map('mapped3'), 'key3')
- nose.tools.eq_(m_.map('mapped4'), 'key4')
- nose.tools.eq_(m_.map('mapped5', 'default'), 'default')
+ assert m_.map('mapped1') == 'key1'
+ assert m_.map('mapped2') == 'key2'
+ assert m_.map('mapped3') == 'key3'
+ assert m_.map('mapped4') == 'key4'
+ assert m_.map('mapped5', 'default') == 'default'
delimiters = [',', ';', '\t']
for delimiter in delimiters:
@@ -39,8 +37,8 @@ def test_OneToOneMappingContainer():
tmp.close()
m = OneToOneMappingContainer(filename=tmp.name).load()
- nose.tools.eq_(m.map('key1'), 'mapped1')
- nose.tools.eq_(m.map('key2'), 'mapped2')
+ assert m.map('key1') == 'mapped1'
+ assert m.map('key2') == 'mapped2'
finally:
try:
tmp.close()
@@ -60,11 +58,11 @@ def test_OneToOneMappingContainer():
).save()
m_ = OneToOneMappingContainer(filename=tmp.name).load()
- nose.tools.eq_(m_.map('key1'), 'mapped1')
- nose.tools.eq_(m_.map('key2'), 'mapped2')
- nose.tools.eq_(m_.map('key3'), 'mapped3')
- nose.tools.eq_(m_.map('key4'), 'mapped4')
- nose.tools.eq_(m_.map('key5', 'default'), 'default')
+ assert m_.map('key1') == 'mapped1'
+ assert m_.map('key2') == 'mapped2'
+ assert m_.map('key3') == 'mapped3'
+ assert m_.map('key4') == 'mapped4'
+ assert m_.map('key5', 'default') == 'default'
finally:
try:
tmp.close()
@@ -72,7 +70,6 @@ def test_OneToOneMappingContainer():
except:
pass
-
def test_save():
# Empty content
OneToOneMappingContainer({}).save(filename=os.path.join(tempfile.gettempdir(), 'saved.csv'))
@@ -89,24 +86,22 @@ def test_save():
OneToOneMappingContainer(data).save(filename=os.path.join(tempfile.gettempdir(), 'saved.csv'))
d = OneToOneMappingContainer().load(filename=os.path.join(tempfile.gettempdir(), 'saved.csv'))
- nose.tools.assert_dict_equal(d, data)
+ assert d == data
OneToOneMappingContainer(data).save(filename=os.path.join(tempfile.gettempdir(), 'saved.txt'))
d = OneToOneMappingContainer().load(filename=os.path.join(tempfile.gettempdir(), 'saved.txt'))
- nose.tools.assert_dict_equal(d, data)
+ assert d == data
OneToOneMappingContainer(data).save(filename=os.path.join(tempfile.gettempdir(), 'saved.cpickle'))
d = OneToOneMappingContainer().load(filename=os.path.join(tempfile.gettempdir(), 'saved.cpickle'))
- nose.tools.assert_dict_equal(d, data)
+ assert d == data
-
-@raises(IOError)
def test_load_not_found2():
- with dcase_util.utils.DisableLogger():
- OneToOneMappingContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.txt'))
-
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ OneToOneMappingContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.txt'))
-@raises(IOError)
def test_load_wrong_type():
- with dcase_util.utils.DisableLogger():
- OneToOneMappingContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.abc'))
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ OneToOneMappingContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.abc'))
diff --git a/tests/containers/test_MetadataContainer.py b/tests/containers/test_MetadataContainer.py
index 5cba1180..0a15919b 100644
--- a/tests/containers/test_MetadataContainer.py
+++ b/tests/containers/test_MetadataContainer.py
@@ -3,8 +3,6 @@
import os
import tempfile
import numpy
-import nose.tools
-
from dcase_util.containers import MetaDataContainer
from dcase_util.utils import FieldValidator
@@ -111,8 +109,8 @@ def test_formats():
tmp.close()
item = MetaDataContainer().load(filename=tmp.name)[0]
- nose.tools.eq_(item.onset, 0.5)
- nose.tools.eq_(item.offset, 0.7)
+ assert item.onset == 0.5
+ assert item.offset == 0.7
finally:
try:
@@ -128,9 +126,9 @@ def test_formats():
tmp.close()
item = MetaDataContainer().load(filename=tmp.name)[0]
- nose.tools.eq_(item.onset, 0.5)
- nose.tools.eq_(item.offset, 0.7)
- nose.tools.eq_(item.event_label, 'event')
+ assert item.onset == 0.5
+ assert item.offset == 0.7
+ assert item.event_label == 'event'
finally:
try:
@@ -146,11 +144,11 @@ def test_formats():
tmp.close()
item = MetaDataContainer().load(filename=tmp.name)[0]
- nose.tools.eq_(item.onset, 0.5)
- nose.tools.eq_(item.offset, 0.7)
- nose.tools.eq_(item.event_label, 'event')
- nose.tools.eq_(item.filename, 'file.wav')
- nose.tools.eq_(item.scene_label, 'scene')
+ assert item.onset == 0.5
+ assert item.offset == 0.7
+ assert item.event_label == 'event'
+ assert item.filename == 'file.wav'
+ assert item.scene_label == 'scene'
finally:
try:
@@ -166,13 +164,13 @@ def test_formats():
tmp.close()
item = MetaDataContainer().load(filename=tmp.name)[0]
- nose.tools.eq_(item.onset, 0.5)
- nose.tools.eq_(item.offset, 0.7)
- nose.tools.eq_(item.event_label, 'event')
- nose.tools.eq_(item.filename, 'file.wav')
- nose.tools.eq_(item.scene_label, 'scene')
- nose.tools.eq_(item.identifier, 'a1')
- nose.tools.eq_(item.source_label, 'm')
+ assert item.onset == 0.5
+ assert item.offset == 0.7
+ assert item.event_label == 'event'
+ assert item.filename == 'file.wav'
+ assert item.scene_label == 'scene'
+ assert item.identifier == 'a1'
+ assert item.source_label == 'm'
finally:
try:
@@ -181,86 +179,84 @@ def test_formats():
except:
pass
-
def test_content():
meta = MetaDataContainer(content)
- nose.tools.eq_(len(meta), 5)
+ assert len(meta) == 5
# Test content
- nose.tools.eq_(meta[0].filename, 'audio_001.wav')
- nose.tools.eq_(meta[0].scene_label, 'office')
- nose.tools.eq_(meta[0].event_label, 'speech')
- nose.tools.eq_(meta[0].onset, 1.0)
- nose.tools.eq_(meta[0].offset, 10.0)
-
- nose.tools.eq_(meta[4].filename, 'audio_002.wav')
- nose.tools.eq_(meta[4].scene_label, 'meeting')
- nose.tools.eq_(meta[4].event_label, 'printer')
- nose.tools.eq_(meta[4].onset, 5.0)
- nose.tools.eq_(meta[4].offset, 7.0)
-
+ assert meta[0].filename == 'audio_001.wav'
+ assert meta[0].scene_label == 'office'
+ assert meta[0].event_label == 'speech'
+ assert meta[0].onset == 1.0
+ assert meta[0].offset == 10.0
+
+ assert meta[4].filename == 'audio_002.wav'
+ assert meta[4].scene_label == 'meeting'
+ assert meta[4].event_label == 'printer'
+ assert meta[4].onset == 5.0
+ assert meta[4].offset == 7.0
def test_filter():
# Test filter by file
meta = MetaDataContainer(content).filter(filename='audio_002.wav')
- nose.tools.eq_(len(meta), 2)
- nose.tools.eq_(meta[0].filename, 'audio_002.wav')
- nose.tools.eq_(meta[0].scene_label, 'meeting')
- nose.tools.eq_(meta[0].event_label, 'speech')
- nose.tools.eq_(meta[0].onset, 1.0)
- nose.tools.eq_(meta[0].offset, 9.0)
+ assert len(meta) == 2
+ assert meta[0].filename == 'audio_002.wav'
+ assert meta[0].scene_label == 'meeting'
+ assert meta[0].event_label == 'speech'
+ assert meta[0].onset == 1.0
+ assert meta[0].offset == 9.0
- nose.tools.eq_(meta[1].filename, 'audio_002.wav')
- nose.tools.eq_(meta[1].scene_label, 'meeting')
- nose.tools.eq_(meta[1].event_label, 'printer')
- nose.tools.eq_(meta[1].onset, 5.0)
- nose.tools.eq_(meta[1].offset, 7.0)
+ assert meta[1].filename == 'audio_002.wav'
+ assert meta[1].scene_label == 'meeting'
+ assert meta[1].event_label == 'printer'
+ assert meta[1].onset == 5.0
+ assert meta[1].offset == 7.0
# Test filter by scene_label
meta = MetaDataContainer(content).filter(scene_label='office')
- nose.tools.eq_(len(meta), 3)
- nose.tools.eq_(meta[0].filename, 'audio_001.wav')
- nose.tools.eq_(meta[0].scene_label, 'office')
- nose.tools.eq_(meta[0].event_label, 'speech')
- nose.tools.eq_(meta[0].onset, 1.0)
- nose.tools.eq_(meta[0].offset, 10.0)
+ assert len(meta) == 3
+ assert meta[0].filename == 'audio_001.wav'
+ assert meta[0].scene_label == 'office'
+ assert meta[0].event_label == 'speech'
+ assert meta[0].onset == 1.0
+ assert meta[0].offset == 10.0
- nose.tools.eq_(meta[1].filename, 'audio_001.wav')
- nose.tools.eq_(meta[1].scene_label, 'office')
- nose.tools.eq_(meta[1].event_label, 'mouse clicking')
- nose.tools.eq_(meta[1].onset, 3.0)
- nose.tools.eq_(meta[1].offset, 5.0)
+ assert meta[1].filename == 'audio_001.wav'
+ assert meta[1].scene_label == 'office'
+ assert meta[1].event_label == 'mouse clicking'
+ assert meta[1].onset == 3.0
+ assert meta[1].offset == 5.0
meta = MetaDataContainer(content).filter(scene_list=['meeting'])
- nose.tools.eq_(len(meta), 2)
+ assert len(meta) == 2
# Test filter by event_label
meta = MetaDataContainer(content).filter(event_label='speech')
- nose.tools.eq_(len(meta), 2)
- nose.tools.eq_(meta[0].filename, 'audio_001.wav')
- nose.tools.eq_(meta[0].scene_label, 'office')
- nose.tools.eq_(meta[0].event_label, 'speech')
- nose.tools.eq_(meta[0].onset, 1.0)
- nose.tools.eq_(meta[0].offset, 10.0)
+ assert len(meta) == 2
+ assert meta[0].filename == 'audio_001.wav'
+ assert meta[0].scene_label == 'office'
+ assert meta[0].event_label == 'speech'
+ assert meta[0].onset == 1.0
+ assert meta[0].offset == 10.0
- nose.tools.eq_(meta[1].filename, 'audio_002.wav')
- nose.tools.eq_(meta[1].scene_label, 'meeting')
- nose.tools.eq_(meta[1].event_label, 'speech')
- nose.tools.eq_(meta[1].onset, 1.0)
- nose.tools.eq_(meta[1].offset, 9.0)
+ assert meta[1].filename == 'audio_002.wav'
+ assert meta[1].scene_label == 'meeting'
+ assert meta[1].event_label == 'speech'
+ assert meta[1].onset == 1.0
+ assert meta[1].offset == 9.0
meta = MetaDataContainer(content).filter(event_list=['speech', 'printer'])
- nose.tools.eq_(len(meta), 4)
+ assert len(meta) == 4
# Test filter by tags
meta = MetaDataContainer(content3).filter(tag='tag1')
- nose.tools.eq_(len(meta), 2)
+ assert len(meta) == 2
meta = MetaDataContainer(content3).filter(tag_list=['tag1', 'tag3'])
- nose.tools.eq_(len(meta), 3)
+ assert len(meta) == 3
def test_filter_time_segment():
# Case 1
@@ -272,18 +268,18 @@ def test_filter_time_segment():
trim=True,
)
- nose.tools.eq_(len(meta), 2)
- nose.tools.eq_(meta[0].filename, 'audio_001.wav')
- nose.tools.eq_(meta[0].scene_label, 'office')
- nose.tools.eq_(meta[0].event_label, 'speech')
- nose.tools.eq_(meta[0].onset, 0.0)
- nose.tools.eq_(meta[0].offset, 2.5)
+ assert len(meta) == 2
+ assert meta[0].filename == 'audio_001.wav'
+ assert meta[0].scene_label == 'office'
+ assert meta[0].event_label == 'speech'
+ assert meta[0].onset == 0.0
+ assert meta[0].offset == 2.5
- nose.tools.eq_(meta[1].filename, 'audio_001.wav')
- nose.tools.eq_(meta[1].scene_label, 'office')
- nose.tools.eq_(meta[1].event_label, 'mouse clicking')
- nose.tools.eq_(meta[1].onset, 2.0)
- nose.tools.eq_(meta[1].offset, 2.5)
+ assert meta[1].filename == 'audio_001.wav'
+ assert meta[1].scene_label == 'office'
+ assert meta[1].event_label == 'mouse clicking'
+ assert meta[1].onset == 2.0
+ assert meta[1].offset == 2.5
# Case 2
meta = MetaDataContainer(content).filter_time_segment(
@@ -293,18 +289,18 @@ def test_filter_time_segment():
zero_time=False,
trim=True,
)
- nose.tools.eq_(len(meta), 2)
- nose.tools.eq_(meta[0].filename, 'audio_001.wav')
- nose.tools.eq_(meta[0].scene_label, 'office')
- nose.tools.eq_(meta[0].event_label, 'speech')
- nose.tools.eq_(meta[0].onset, 1.0)
- nose.tools.eq_(meta[0].offset, 3.5)
-
- nose.tools.eq_(meta[1].filename, 'audio_001.wav')
- nose.tools.eq_(meta[1].scene_label, 'office')
- nose.tools.eq_(meta[1].event_label, 'mouse clicking')
- nose.tools.eq_(meta[1].onset, 3.0)
- nose.tools.eq_(meta[1].offset, 3.5)
+ assert len(meta) == 2
+ assert meta[0].filename == 'audio_001.wav'
+ assert meta[0].scene_label == 'office'
+ assert meta[0].event_label == 'speech'
+ assert meta[0].onset == 1.0
+ assert meta[0].offset == 3.5
+
+ assert meta[1].filename == 'audio_001.wav'
+ assert meta[1].scene_label == 'office'
+ assert meta[1].event_label == 'mouse clicking'
+ assert meta[1].onset == 3.0
+ assert meta[1].offset == 3.5
# Case 3
meta = MetaDataContainer(content).filter_time_segment(
@@ -314,19 +310,18 @@ def test_filter_time_segment():
zero_time=False,
trim=False,
)
- nose.tools.eq_(len(meta), 2)
- nose.tools.eq_(meta[0].filename, 'audio_001.wav')
- nose.tools.eq_(meta[0].scene_label, 'office')
- nose.tools.eq_(meta[0].event_label, 'speech')
- nose.tools.eq_(meta[0].onset, 1.0)
- nose.tools.eq_(meta[0].offset, 10.0)
-
- nose.tools.eq_(meta[1].filename, 'audio_001.wav')
- nose.tools.eq_(meta[1].scene_label, 'office')
- nose.tools.eq_(meta[1].event_label, 'mouse clicking')
- nose.tools.eq_(meta[1].onset, 3.0)
- nose.tools.eq_(meta[1].offset, 5.0)
-
+ assert len(meta) == 2
+ assert meta[0].filename == 'audio_001.wav'
+ assert meta[0].scene_label == 'office'
+ assert meta[0].event_label == 'speech'
+ assert meta[0].onset == 1.0
+ assert meta[0].offset == 10.0
+
+ assert meta[1].filename == 'audio_001.wav'
+ assert meta[1].scene_label == 'office'
+ assert meta[1].event_label == 'mouse clicking'
+ assert meta[1].onset == 3.0
+ assert meta[1].offset == 5.0
def test_process_events():
meta = MetaDataContainer(content2).process_events(
@@ -334,37 +329,37 @@ def test_process_events():
minimum_event_length=1.0
)
- nose.tools.eq_(len(meta), 3)
+ assert len(meta) == 3
- nose.tools.eq_(meta[0].filename, 'audio_001.wav')
- nose.tools.eq_(meta[0].scene_label, 'office')
- nose.tools.eq_(meta[0].event_label, 'speech')
- nose.tools.eq_(meta[0].onset, 1.5)
- nose.tools.eq_(meta[0].offset, 3.0)
+ assert meta[0].filename == 'audio_001.wav'
+ assert meta[0].scene_label == 'office'
+ assert meta[0].event_label == 'speech'
+ assert meta[0].onset == 1.5
+ assert meta[0].offset == 3.0
- nose.tools.eq_(meta[1].filename, 'audio_001.wav')
- nose.tools.eq_(meta[1].scene_label, 'office')
- nose.tools.eq_(meta[1].event_label, 'speech')
- nose.tools.eq_(meta[1].onset, 4.0)
- nose.tools.eq_(meta[1].offset, 6.0)
+ assert meta[1].filename == 'audio_001.wav'
+ assert meta[1].scene_label == 'office'
+ assert meta[1].event_label == 'speech'
+ assert meta[1].onset == 4.0
+ assert meta[1].offset == 6.0
- nose.tools.eq_(meta[2].filename, 'audio_001.wav')
- nose.tools.eq_(meta[2].scene_label, 'office')
- nose.tools.eq_(meta[2].event_label, 'speech')
- nose.tools.eq_(meta[2].onset, 7.0)
- nose.tools.eq_(meta[2].offset, 8.0)
+ assert meta[2].filename == 'audio_001.wav'
+ assert meta[2].scene_label == 'office'
+ assert meta[2].event_label == 'speech'
+ assert meta[2].onset == 7.0
+ assert meta[2].offset == 8.0
meta = MetaDataContainer(content2).process_events(
minimum_event_gap=1.0,
minimum_event_length=1.0
)
- nose.tools.eq_(len(meta), 1)
- nose.tools.eq_(meta[0].filename, 'audio_001.wav')
- nose.tools.eq_(meta[0].scene_label, 'office')
- nose.tools.eq_(meta[0].event_label, 'speech')
- nose.tools.eq_(meta[0].onset, 1.5)
- nose.tools.eq_(meta[0].offset, 8.0)
+ assert len(meta) == 1
+ assert meta[0].filename == 'audio_001.wav'
+ assert meta[0].scene_label == 'office'
+ assert meta[0].event_label == 'speech'
+ assert meta[0].onset == 1.5
+ assert meta[0].offset == 8.0
meta = MetaDataContainer(
[
@@ -387,26 +382,24 @@ def test_process_events():
]
).process_events(minimum_event_gap=1.0, minimum_event_length=numpy.spacing(1))
- nose.tools.eq_(len(meta), 1)
-
+ assert len(meta) == 1
def test_add_time_offset():
meta = MetaDataContainer(content2).add_time(time=2.0)
- nose.tools.eq_(len(meta), 4)
+ assert len(meta) == 4
- nose.tools.eq_(meta[0].filename, 'audio_001.wav')
- nose.tools.eq_(meta[0].scene_label, 'office')
- nose.tools.eq_(meta[0].event_label, 'speech')
- nose.tools.eq_(meta[0].onset, 3.0)
- nose.tools.eq_(meta[0].offset, 3.2)
-
- nose.tools.eq_(meta[3].filename, 'audio_001.wav')
- nose.tools.eq_(meta[3].scene_label, 'office')
- nose.tools.eq_(meta[3].event_label, 'speech')
- nose.tools.eq_(meta[3].onset, 9.0)
- nose.tools.eq_(meta[3].offset, 10.0)
+ assert meta[0].filename == 'audio_001.wav'
+ assert meta[0].scene_label == 'office'
+ assert meta[0].event_label == 'speech'
+ assert meta[0].onset == 3.0
+ assert meta[0].offset == 3.2
+ assert meta[3].filename == 'audio_001.wav'
+ assert meta[3].scene_label == 'office'
+ assert meta[3].event_label == 'speech'
+ assert meta[3].onset == 9.0
+ assert meta[3].offset == 10.0
def test_addition():
meta = MetaDataContainer(content)
@@ -414,52 +407,44 @@ def test_addition():
meta += meta2
- nose.tools.eq_(len(meta), 9)
- nose.tools.eq_(meta[8].filename, 'audio_001.wav')
- nose.tools.eq_(meta[8].scene_label, 'office')
- nose.tools.eq_(meta[8].event_label, 'speech')
- nose.tools.eq_(meta[8].onset, 7.0)
- nose.tools.eq_(meta[8].offset, 8.0)
-
+ assert len(meta) == 9
+ assert meta[8].filename == 'audio_001.wav'
+ assert meta[8].scene_label == 'office'
+ assert meta[8].event_label == 'speech'
+ assert meta[8].onset == 7.0
+ assert meta[8].offset == 8.0
def test_unique_files():
files = MetaDataContainer(content).unique_files
- nose.tools.eq_(len(files), 2)
- nose.tools.eq_(files[0], 'audio_001.wav')
- nose.tools.eq_(files[1], 'audio_002.wav')
-
+ assert len(files) == 2
+ assert files[0] == 'audio_001.wav'
+ assert files[1] == 'audio_002.wav'
def test_event_count():
- nose.tools.eq_(MetaDataContainer(content).event_count, len(content))
-
+ assert MetaDataContainer(content).event_count == len(content)
def test_scene_label_count():
- nose.tools.eq_(MetaDataContainer(content).scene_label_count, 2)
-
+ assert MetaDataContainer(content).scene_label_count == 2
def test_event_label_count():
- nose.tools.eq_(MetaDataContainer(content).event_label_count, 3)
-
+ assert MetaDataContainer(content).event_label_count == 3
def test_unique_event_labels():
events = MetaDataContainer(content).unique_event_labels
- nose.tools.eq_(len(events), 3)
- nose.tools.eq_(events[0], 'mouse clicking')
- nose.tools.eq_(events[1], 'printer')
- nose.tools.eq_(events[2], 'speech')
-
+ assert len(events) == 3
+ assert events[0] == 'mouse clicking'
+ assert events[1] == 'printer'
+ assert events[2] == 'speech'
def test_unique_scene_labels():
scenes = MetaDataContainer(content).unique_scene_labels
- nose.tools.eq_(len(scenes), 2)
- nose.tools.eq_(scenes[0], 'meeting')
- nose.tools.eq_(scenes[1], 'office')
-
+ assert len(scenes) == 2
+ assert scenes[0] == 'meeting'
+ assert scenes[1] == 'office'
def test_max_event_offset():
- nose.tools.eq_(MetaDataContainer(content).max_offset, 10)
-
+ assert MetaDataContainer(content).max_offset == 10
def test_intersection():
data1 = MetaDataContainer(content)
@@ -475,9 +460,8 @@ def test_intersection():
}
])
intersection = data1.intersection(data2)
- nose.tools.eq_(len(intersection), 1)
- nose.tools.eq_(intersection[0].filename, 'audio_001.wav')
-
+ assert len(intersection) == 1
+ assert intersection[0].filename == 'audio_001.wav'
def test_map_events():
meta = MetaDataContainer(content)
@@ -485,19 +469,18 @@ def test_map_events():
target_event_label='activity',
source_event_labels=['speech', 'printer']
)
- nose.tools.eq_(len(meta_mapped_1), 4)
+ assert len(meta_mapped_1) == 4
meta_mapped_2 = meta.map_events(
target_event_label='activity'
)
- nose.tools.eq_(len(meta_mapped_2), 5)
-
+ assert len(meta_mapped_2) == 5
def test_event_inactivity():
meta = MetaDataContainer(content)
meta_inactivity = meta.event_inactivity()
- nose.tools.eq_(len(meta_inactivity), 3)
+ assert len(meta_inactivity) == 3
meta = MetaDataContainer(
[
@@ -520,8 +503,8 @@ def test_event_inactivity():
]
)
meta_inactivity = meta.event_inactivity(duration_list={'audio_001.wav': 20.0})
- nose.tools.eq_(meta_inactivity[0].onset, 0.00)
- nose.tools.eq_(meta_inactivity[0].offset, 3.00)
+ assert meta_inactivity[0].onset == 0.00
+ assert meta_inactivity[0].offset == 3.00
- nose.tools.eq_(meta_inactivity[1].onset, 5.00)
- nose.tools.eq_(meta_inactivity[1].offset, 20.00)
+ assert meta_inactivity[1].onset == 5.00
+ assert meta_inactivity[1].offset == 20.00
diff --git a/tests/containers/test_MetadataItem.py b/tests/containers/test_MetadataItem.py
index 579f2c74..907026b5 100644
--- a/tests/containers/test_MetadataItem.py
+++ b/tests/containers/test_MetadataItem.py
@@ -2,12 +2,8 @@
import os
import tempfile
-
-import nose.tools
-
from dcase_util.containers import MetaDataItem
-
def test_MetaDataItem():
item = MetaDataItem({
'filename': 'audio_001.wav',
@@ -19,43 +15,43 @@ def test_MetaDataItem():
'source_label': 'm',
})
- nose.tools.eq_(item.scene_label, 'office')
- nose.tools.eq_(item.event_label, 'speech')
- nose.tools.eq_(item.onset, 1.0)
- nose.tools.eq_(item.offset, 10.0)
- nose.tools.eq_(item.identifier, 'a001')
- nose.tools.eq_(item.source_label, 'm')
- nose.tools.eq_(item.id, '606198b478e63c2d88af9a5a07471e3d')
+ assert item.scene_label == 'office'
+ assert item.event_label == 'speech'
+ assert item.onset == 1.0
+ assert item.offset == 10.0
+ assert item.identifier == 'a001'
+ assert item.source_label == 'm'
+ assert item.id == '606198b478e63c2d88af9a5a07471e3d'
item = MetaDataItem({
'filename': 'audio_001.wav',
'scene_label': 'office',
})
- nose.tools.eq_(item.get_list(), ['audio_001.wav', 'office'])
+ assert item.get_list() == ['audio_001.wav', 'office']
item = MetaDataItem({
'filename': 'audio_001.wav',
'tags': 'cat, dog',
})
- nose.tools.eq_(item.tags, ['cat', 'dog'])
+ assert item.tags == ['cat', 'dog']
item = MetaDataItem({
'filename': 'audio_001.wav',
'tags': ['cat', 'dog']
})
- nose.tools.eq_(item.tags, ['cat', 'dog'])
+ assert item.tags == ['cat', 'dog']
item.tags = ['bird']
- nose.tools.eq_(item.tags, ['bird'])
+ assert item.tags == ['bird']
item.tags = 'bird, cat'
- nose.tools.eq_(item.tags, ['bird', 'cat'])
+ assert item.tags == ['bird', 'cat']
item.tags = 'bird;cat'
- nose.tools.eq_(item.tags, ['bird', 'cat'])
+ assert item.tags == ['bird', 'cat']
item.tags = 'bird:cat'
- nose.tools.eq_(item.tags, ['bird', 'cat'])
+ assert item.tags == ['bird', 'cat']
item.tags = 'bird#cat'
- nose.tools.eq_(item.tags, ['bird', 'cat'])
+ assert item.tags == ['bird', 'cat']
diff --git a/tests/containers/test_Mixins.py b/tests/containers/test_Mixins.py
index 921f8a4e..f5cafd44 100644
--- a/tests/containers/test_Mixins.py
+++ b/tests/containers/test_Mixins.py
@@ -1,40 +1,35 @@
""" Unit tests for Mixin """
-
-import nose.tools
import dcase_util
from dcase_util.containers import FileMixin
from dcase_util.utils import FileFormat
-from nose.tools import *
import tempfile
import os
-
def test_FileMixin_formats():
- nose.tools.eq_(FileMixin(filename='test.yaml').detect_file_format().format, FileFormat.YAML)
- nose.tools.eq_(FileMixin(filename='test.xml').detect_file_format().format, FileFormat.XML)
- nose.tools.eq_(FileMixin(filename='test.json').detect_file_format().format, FileFormat.JSON)
- nose.tools.eq_(FileMixin(filename='test.cpickle').detect_file_format().format, FileFormat.CPICKLE)
- nose.tools.eq_(FileMixin(filename='test.pickle').detect_file_format().format, FileFormat.CPICKLE)
- nose.tools.eq_(FileMixin(filename='test.pkl').detect_file_format().format, FileFormat.CPICKLE)
- nose.tools.eq_(FileMixin(filename='test.marshal').detect_file_format().format, FileFormat.MARSHAL)
- nose.tools.eq_(FileMixin(filename='test.wav').detect_file_format().format, FileFormat.WAV)
- nose.tools.eq_(FileMixin(filename='test.flac').detect_file_format().format, FileFormat.FLAC)
- nose.tools.eq_(FileMixin(filename='test.mp3').detect_file_format().format, FileFormat.MP3)
- nose.tools.eq_(FileMixin(filename='test.m4a').detect_file_format().format, FileFormat.M4A)
- nose.tools.eq_(FileMixin(filename='test.txt').detect_file_format().format, FileFormat.TXT)
- nose.tools.eq_(FileMixin(filename='test.hash').detect_file_format().format, FileFormat.TXT)
- nose.tools.eq_(FileMixin(filename='test.webm').detect_file_format().format, FileFormat.WEBM)
- nose.tools.eq_(FileMixin(filename='test.tar').detect_file_format().format, FileFormat.TAR)
- nose.tools.eq_(FileMixin(filename='test.tar.gz').detect_file_format().format, FileFormat.TAR)
- nose.tools.eq_(FileMixin(filename='test.zip').detect_file_format().format, FileFormat.ZIP)
- nose.tools.eq_(FileMixin(filename='test.csv').detect_file_format().format, FileFormat.CSV)
- nose.tools.eq_(FileMixin(filename='test.ann').detect_file_format().format, FileFormat.ANN)
-
- nose.tools.eq_(FileMixin(filename='test.zip').is_package(), True)
- nose.tools.eq_(FileMixin(filename='test.tar').is_package(), True)
- nose.tools.eq_(FileMixin(filename='test.tar.gz').is_package(), True)
- nose.tools.eq_(FileMixin(filename='test.wav').is_package(), False)
-
+ assert FileMixin(filename='test.yaml').detect_file_format().format == FileFormat.YAML
+ assert FileMixin(filename='test.xml').detect_file_format().format == FileFormat.XML
+ assert FileMixin(filename='test.json').detect_file_format().format == FileFormat.JSON
+ assert FileMixin(filename='test.cpickle').detect_file_format().format == FileFormat.CPICKLE
+ assert FileMixin(filename='test.pickle').detect_file_format().format == FileFormat.CPICKLE
+ assert FileMixin(filename='test.pkl').detect_file_format().format == FileFormat.CPICKLE
+ assert FileMixin(filename='test.marshal').detect_file_format().format == FileFormat.MARSHAL
+ assert FileMixin(filename='test.wav').detect_file_format().format == FileFormat.WAV
+ assert FileMixin(filename='test.flac').detect_file_format().format == FileFormat.FLAC
+ assert FileMixin(filename='test.mp3').detect_file_format().format == FileFormat.MP3
+ assert FileMixin(filename='test.m4a').detect_file_format().format == FileFormat.M4A
+ assert FileMixin(filename='test.txt').detect_file_format().format == FileFormat.TXT
+ assert FileMixin(filename='test.hash').detect_file_format().format == FileFormat.TXT
+ assert FileMixin(filename='test.webm').detect_file_format().format == FileFormat.WEBM
+ assert FileMixin(filename='test.tar').detect_file_format().format == FileFormat.TAR
+ assert FileMixin(filename='test.tar.gz').detect_file_format().format == FileFormat.TAR
+ assert FileMixin(filename='test.zip').detect_file_format().format == FileFormat.ZIP
+ assert FileMixin(filename='test.csv').detect_file_format().format == FileFormat.CSV
+ assert FileMixin(filename='test.ann').detect_file_format().format == FileFormat.ANN
+
+ assert FileMixin(filename='test.zip').is_package() == True
+ assert FileMixin(filename='test.tar').is_package() == True
+ assert FileMixin(filename='test.tar.gz').is_package() == True
+ assert FileMixin(filename='test.wav').is_package() == False
def test_FileMixin_delimiters():
delimiters = [',', ';', '\t']
@@ -46,7 +41,7 @@ def test_FileMixin_delimiters():
tmp.close()
item = FileMixin(filename=tmp.name)
- nose.tools.eq_(item.delimiter(), delimiter)
+ assert item.delimiter() == delimiter
finally:
try:
tmp.close()
diff --git a/tests/containers/test_ProbabilityContainer.py b/tests/containers/test_ProbabilityContainer.py
index ea033340..09f1b314 100644
--- a/tests/containers/test_ProbabilityContainer.py
+++ b/tests/containers/test_ProbabilityContainer.py
@@ -1,14 +1,11 @@
""" Unit tests for ProbabilityContainer """
+import pytest
import os
import tempfile
-from nose.tools import *
-import nose.tools
-
import dcase_util
from dcase_util.containers import ProbabilityContainer, ProbabilityItem
-
def test_item():
item = ProbabilityItem(
{
@@ -34,10 +31,9 @@ def test_item():
item.label = 'cat'
item.probability = 0.1
- nose.tools.eq_(item.filename, 'file2.wav')
- nose.tools.eq_(item.label, 'cat')
- nose.tools.eq_(item.probability, 0.1)
-
+ assert item.filename == 'file2.wav'
+ assert item.label == 'cat'
+ assert item.probability == 0.1
def test_container():
item_list = ProbabilityContainer(
@@ -65,12 +61,12 @@ def test_container():
]
)
- nose.tools.eq_(item_list.unique_labels, ['cat', 'dog'])
- nose.tools.eq_(item_list.unique_files, ['file1.wav', 'file2.wav'])
- nose.tools.eq_(len(item_list.filter(label='dog')), 2)
- nose.tools.eq_(len(item_list.filter(filename='file1.wav')), 2)
- nose.tools.eq_(len(item_list.filter(file_list=['file1.wav', 'file2.wav'])), 4)
- nose.tools.eq_(len(item_list.filter(filename='file1.wav', label='cat')), 1)
+ assert item_list.unique_labels == ['cat', 'dog']
+ assert item_list.unique_files == ['file1.wav', 'file2.wav']
+ assert len(item_list.filter(label='dog')) == 2
+ assert len(item_list.filter(filename='file1.wav')) == 2
+ assert len(item_list.filter(file_list=['file1.wav', 'file2.wav'])) == 4
+ assert len(item_list.filter(filename='file1.wav', label='cat')) == 1
item_list1 = ProbabilityContainer(
[
@@ -102,12 +98,11 @@ def test_container():
)
item_list = item_list1 + item_list2
- nose.tools.eq_(item_list.unique_labels, ['cat', 'dog'])
- nose.tools.eq_(item_list.unique_files, ['file1.wav', 'file2.wav'])
- nose.tools.eq_(len(item_list.filter(label='dog')), 2)
- nose.tools.eq_(len(item_list.filter(filename='file1.wav')), 2)
- nose.tools.eq_(len(item_list.filter(file_list=['file1.wav', 'file2.wav'])), 4)
-
+ assert item_list.unique_labels == ['cat', 'dog']
+ assert item_list.unique_files == ['file1.wav', 'file2.wav']
+ assert len(item_list.filter(label='dog')) == 2
+ assert len(item_list.filter(filename='file1.wav')) == 2
+ assert len(item_list.filter(file_list=['file1.wav', 'file2.wav'])) == 4
def test_formats():
delimiters = [',', ';', '\t']
@@ -124,17 +119,17 @@ def test_formats():
item_list = ProbabilityContainer().load(filename=tmp.name)
- nose.tools.eq_(item_list[0].filename, 'file1.wav')
- nose.tools.eq_(item_list[0].label, 'cat')
- nose.tools.eq_(item_list[0].probability, 0.7)
+ assert item_list[0].filename == 'file1.wav'
+ assert item_list[0].label == 'cat'
+ assert item_list[0].probability == 0.7
- nose.tools.eq_(item_list[1].filename, 'file1.wav')
- nose.tools.eq_(item_list[1].label, 'dog')
- nose.tools.eq_(item_list[1].probability, 0.3)
+ assert item_list[1].filename == 'file1.wav'
+ assert item_list[1].label == 'dog'
+ assert item_list[1].probability == 0.3
- nose.tools.eq_(item_list[3].filename, 'file2.wav')
- nose.tools.eq_(item_list[3].label, 'c')
- nose.tools.eq_(item_list[3].probability, 0.2)
+ assert item_list[3].filename == 'file2.wav'
+ assert item_list[3].label == 'c'
+ assert item_list[3].probability == 0.2
with dcase_util.utils.DisableLogger():
item_list.log()
@@ -146,23 +141,21 @@ def test_formats():
except:
pass
-
-@raises(IOError)
def test_unknown_formats():
- with dcase_util.utils.DisableLogger():
- tmp = tempfile.NamedTemporaryFile('r+', suffix='.txt', dir=tempfile.gettempdir(), delete=False)
- try:
- tmp.write('file1.wav' + ',' + 'cat\n')
- tmp.close()
- item_list = ProbabilityContainer().load(filename=tmp.name)
-
- finally:
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ tmp = tempfile.NamedTemporaryFile('r+', suffix='.txt', dir=tempfile.gettempdir(), delete=False)
try:
+ tmp.write('file1.wav' + ',' + 'cat\n')
tmp.close()
- os.unlink(tmp.name)
- except:
- pass
+ item_list = ProbabilityContainer().load(filename=tmp.name)
+ finally:
+ try:
+ tmp.close()
+ os.unlink(tmp.name)
+ except:
+ pass
def test_save():
tmp = tempfile.NamedTemporaryFile('r+', suffix='.txt', dir=tempfile.gettempdir(), delete=False)
@@ -193,13 +186,13 @@ def test_save():
filename=tmp.name
).save().load()
- nose.tools.eq_(item_list[0].filename, 'file1.wav')
- nose.tools.eq_(item_list[0].label, 'cat')
- nose.tools.eq_(item_list[0].probability, 0.123456789)
+ assert item_list[0].filename == 'file1.wav'
+ assert item_list[0].label == 'cat'
+ assert item_list[0].probability == 0.123456789
- nose.tools.eq_(item_list[1].filename, 'file1.wav')
- nose.tools.eq_(item_list[1].label, 'dog')
- nose.tools.eq_(item_list[1].probability, 0.234)
+ assert item_list[1].filename == 'file1.wav'
+ assert item_list[1].label == 'dog'
+ assert item_list[1].probability == 0.234
finally:
try:
tmp.close()
@@ -235,13 +228,13 @@ def test_save():
filename=tmp.name
).save().load()
- nose.tools.eq_(item_list[0].filename, 'file1.wav')
- nose.tools.eq_(item_list[0].label, 'c')
- nose.tools.eq_(item_list[0].probability, 0.123456789)
+ assert item_list[0].filename == 'file1.wav'
+ assert item_list[0].label == 'c'
+ assert item_list[0].probability == 0.123456789
- nose.tools.eq_(item_list[2].filename, 'file2.wav')
- nose.tools.eq_(item_list[2].label, 'ca')
- nose.tools.eq_(item_list[2].probability, 0.123456789)
+ assert item_list[2].filename == 'file2.wav'
+ assert item_list[2].label == 'ca'
+ assert item_list[2].probability == 0.123456789
finally:
try:
tmp.close()
@@ -249,20 +242,17 @@ def test_save():
except:
pass
-
-@raises(IOError)
def test_load_not_found():
- with dcase_util.utils.DisableLogger():
- ProbabilityContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.cpickle'))
-
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ ProbabilityContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.cpickle'))
-@raises(IOError)
def test_load_wrong_type():
- with dcase_util.utils.DisableLogger():
- ProbabilityContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.wav'))
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ ProbabilityContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.wav'))
-
-@raises(IOError)
def test_load_wrong_type2():
- with dcase_util.utils.DisableLogger():
- ProbabilityContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.abc'))
+ with pytest.raises(IOError):
+ with dcase_util.utils.DisableLogger():
+ ProbabilityContainer().load(filename=os.path.join(tempfile.gettempdir(), 'wrong.abc'))
diff --git a/tests/data/test_Aggregator.py b/tests/data/test_Aggregator.py
index 2521254d..b30cd916 100644
--- a/tests/data/test_Aggregator.py
+++ b/tests/data/test_Aggregator.py
@@ -1,6 +1,4 @@
""" Unit tests for Aggregator """
-
-import nose.tools
import os
import numpy
import tempfile
@@ -25,7 +23,6 @@
]
).T
-
def test_aggregate():
data_target = numpy.array(
[
@@ -133,7 +130,6 @@ def test_aggregate():
data_aggregated = agg.aggregate(data=container)
numpy.testing.assert_array_equal(data_target, data_aggregated.data)
-
def test_aggregate_flatten():
data_target = numpy.array(
[
@@ -163,7 +159,6 @@ def test_aggregate_flatten():
numpy.testing.assert_array_equal(data_target, data_aggregated.data)
-
def test_aggregate_mean():
data_target = numpy.array(
[
@@ -194,7 +189,6 @@ def test_aggregate_mean():
numpy.testing.assert_array_equal(data_target, data_aggregated.data)
-
def test_aggregate_std():
data_target = numpy.array(
[
@@ -225,7 +219,6 @@ def test_aggregate_std():
numpy.testing.assert_array_equal(data_target, data_aggregated.data)
-
def test_aggregate_cov():
data_target = numpy.array(
[
@@ -256,7 +249,6 @@ def test_aggregate_cov():
numpy.testing.assert_array_equal(data_target, data_aggregated.data)
-
def test_aggregate_kurtosis():
data_target = numpy.array(
[
@@ -287,7 +279,6 @@ def test_aggregate_kurtosis():
numpy.testing.assert_array_equal(data_target, data_aggregated.data)
-
def test_aggregate_skew():
data_target = numpy.array(
[
@@ -318,7 +309,6 @@ def test_aggregate_skew():
numpy.testing.assert_array_equal(data_target, data_aggregated.data)
-
def test_save():
data_target = numpy.array(
[
@@ -356,7 +346,6 @@ def test_save():
except:
pass
-
def test_log():
with dcase_util.utils.DisableLogger():
Aggregator(
diff --git a/tests/data/test_BinaryMatrixEncoder.py b/tests/data/test_BinaryMatrixEncoder.py
index 0a73d329..3a29583f 100644
--- a/tests/data/test_BinaryMatrixEncoder.py
+++ b/tests/data/test_BinaryMatrixEncoder.py
@@ -4,7 +4,6 @@
from dcase_util.data import BinaryMatrixEncoder
-
def test_log():
with dcase_util.utils.DisableLogger():
BinaryMatrixEncoder(
diff --git a/tests/data/test_DataBuffer.py b/tests/data/test_DataBuffer.py
index 59d51925..133f6599 100644
--- a/tests/data/test_DataBuffer.py
+++ b/tests/data/test_DataBuffer.py
@@ -1,44 +1,40 @@
""" Unit tests for FIFOBuffer """
-
-import nose.tools
import numpy
import dcase_util
from dcase_util.containers import MetaDataContainer
from dcase_util.data import DataBuffer
-
def test_DataBuffer():
buf = DataBuffer(size=2)
- nose.tools.eq_(buf.count, 0)
- nose.tools.eq_(buf.full, False)
+ assert buf.count == 0
+ assert buf.full == False
buf.set(key='key1', data=[1, 2, 3], meta='metadata1')
- nose.tools.eq_(buf.count, 1)
- nose.tools.eq_(buf.full, False)
+ assert buf.count == 1
+ assert buf.full == False
buf.set(key='key2', data=[2, 3, 4], meta='metadata2')
- nose.tools.eq_(buf.count, 2)
- nose.tools.eq_(buf.full, True)
+ assert buf.count == 2
+ assert buf.full == True
item_data, item_meta = buf.get(key='key1')
- nose.tools.eq_(item_data, [1, 2, 3])
- nose.tools.eq_(item_meta, 'metadata1')
+ assert item_data == [1, 2, 3]
+ assert item_meta == 'metadata1'
item_data, item_meta = buf.get(key='key2')
- nose.tools.eq_(item_data, [2, 3, 4])
- nose.tools.eq_(item_meta, 'metadata2')
+ assert item_data == [2, 3, 4]
+ assert item_meta == 'metadata2'
buf.set(key='key3', data=[3, 4, 5], meta='metadata3')
item_data, item_meta = buf.get(key='key3')
- nose.tools.eq_(item_data, [3, 4, 5])
- nose.tools.eq_(item_meta, 'metadata3')
+ assert item_data == [3, 4, 5]
+ assert item_meta == 'metadata3'
- nose.tools.eq_(buf.get(key='key4'), (None, None))
+ assert buf.get(key='key4') == (None, None)
- nose.tools.eq_(buf.count, 2)
+ assert buf.count == 2
buf.clear()
- nose.tools.eq_(buf.count, 0)
-
+ assert buf.count == 0
def test_log():
with dcase_util.utils.DisableLogger():
diff --git a/tests/data/test_EventRollEncoder.py b/tests/data/test_EventRollEncoder.py
index 5556b869..32078dcc 100644
--- a/tests/data/test_EventRollEncoder.py
+++ b/tests/data/test_EventRollEncoder.py
@@ -1,13 +1,10 @@
""" Unit tests for EventRollEncoder """
-
-import nose.tools
import numpy
import dcase_util
from dcase_util.containers import MetaDataContainer
from dcase_util.data import EventRollEncoder
-
def test_construction():
minimal_event_list = [
{'event_label': 'A', 'onset': 0, 'offset': 1, },
@@ -44,9 +41,8 @@ def test_construction():
).encode(metadata_container=meta)
numpy.testing.assert_array_equal(target_event_roll, event_roll.data)
- nose.tools.assert_equal(event_roll.shape[0], target_event_roll.shape[0])
- nose.tools.assert_equal(event_roll.shape[1], target_event_roll.shape[1])
-
+ assert event_roll.shape[0] == target_event_roll.shape[0]
+ assert event_roll.shape[1] == target_event_roll.shape[1]
def test_pad():
minimal_event_list = [
@@ -88,17 +84,16 @@ def test_pad():
)
numpy.testing.assert_array_equal(target_event_roll, event_roll.data)
- nose.tools.assert_equal(event_roll.shape[0], target_event_roll.shape[0])
- nose.tools.assert_equal(event_roll.shape[1], target_event_roll.shape[1])
+ assert event_roll.shape[0] == target_event_roll.shape[0]
+ assert event_roll.shape[1] == target_event_roll.shape[1]
padded_event_roll = roller.pad(length=18)
- nose.tools.assert_equal(padded_event_roll.length, 18)
- nose.tools.assert_equal(padded_event_roll.shape[1], event_roll.shape[1])
+ assert padded_event_roll.length == 18
+ assert padded_event_roll.shape[1] == event_roll.shape[1]
padded_event_roll = roller.pad(length=10)
- nose.tools.assert_equal(padded_event_roll.length, 10)
- nose.tools.assert_equal(padded_event_roll.shape[1], event_roll.shape[1])
-
+ assert padded_event_roll.length == 10
+ assert padded_event_roll.shape[1] == event_roll.shape[1]
def test_log():
with dcase_util.utils.DisableLogger():
diff --git a/tests/data/test_ManyHotEncoder.py b/tests/data/test_ManyHotEncoder.py
index b54ec315..bea8850f 100644
--- a/tests/data/test_ManyHotEncoder.py
+++ b/tests/data/test_ManyHotEncoder.py
@@ -1,13 +1,12 @@
""" Unit tests for OneHotEncoder """
-import nose.tools
+import pytest
import numpy
import dcase_util
from dcase_util.containers import MetaDataContainer
from dcase_util.data import ManyHotEncoder
-
def test_construction():
minimal_event_list = [
{'scene_label': 'A'},
@@ -34,8 +33,8 @@ def test_construction():
)
numpy.testing.assert_array_equal(target_binary_matrix, binary_matrix.data)
- nose.tools.assert_equal(binary_matrix.shape[0], target_binary_matrix.shape[0])
- nose.tools.assert_equal(binary_matrix.shape[1], target_binary_matrix.shape[1])
+ assert binary_matrix.shape[0] == target_binary_matrix.shape[0]
+ assert binary_matrix.shape[1] == target_binary_matrix.shape[1]
target_binary_matrix = numpy.array([
[0., 1., 0.], # 0
@@ -53,9 +52,8 @@ def test_construction():
)
numpy.testing.assert_array_equal(target_binary_matrix, binary_matrix.data)
- nose.tools.assert_equal(binary_matrix.shape[0], target_binary_matrix.shape[0])
- nose.tools.assert_equal(binary_matrix.shape[1], target_binary_matrix.shape[1])
-
+ assert binary_matrix.shape[0] == target_binary_matrix.shape[0]
+ assert binary_matrix.shape[1] == target_binary_matrix.shape[1]
def test_log():
with dcase_util.utils.DisableLogger():
@@ -65,15 +63,14 @@ def test_log():
filename='test.cpickle'
).log()
-
-@nose.tools.raises(ValueError)
def test_unknown_label():
- with dcase_util.utils.DisableLogger():
- ManyHotEncoder(
- label_list=['A', 'B', 'C'],
- time_resolution=1.0,
- filename='test.cpickle'
- ).encode(
- label_list=['BB'],
- length_seconds=3,
- )
+ with pytest.raises(ValueError):
+ with dcase_util.utils.DisableLogger():
+ ManyHotEncoder(
+ label_list=['A', 'B', 'C'],
+ time_resolution=1.0,
+ filename='test.cpickle'
+ ).encode(
+ label_list=['BB'],
+ length_seconds=3,
+ )
diff --git a/tests/data/test_Normalizer.py b/tests/data/test_Normalizer.py
index 6c344f74..2dab2eb5 100644
--- a/tests/data/test_Normalizer.py
+++ b/tests/data/test_Normalizer.py
@@ -1,12 +1,9 @@
""" Unit tests for Normalizer """
-
-import nose.tools
import numpy
import dcase_util
from dcase_util.data import Normalizer
-
def test_normalize():
# Load audio and extract mel features
@@ -51,8 +48,7 @@ def test_normalize():
normalizer.s1,
numpy.sum(container.data, axis=container.time_axis)
)
- nose.tools.eq_(normalizer.n, 501)
-
+ assert normalizer.n == 501
def test_log():
with dcase_util.utils.DisableLogger():
diff --git a/tests/data/test_OneHotEncoder.py b/tests/data/test_OneHotEncoder.py
index 2ce5821b..fd404463 100644
--- a/tests/data/test_OneHotEncoder.py
+++ b/tests/data/test_OneHotEncoder.py
@@ -1,13 +1,12 @@
""" Unit tests for OneHotEncoder """
-import nose.tools
+import pytest
import numpy
import dcase_util
from dcase_util.containers import MetaDataContainer
from dcase_util.data import OneHotEncoder
-
def test_construction():
minimal_event_list = [
{'scene_label': 'A'},
@@ -34,8 +33,8 @@ def test_construction():
)
numpy.testing.assert_array_equal(target_binary_matrix, binary_matrix.data)
- nose.tools.assert_equal(binary_matrix.shape[0], target_binary_matrix.shape[0])
- nose.tools.assert_equal(binary_matrix.shape[1], target_binary_matrix.shape[1])
+ assert binary_matrix.shape[0] == target_binary_matrix.shape[0]
+ assert binary_matrix.shape[1] == target_binary_matrix.shape[1]
target_binary_matrix = numpy.array([
[0., 1., 0.], # 0
@@ -53,9 +52,8 @@ def test_construction():
)
numpy.testing.assert_array_equal(target_binary_matrix, binary_matrix.data)
- nose.tools.assert_equal(binary_matrix.shape[0], target_binary_matrix.shape[0])
- nose.tools.assert_equal(binary_matrix.shape[1], target_binary_matrix.shape[1])
-
+ assert binary_matrix.shape[0] == target_binary_matrix.shape[0]
+ assert binary_matrix.shape[1] == target_binary_matrix.shape[1]
def test_log():
with dcase_util.utils.DisableLogger():
@@ -65,15 +63,14 @@ def test_log():
filename='test.cpickle'
).log()
-
-@nose.tools.raises(ValueError)
def test_unknown_label():
- with dcase_util.utils.DisableLogger():
- OneHotEncoder(
- label_list=['A', 'B', 'C'],
- time_resolution=1.0,
- filename='test.cpickle'
- ).encode(
- label='BB',
- length_seconds=3,
- )
+ with pytest.raises(ValueError):
+ with dcase_util.utils.DisableLogger():
+ OneHotEncoder(
+ label_list=['A', 'B', 'C'],
+ time_resolution=1.0,
+ filename='test.cpickle'
+ ).encode(
+ label='BB',
+ length_seconds=3,
+ )
diff --git a/tests/data/test_Sequencer.py b/tests/data/test_Sequencer.py
index 39019e27..7af48ecb 100644
--- a/tests/data/test_Sequencer.py
+++ b/tests/data/test_Sequencer.py
@@ -1,13 +1,10 @@
""" Unit tests for Sequencer """
-
-import nose.tools
import tempfile
import os
import numpy
import dcase_util
from dcase_util.data import Sequencer
-
def test_sequence():
# Get data in container
container = dcase_util.containers.FeatureContainer(
@@ -24,9 +21,9 @@ def test_sequence():
data=container
)
# Check shape
- nose.tools.eq_(sequenced_data.length, 10)
- nose.tools.eq_(sequenced_data.vector_length, 3)
- nose.tools.eq_(sequenced_data.data.shape, (3, 10, 10))
+ assert sequenced_data.length == 10
+ assert sequenced_data.vector_length == 3
+ assert sequenced_data.data.shape == (3, 10, 10)
# Check content
numpy.testing.assert_equal(sequenced_data.data[0, :, 0], numpy.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))
@@ -42,9 +39,9 @@ def test_sequence():
data=container
)
# Check shape
- nose.tools.eq_(sequenced_data.length, 10)
- nose.tools.eq_(sequenced_data.vector_length, 3)
- nose.tools.eq_(sequenced_data.data.shape, (3, 10, 91))
+ assert sequenced_data.length == 10
+ assert sequenced_data.vector_length == 3
+ assert sequenced_data.data.shape == (3, 10, 91)
# Check content
numpy.testing.assert_equal(sequenced_data.data[0, :, 0], numpy.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))
@@ -96,9 +93,9 @@ def test_sequence():
hop_length=10,
)
sequenced_data = sequencer.sequence(data=container)
- nose.tools.eq_(sequenced_data.length, 10)
- nose.tools.eq_(sequenced_data.vector_length, 40)
- nose.tools.eq_(sequenced_data.data.shape, (40, 10, 50))
+ assert sequenced_data.length == 10
+ assert sequenced_data.vector_length == 40
+ assert sequenced_data.data.shape == (40, 10, 50)
sequencer = Sequencer(
sequence_length=10,
@@ -106,10 +103,9 @@ def test_sequence():
)
sequenced_data = sequencer.sequence(data=container)
- nose.tools.eq_(sequenced_data.length, 10)
- nose.tools.eq_(sequenced_data.vector_length, 40)
- nose.tools.eq_(sequenced_data.data.shape, (40, 10, 492))
-
+ assert sequenced_data.length == 10
+ assert sequenced_data.vector_length == 40
+ assert sequenced_data.data.shape == (40, 10, 492)
def test_save():
@@ -152,9 +148,9 @@ def test_save():
).save(filename=tmp.name).load()
sequenced_data = sequencer.sequence(data=container)
- nose.tools.eq_(sequenced_data.length, 10)
- nose.tools.eq_(sequenced_data.vector_length, 40)
- nose.tools.eq_(sequenced_data.data.shape, (40, 10, 50))
+ assert sequenced_data.length == 10
+ assert sequenced_data.vector_length == 40
+ assert sequenced_data.data.shape == (40, 10, 50)
finally:
try:
@@ -163,7 +159,6 @@ def test_save():
except:
pass
-
def test_log():
with dcase_util.utils.DisableLogger():
Sequencer(
diff --git a/tests/data/test_Stacker.py b/tests/data/test_Stacker.py
index c4a187b7..c6ed53f3 100644
--- a/tests/data/test_Stacker.py
+++ b/tests/data/test_Stacker.py
@@ -1,13 +1,10 @@
""" Unit tests for Stacker """
-
-import nose.tools
import tempfile
import os
import dcase_util
from dcase_util.data import Stacker
-
def test_stack():
# Load audio and extract mel features
param = {
@@ -46,32 +43,31 @@ def test_stack():
stacked_data = Stacker(recipe='mel').stack(repository=repository)
- nose.tools.eq_(stacked_data.length, 501)
- nose.tools.eq_(stacked_data.vector_length, param['feature_extraction']['n_mels'])
+ assert stacked_data.length == 501
+ assert stacked_data.vector_length == param['feature_extraction']['n_mels']
stacked_data = Stacker(recipe='mel=0-5').stack(repository=repository)
- nose.tools.eq_(stacked_data.length, 501)
- nose.tools.eq_(stacked_data.vector_length, 6)
+ assert stacked_data.length == 501
+ assert stacked_data.vector_length == 6
stacked_data = Stacker(recipe='mel=1-5').stack(repository=repository)
- nose.tools.eq_(stacked_data.length, 501)
- nose.tools.eq_(stacked_data.vector_length, 5)
+ assert stacked_data.length == 501
+ assert stacked_data.vector_length == 5
stacked_data = Stacker(recipe='mel=1,2,3,4').stack(repository=repository)
- nose.tools.eq_(stacked_data.length, 501)
- nose.tools.eq_(stacked_data.vector_length, 4)
+ assert stacked_data.length == 501
+ assert stacked_data.vector_length == 4
stacked_data = Stacker(recipe='mel;mfcc=1-10').stack(repository=repository)
- nose.tools.eq_(stacked_data.length, 501)
- nose.tools.eq_(stacked_data.vector_length, 50)
+ assert stacked_data.length == 501
+ assert stacked_data.vector_length == 50
stacked_data = Stacker(recipe='mel=0;mfcc=0:1-10').stack(repository=repository)
- nose.tools.eq_(stacked_data.length, 501)
- nose.tools.eq_(stacked_data.vector_length, 50)
-
+ assert stacked_data.length == 501
+ assert stacked_data.vector_length == 50
def test_save():
# Load audio and extract mel features
@@ -113,31 +109,31 @@ def test_save():
try:
stacked_data = Stacker(recipe='mel').stack(repository=repository).save(filename=tmp.name).load()
- nose.tools.eq_(stacked_data.length, 501)
- nose.tools.eq_(stacked_data.vector_length, param['feature_extraction']['n_mels'])
+ assert stacked_data.length == 501
+ assert stacked_data.vector_length == param['feature_extraction']['n_mels']
stacked_data = Stacker(recipe='mel=0-5').stack(repository=repository)
- nose.tools.eq_(stacked_data.length, 501)
- nose.tools.eq_(stacked_data.vector_length, 6)
+ assert stacked_data.length == 501
+ assert stacked_data.vector_length == 6
stacked_data = Stacker(recipe='mel=1-5').stack(repository=repository)
- nose.tools.eq_(stacked_data.length, 501)
- nose.tools.eq_(stacked_data.vector_length, 5)
+ assert stacked_data.length == 501
+ assert stacked_data.vector_length == 5
stacked_data = Stacker(recipe='mel=1,2,3,4').stack(repository=repository)
- nose.tools.eq_(stacked_data.length, 501)
- nose.tools.eq_(stacked_data.vector_length, 4)
+ assert stacked_data.length == 501
+ assert stacked_data.vector_length == 4
stacked_data = Stacker(recipe='mel;mfcc=1-10').stack(repository=repository)
- nose.tools.eq_(stacked_data.length, 501)
- nose.tools.eq_(stacked_data.vector_length, 50)
+ assert stacked_data.length == 501
+ assert stacked_data.vector_length == 50
stacked_data = Stacker(recipe='mel=0;mfcc=0:1-10').stack(repository=repository)
- nose.tools.eq_(stacked_data.length, 501)
- nose.tools.eq_(stacked_data.vector_length, 50)
+ assert stacked_data.length == 501
+ assert stacked_data.vector_length == 50
finally:
try:
@@ -146,7 +142,6 @@ def test_save():
except:
pass
-
def test_log():
with dcase_util.utils.DisableLogger():
Stacker(recipe='mel', filename='Stacker.cpickle').log()
diff --git a/tests/datasets/test_Datasets.py b/tests/datasets/test_Datasets.py
index e065f989..dd994999 100644
--- a/tests/datasets/test_Datasets.py
+++ b/tests/datasets/test_Datasets.py
@@ -1,6 +1,5 @@
""" Unit tests for Datasets """
import os
-import nose.tools
import dcase_util
import tempfile
from dcase_util.datasets import Dataset
@@ -44,22 +43,20 @@
},
]
-
def test_dataset():
d = Dataset()
d.meta_container = MetaDataContainer(content)
- nose.tools.eq_(d.scene_labels(), ['meeting', 'office'])
- nose.tools.eq_(d.scene_label_count(), 2)
- nose.tools.eq_(d.event_labels(), ['mouse clicking', 'printer', 'speech'])
- nose.tools.eq_(d.event_label_count(), 3)
-
- nose.tools.eq_(d.meta_count, len(content))
- nose.tools.eq_(d.meta, content)
+ assert d.scene_labels() == ['meeting', 'office']
+ assert d.scene_label_count() == 2
+ assert d.event_labels() == ['mouse clicking', 'printer', 'speech']
+ assert d.event_label_count() == 3
- nose.tools.eq_(d.file_meta(filename='audio_001.wav'), [content[0], content[1], content[2]])
- nose.tools.eq_(d.file_meta(filename='audio_002.wav'), [content[3], content[4]])
+ assert d.meta_count == len(content)
+ assert d.meta == content
+ assert d.file_meta(filename='audio_001.wav') == [content[0], content[1], content[2]]
+ assert d.file_meta(filename='audio_002.wav') == [content[3], content[4]]
def test_dataset_construction():
dcase_util.datasets.TUTUrbanAcousticScenes_2018_DevelopmentSet(
@@ -134,46 +131,45 @@ def test_dataset_construction():
included_content_types=['meta']
)
-
def test_TUTAcousticScenes_2016_DevelopmentSet():
db = dcase_util.datasets.TUTAcousticScenes_2016_DevelopmentSet(
included_content_types=['meta']
).initialize()
# Cross-validation setup / Train
- nose.tools.eq_(db.train().file_count, 1170)
- nose.tools.eq_(db.train(1).file_count, 880)
- nose.tools.eq_(db.train(2).file_count, 880)
- nose.tools.eq_(db.train(3).file_count, 872)
- nose.tools.eq_(db.train(4).file_count, 878)
+ assert db.train().file_count == 1170
+ assert db.train(1).file_count == 880
+ assert db.train(2).file_count == 880
+ assert db.train(3).file_count == 872
+ assert db.train(4).file_count == 878
# Cross-validation setup / Test
- nose.tools.eq_(db.test().file_count, 1170)
- nose.tools.eq_(db.test(1).file_count, 290)
- nose.tools.eq_(db.test(2).file_count, 290)
- nose.tools.eq_(db.test(3).file_count, 298)
- nose.tools.eq_(db.test(4).file_count, 292)
+ assert db.test().file_count == 1170
+ assert db.test(1).file_count == 290
+ assert db.test(2).file_count == 290
+ assert db.test(3).file_count == 298
+ assert db.test(4).file_count == 292
- nose.tools.eq_(db.eval().file_count, 1170)
- nose.tools.eq_(db.eval(1).file_count, 290)
- nose.tools.eq_(db.eval(2).file_count, 290)
- nose.tools.eq_(db.eval(3).file_count, 298)
- nose.tools.eq_(db.eval(4).file_count, 292)
+ assert db.eval().file_count == 1170
+ assert db.eval(1).file_count == 290
+ assert db.eval(2).file_count == 290
+ assert db.eval(3).file_count == 298
+ assert db.eval(4).file_count == 292
- nose.tools.eq_(set(db.train_files(1)).intersection(db.test_files(1)), set())
- nose.tools.eq_(set(db.train_files(2)).intersection(db.test_files(2)), set())
- nose.tools.eq_(set(db.train_files(3)).intersection(db.test_files(3)), set())
- nose.tools.eq_(set(db.train_files(4)).intersection(db.test_files(4)), set())
+ assert set(db.train_files(1)).intersection(db.test_files(1)) == set()
+ assert set(db.train_files(2)).intersection(db.test_files(2)) == set()
+ assert set(db.train_files(3)).intersection(db.test_files(3)) == set()
+ assert set(db.train_files(4)).intersection(db.test_files(4)) == set()
- nose.tools.eq_(db.audio_files, [])
- nose.tools.eq_(db.audio_file_count, 0)
+ assert db.audio_files == []
+ assert db.audio_file_count == 0
- nose.tools.eq_(len(db.meta), 1170)
- nose.tools.eq_(db.meta_count, 1170)
+ assert len(db.meta) == 1170
+ assert db.meta_count == 1170
- nose.tools.eq_(db.fold_count, 4)
+ assert db.fold_count == 4
- nose.tools.eq_(db.scene_labels(), ['beach',
+ assert db.scene_labels() == ['beach',
'bus',
'cafe/restaurant',
'car',
@@ -187,50 +183,48 @@ def test_TUTAcousticScenes_2016_DevelopmentSet():
'park',
'residential_area',
'train',
- 'tram'])
- nose.tools.eq_(db.scene_label_count(), 15)
+ 'tram']
+ assert db.scene_label_count() == 15
- nose.tools.eq_(db.check_filelist(), True)
+ assert db.check_filelist() == True
- nose.tools.eq_(db.folds(), [1, 2, 3, 4])
- nose.tools.eq_(db.folds('full'), ['all_data'])
+ assert db.folds() == [1, 2, 3, 4]
+ assert db.folds('full') == ['all_data']
with dcase_util.utils.DisableLogger():
db.log()
-
def test_TUTAcousticScenes_2016_EvaluationSet():
db = dcase_util.datasets.TUTAcousticScenes_2016_EvaluationSet(
included_content_types=['meta']
).initialize()
# Cross-validation setup / Train
- nose.tools.eq_(db.train().file_count, 0)
+ assert db.train().file_count == 0
# Cross-validation setup / Test
- nose.tools.eq_(db.test().file_count, 390)
+ assert db.test().file_count == 390
- nose.tools.eq_(db.eval().file_count, 390)
+ assert db.eval().file_count == 390
- nose.tools.eq_(db.audio_files, [])
- nose.tools.eq_(db.audio_file_count, 0)
+ assert db.audio_files == []
+ assert db.audio_file_count == 0
- nose.tools.eq_(len(db.meta), 390)
- nose.tools.eq_(db.meta_count, 390)
+ assert len(db.meta) == 390
+ assert db.meta_count == 390
- nose.tools.eq_(db.fold_count, None)
+ assert db.fold_count == None
- nose.tools.eq_(db.scene_label_count(), 15)
+ assert db.scene_label_count() == 15
- nose.tools.eq_(db.check_filelist(), True)
+ assert db.check_filelist() == True
- nose.tools.eq_(db.folds(), ['all_data'])
- nose.tools.eq_(db.folds('full'), ['all_data'])
+ assert db.folds() == ['all_data']
+ assert db.folds('full') == ['all_data']
with dcase_util.utils.DisableLogger():
db.log()
-
def test_TUTAcousticScenes_2017_DevelopmentSet():
db = dcase_util.datasets.TUTAcousticScenes_2017_DevelopmentSet(
included_content_types=['meta']
@@ -244,63 +238,63 @@ def test_TUTAcousticScenes_2017_DevelopmentSet():
)
# Cross-validation setup / Train
- nose.tools.eq_(db.train().file_count, 4680)
- nose.tools.eq_(db.train(1).file_count, 3510)
- nose.tools.eq_(db.train(2).file_count, 3507)
- nose.tools.eq_(db.train(3).file_count, 3507)
- nose.tools.eq_(db.train(4).file_count, 3510)
-
- nose.tools.eq_(db.train_files()[0], os.path.join(audio_path, 'a001_0_10.wav'))
- nose.tools.eq_(db.train_files(1)[0], os.path.join(audio_path, 'a001_0_10.wav'))
- nose.tools.eq_(db.train_files(2)[0], os.path.join(audio_path, 'a001_0_10.wav'))
- nose.tools.eq_(db.train_files(3)[0], os.path.join(audio_path, 'a001_0_10.wav'))
- nose.tools.eq_(db.train_files(4)[0], os.path.join(audio_path, 'a002_0_10.wav'))
+ assert db.train().file_count == 4680
+ assert db.train(1).file_count == 3510
+ assert db.train(2).file_count == 3507
+ assert db.train(3).file_count == 3507
+ assert db.train(4).file_count == 3510
+
+ assert db.train_files()[0] == os.path.join(audio_path, 'a001_0_10.wav')
+ assert db.train_files(1)[0] == os.path.join(audio_path, 'a001_0_10.wav')
+ assert db.train_files(2)[0] == os.path.join(audio_path, 'a001_0_10.wav')
+ assert db.train_files(3)[0] == os.path.join(audio_path, 'a001_0_10.wav')
+ assert db.train_files(4)[0] == os.path.join(audio_path, 'a002_0_10.wav')
# Cross-validation setup / Test
- nose.tools.eq_(db.test().file_count, 4680)
- nose.tools.eq_(db.test(1).file_count, 1170)
- nose.tools.eq_(db.test(2).file_count, 1173)
- nose.tools.eq_(db.test(3).file_count, 1173)
- nose.tools.eq_(db.test(4).file_count, 1170)
-
- nose.tools.eq_(db.test_files()[0], os.path.join(audio_path, 'a001_0_10.wav'))
- nose.tools.eq_(db.test_files(1)[0], os.path.join(audio_path, 'a002_0_10.wav'))
- nose.tools.eq_(db.test_files(2)[0], os.path.join(audio_path, 'a005_0_10.wav'))
- nose.tools.eq_(db.test_files(3)[0], os.path.join(audio_path, 'a010_0_10.wav'))
- nose.tools.eq_(db.test_files(4)[0], os.path.join(audio_path, 'a001_0_10.wav'))
-
- nose.tools.eq_(db.eval().file_count, 4680)
- nose.tools.eq_(db.eval(1).file_count, 1170)
- nose.tools.eq_(db.eval(2).file_count, 1173)
- nose.tools.eq_(db.eval(3).file_count, 1173)
- nose.tools.eq_(db.eval(4).file_count, 1170)
-
- nose.tools.eq_(db.eval_files()[0], os.path.join(audio_path, 'a001_0_10.wav'))
- nose.tools.eq_(db.eval_files(1)[0], os.path.join(audio_path, 'a002_0_10.wav'))
- nose.tools.eq_(db.eval_files(2)[0], os.path.join(audio_path, 'a005_0_10.wav'))
- nose.tools.eq_(db.eval_files(3)[0], os.path.join(audio_path, 'a010_0_10.wav'))
- nose.tools.eq_(db.eval_files(4)[0], os.path.join(audio_path, 'a001_0_10.wav'))
-
- nose.tools.eq_(set(db.train_files(1)).intersection(db.test_files(1)), set())
- nose.tools.eq_(set(db.train_files(2)).intersection(db.test_files(2)), set())
- nose.tools.eq_(set(db.train_files(3)).intersection(db.test_files(3)), set())
- nose.tools.eq_(set(db.train_files(4)).intersection(db.test_files(4)), set())
-
- nose.tools.eq_(db[0].filename, os.path.join(audio_path, 'b020_90_100.wav'))
- nose.tools.eq_(db[0].scene_label, 'beach')
-
- nose.tools.eq_(db.audio_files, [])
- nose.tools.eq_(db.audio_file_count, 0)
-
- nose.tools.eq_(len(db.meta), 4680)
- nose.tools.eq_(db.meta_count, 4680)
-
- nose.tools.eq_(len(db.error_meta), 84)
- nose.tools.eq_(db.error_meta_count, 84)
-
- nose.tools.eq_(db.fold_count, 4)
-
- nose.tools.eq_(db.scene_labels(), ['beach',
+ assert db.test().file_count == 4680
+ assert db.test(1).file_count == 1170
+ assert db.test(2).file_count == 1173
+ assert db.test(3).file_count == 1173
+ assert db.test(4).file_count == 1170
+
+ assert db.test_files()[0] == os.path.join(audio_path, 'a001_0_10.wav')
+ assert db.test_files(1)[0] == os.path.join(audio_path, 'a002_0_10.wav')
+ assert db.test_files(2)[0] == os.path.join(audio_path, 'a005_0_10.wav')
+ assert db.test_files(3)[0] == os.path.join(audio_path, 'a010_0_10.wav')
+ assert db.test_files(4)[0] == os.path.join(audio_path, 'a001_0_10.wav')
+
+ assert db.eval().file_count == 4680
+ assert db.eval(1).file_count == 1170
+ assert db.eval(2).file_count == 1173
+ assert db.eval(3).file_count == 1173
+ assert db.eval(4).file_count == 1170
+
+ assert db.eval_files()[0] == os.path.join(audio_path, 'a001_0_10.wav')
+ assert db.eval_files(1)[0] == os.path.join(audio_path, 'a002_0_10.wav')
+ assert db.eval_files(2)[0] == os.path.join(audio_path, 'a005_0_10.wav')
+ assert db.eval_files(3)[0] == os.path.join(audio_path, 'a010_0_10.wav')
+ assert db.eval_files(4)[0] == os.path.join(audio_path, 'a001_0_10.wav')
+
+ assert set(db.train_files(1)).intersection(db.test_files(1)) == set()
+ assert set(db.train_files(2)).intersection(db.test_files(2)) == set()
+ assert set(db.train_files(3)).intersection(db.test_files(3)) == set()
+ assert set(db.train_files(4)).intersection(db.test_files(4)) == set()
+
+ assert db[0].filename == os.path.join(audio_path, 'b020_90_100.wav')
+ assert db[0].scene_label == 'beach'
+
+ assert db.audio_files == []
+ assert db.audio_file_count == 0
+
+ assert len(db.meta) == 4680
+ assert db.meta_count == 4680
+
+ assert len(db.error_meta) == 84
+ assert db.error_meta_count == 84
+
+ assert db.fold_count == 4
+
+ assert db.scene_labels() == ['beach',
'bus',
'cafe/restaurant',
'car',
@@ -314,10 +308,10 @@ def test_TUTAcousticScenes_2017_DevelopmentSet():
'park',
'residential_area',
'train',
- 'tram'])
- nose.tools.eq_(db.scene_label_count(), 15)
+ 'tram']
+ assert db.scene_label_count() == 15
- nose.tools.eq_(db.check_filelist(), True)
+ assert db.check_filelist() == True
with dcase_util.utils.DisableLogger():
rand_train, rand_validation = db.validation_split(
@@ -328,7 +322,7 @@ def test_TUTAcousticScenes_2017_DevelopmentSet():
verbose=False
)
- nose.tools.eq_(set(rand_train).intersection(rand_validation), set())
+ assert set(rand_train).intersection(rand_validation) == set()
with dcase_util.utils.DisableLogger():
bal_train, bal_validation = db.validation_split(
@@ -339,102 +333,82 @@ def test_TUTAcousticScenes_2017_DevelopmentSet():
verbose=False
)
- nose.tools.eq_(set(bal_train).intersection(bal_validation), set())
+ assert set(bal_train).intersection(bal_validation) == set()
- nose.tools.eq_(db.folds(), [1, 2, 3, 4])
- nose.tools.eq_(db.folds('full'), ['all_data'])
+ assert db.folds() == [1, 2, 3, 4]
+ assert db.folds('full') == ['all_data']
- nose.tools.eq_(
- db.file_error_meta(filename='audio/b079_180_190.wav')[0].filename,
- 'audio/b079_180_190.wav'
- )
- nose.tools.eq_(
- db.file_error_meta(filename='audio/b079_180_190.wav')[0].event_label,
- 'error'
- )
- nose.tools.eq_(
- db.file_error_meta(filename='audio/b079_180_190.wav')[0].onset,
- 1.991448
- )
- nose.tools.eq_(
- db.file_error_meta(filename='audio/b079_180_190.wav')[0].offset,
- 2.446579
- )
+ assert db.file_error_meta(filename='audio/b079_180_190.wav')[0].filename == 'audio/b079_180_190.wav'
+ assert db.file_error_meta(filename='audio/b079_180_190.wav')[0].event_label == 'error'
+ assert db.file_error_meta(filename='audio/b079_180_190.wav')[0].onset == 1.991448
+ assert db.file_error_meta(filename='audio/b079_180_190.wav')[0].offset == 2.446579
- nose.tools.eq_(
- db.relative_to_absolute_path('audio/b079_180_190.wav'),
- os.path.join(audio_path, 'b079_180_190.wav')
- )
+ assert db.relative_to_absolute_path('audio/b079_180_190.wav') == os.path.join(audio_path, 'b079_180_190.wav')
- nose.tools.eq_(
- db.absolute_to_relative_path(os.path.join(audio_path, 'b079_180_190.wav')),
- os.path.join('audio', 'b079_180_190.wav')
- )
+ assert db.absolute_to_relative_path(os.path.join(audio_path, 'b079_180_190.wav')) == os.path.join('audio', 'b079_180_190.wav')
- nose.tools.eq_(db.dataset_bytes(), 10700420548)
- nose.tools.eq_(db.dataset_size_string(), '9.966 GB')
- nose.tools.eq_(db.dataset_size_on_disk(), '969.1 KB')
+ assert db.dataset_bytes() == 10700420548
+ assert db.dataset_size_string() == '9.966 GB'
+ assert db.dataset_size_on_disk() == '969.1 KB'
with dcase_util.utils.DisableLogger():
db.log()
-
def test_TUTAcousticScenes_2017_EvaluationSet():
db = dcase_util.datasets.TUTAcousticScenes_2017_EvaluationSet(
included_content_types=['meta']
).initialize()
# Cross-validation setup / Train
- nose.tools.eq_(db.train().file_count, 0)
+ assert db.train().file_count == 0
# Cross-validation setup / Test
- nose.tools.eq_(db.test().file_count, 1620)
+ assert db.test().file_count == 1620
- nose.tools.eq_(db.eval().file_count, 1620)
+ assert db.eval().file_count == 1620
- nose.tools.eq_(db.audio_files, [])
- nose.tools.eq_(db.audio_file_count, 0)
+ assert db.audio_files == []
+ assert db.audio_file_count == 0
- nose.tools.eq_(len(db.meta), 1620)
- nose.tools.eq_(db.meta_count, 1620)
+ assert len(db.meta) == 1620
+ assert db.meta_count == 1620
- nose.tools.eq_(db.fold_count, None)
+ assert db.fold_count == None
- nose.tools.eq_(db.scene_label_count(), 15)
+ assert db.scene_label_count() == 15
- nose.tools.eq_(db.check_filelist(), True)
+ assert db.check_filelist() == True
- nose.tools.eq_(db.folds(), ['all_data'])
- nose.tools.eq_(db.folds('full'), ['all_data'])
+ assert db.folds() == ['all_data']
+ assert db.folds('full') == ['all_data']
with dcase_util.utils.DisableLogger():
db.log()
-
def test_TUTUrbanAcousticScenes_2018_DevelopmentSet():
db = dcase_util.datasets.TUTUrbanAcousticScenes_2018_DevelopmentSet(
included_content_types=['meta']
).initialize()
# Cross-validation setup / Train
- nose.tools.eq_(db.train().file_count, 8640)
- nose.tools.eq_(db.train(1).file_count, 6122)
+ assert db.train().file_count == 8640
+ assert db.train(1).file_count == 6122
# Cross-validation setup / Test
- nose.tools.eq_(db.test().file_count, 8640)
- nose.tools.eq_(db.test(1).file_count, 2518)
+ assert db.test().file_count == 8640
+ assert db.test(1).file_count == 2518
- nose.tools.eq_(db.eval().file_count, 8640)
- nose.tools.eq_(db.eval(1).file_count, 2518)
+ assert db.eval().file_count == 8640
+ assert db.eval(1).file_count == 2518
- nose.tools.eq_(set(db.train_files(1)).intersection(db.test_files(1)), set())
- nose.tools.eq_(db.audio_files, [])
- nose.tools.eq_(db.audio_file_count, 0)
- nose.tools.eq_(len(db.meta), 8640)
- nose.tools.eq_(db.meta_count, 8640)
- nose.tools.eq_(db.fold_count, 1)
- nose.tools.eq_(db.scene_label_count(), 10)
- nose.tools.eq_(db.check_filelist(), True)
+ assert set(db.train_files(1)).intersection(db.test_files(1)) == set()
+ assert db.audio_files == []
+ assert db.audio_file_count == 0
+ assert len(db.meta) == 8640
+ assert db.meta_count == 8640
+ assert db.fold_count == 1
+ assert db.scene_label_count() == 10
+ assert db.check_filelist() == True
with dcase_util.utils.DisableLogger():
bal_train, bal_validation = db.validation_split(
@@ -445,89 +419,86 @@ def test_TUTUrbanAcousticScenes_2018_DevelopmentSet():
verbose=False
)
- nose.tools.eq_(set(bal_train).intersection(bal_validation), set())
- nose.tools.eq_(db.folds(), [1])
- nose.tools.eq_(db.folds('full'), ['all_data'])
+ assert set(bal_train).intersection(bal_validation) == set()
+ assert db.folds() == [1]
+ assert db.folds('full') == ['all_data']
with dcase_util.utils.DisableLogger():
db.log()
-
def test_TUTUrbanAcousticScenes_2018_Mobile_DevelopmentSet():
db = dcase_util.datasets.TUTUrbanAcousticScenes_2018_Mobile_DevelopmentSet(
included_content_types=['meta']
).initialize()
# Cross-validation setup / Train
- nose.tools.eq_(db.train().file_count, 10080)
- nose.tools.eq_(db.train(1).file_count, 7202)
+ assert db.train().file_count == 10080
+ assert db.train(1).file_count == 7202
# Cross-validation setup / Test
- nose.tools.eq_(db.test().file_count, 10080)
- nose.tools.eq_(db.test(1).file_count, 2878)
-
- nose.tools.eq_(db.eval().file_count, 10080)
- nose.tools.eq_(db.eval(1).file_count, 2878)
-
- nose.tools.eq_(set(db.train_files(1)).intersection(db.test_files(1)), set())
- nose.tools.eq_(db.audio_files, [])
- nose.tools.eq_(db.audio_file_count, 0)
- nose.tools.eq_(len(db.meta), 10080)
- nose.tools.eq_(db.meta_count, 10080)
- nose.tools.eq_(db.fold_count, 1)
- nose.tools.eq_(db.scene_label_count(), 10)
- nose.tools.eq_(db.check_filelist(), True)
- nose.tools.eq_(db.folds(), [1])
- nose.tools.eq_(db.folds('full'), ['all_data'])
+ assert db.test().file_count == 10080
+ assert db.test(1).file_count == 2878
+
+ assert db.eval().file_count == 10080
+ assert db.eval(1).file_count == 2878
+
+ assert set(db.train_files(1)).intersection(db.test_files(1)) == set()
+ assert db.audio_files == []
+ assert db.audio_file_count == 0
+ assert len(db.meta) == 10080
+ assert db.meta_count == 10080
+ assert db.fold_count == 1
+ assert db.scene_label_count() == 10
+ assert db.check_filelist() == True
+ assert db.folds() == [1]
+ assert db.folds('full') == ['all_data']
with dcase_util.utils.DisableLogger():
db.log()
-
def test_TUTSoundEvents_2016_DevelopmentSet():
db = dcase_util.datasets.TUTSoundEvents_2016_DevelopmentSet(
included_content_types=['meta']
).initialize()
# Cross-validation setup / Train
- nose.tools.eq_(db.train().file_count, 22)
- nose.tools.eq_(db.train(1).file_count, 16)
- nose.tools.eq_(db.train(2).file_count, 16)
- nose.tools.eq_(db.train(3).file_count, 17)
- nose.tools.eq_(db.train(4).file_count, 17)
+ assert db.train().file_count == 22
+ assert db.train(1).file_count == 16
+ assert db.train(2).file_count == 16
+ assert db.train(3).file_count == 17
+ assert db.train(4).file_count == 17
# Cross-validation setup / Test
- nose.tools.eq_(db.test().file_count, 22)
- nose.tools.eq_(db.test(1).file_count, 6)
- nose.tools.eq_(db.test(2).file_count, 6)
- nose.tools.eq_(db.test(3).file_count, 5)
- nose.tools.eq_(db.test(4).file_count, 5)
-
- nose.tools.eq_(db.eval().file_count, 22)
- nose.tools.eq_(db.eval(1).file_count, 6)
- nose.tools.eq_(db.eval(2).file_count, 6)
- nose.tools.eq_(db.eval(3).file_count, 5)
- nose.tools.eq_(db.eval(4).file_count, 5)
+ assert db.test().file_count == 22
+ assert db.test(1).file_count == 6
+ assert db.test(2).file_count == 6
+ assert db.test(3).file_count == 5
+ assert db.test(4).file_count == 5
- nose.tools.eq_(set(db.train_files(1)).intersection(db.test_files(1)), set())
- nose.tools.eq_(set(db.train_files(2)).intersection(db.test_files(2)), set())
- nose.tools.eq_(set(db.train_files(3)).intersection(db.test_files(3)), set())
- nose.tools.eq_(set(db.train_files(4)).intersection(db.test_files(4)), set())
+ assert db.eval().file_count == 22
+ assert db.eval(1).file_count == 6
+ assert db.eval(2).file_count == 6
+ assert db.eval(3).file_count == 5
+ assert db.eval(4).file_count == 5
- nose.tools.eq_(len(db.meta), 954)
- nose.tools.eq_(db.meta_count, 954)
+ assert set(db.train_files(1)).intersection(db.test_files(1)) == set()
+ assert set(db.train_files(2)).intersection(db.test_files(2)) == set()
+ assert set(db.train_files(3)).intersection(db.test_files(3)) == set()
+ assert set(db.train_files(4)).intersection(db.test_files(4)) == set()
- nose.tools.eq_(db.scene_labels(), ['home', 'residential_area'])
- nose.tools.eq_(db.scene_label_count(), 2)
+ assert len(db.meta) == 954
+ assert db.meta_count == 954
- nose.tools.eq_(db.event_labels(), ['(object) banging', '(object) rustling', '(object) snapping', 'bird singing', 'car passing by', 'children shouting', 'cupboard', 'cutlery', 'dishes', 'drawer', 'glass jingling', 'object impact', 'people speaking', 'people walking', 'washing dishes', 'water tap running', 'wind blowing'])
+ assert db.scene_labels() == ['home', 'residential_area']
+ assert db.scene_label_count() == 2
- nose.tools.eq_(db.event_label_count(), 17)
+ assert db.event_labels() == ['(object) banging', '(object) rustling', '(object) snapping', 'bird singing', 'car passing by', 'children shouting', 'cupboard', 'cutlery', 'dishes', 'drawer', 'glass jingling', 'object impact', 'people speaking', 'people walking', 'washing dishes', 'water tap running', 'wind blowing']
- nose.tools.eq_(db.check_filelist(), True)
+ assert db.event_label_count() == 17
- nose.tools.eq_(db.folds(), [1, 2, 3, 4])
- nose.tools.eq_(db.folds('full'), ['all_data'])
+ assert db.check_filelist() == True
+ assert db.folds() == [1, 2, 3, 4]
+ assert db.folds('full') == ['all_data']
def test_TUTSoundEvents_2016_EvaluationSet():
db = dcase_util.datasets.TUTSoundEvents_2016_EvaluationSet(
@@ -535,28 +506,26 @@ def test_TUTSoundEvents_2016_EvaluationSet():
).initialize()
# Cross-validation setup / Test
- nose.tools.eq_(db.test().file_count, 10)
+ assert db.test().file_count == 10
- nose.tools.eq_(db.eval().file_count, 10)
+ assert db.eval().file_count == 10
- nose.tools.eq_(len(db.meta), 511)
- nose.tools.eq_(db.meta_count, 511)
+ assert len(db.meta) == 511
+ assert db.meta_count == 511
- nose.tools.eq_(db.scene_labels(), ['home', 'residential_area'])
- nose.tools.eq_(db.scene_label_count(), 2)
+ assert db.scene_labels() == ['home', 'residential_area']
+ assert db.scene_label_count() == 2
- nose.tools.eq_(db.event_labels(),
- ['(object) banging', '(object) rustling', '(object) snapping', 'bird singing', 'car passing by',
+ assert db.event_labels() == ['(object) banging', '(object) rustling', '(object) snapping', 'bird singing', 'car passing by',
'children shouting', 'cupboard', 'cutlery', 'dishes', 'drawer', 'glass jingling', 'object impact',
- 'people speaking', 'people walking', 'washing dishes', 'water tap running', 'wind blowing'])
+ 'people speaking', 'people walking', 'washing dishes', 'water tap running', 'wind blowing']
- nose.tools.eq_(db.event_label_count(), 17)
+ assert db.event_label_count() == 17
- nose.tools.eq_(db.check_filelist(), True)
-
- nose.tools.eq_(db.folds(), ['all_data'])
- nose.tools.eq_(db.folds('full'), ['all_data'])
+ assert db.check_filelist() == True
+ assert db.folds() == ['all_data']
+ assert db.folds('full') == ['all_data']
def test_TUTSoundEvents_2017_DevelopmentSet():
db = dcase_util.datasets.TUTSoundEvents_2017_DevelopmentSet(
@@ -572,67 +541,67 @@ def test_TUTSoundEvents_2017_DevelopmentSet():
)
# Cross-validation setup / Train
- nose.tools.eq_(db.train().file_count, 24)
- nose.tools.eq_(db.train(1).file_count, 18)
- nose.tools.eq_(db.train(2).file_count, 18)
- nose.tools.eq_(db.train(3).file_count, 18)
- nose.tools.eq_(db.train(4).file_count, 18)
-
- nose.tools.eq_(db.train_files()[0], os.path.join(audio_path, 'a001.wav'))
- nose.tools.eq_(db.train_files(1)[0], os.path.join(audio_path, 'a001.wav'))
- nose.tools.eq_(db.train_files(2)[0], os.path.join(audio_path, 'a001.wav'))
- nose.tools.eq_(db.train_files(3)[0], os.path.join(audio_path, 'a001.wav'))
- nose.tools.eq_(db.train_files(4)[0], os.path.join(audio_path, 'a003.wav'))
+ assert db.train().file_count == 24
+ assert db.train(1).file_count == 18
+ assert db.train(2).file_count == 18
+ assert db.train(3).file_count == 18
+ assert db.train(4).file_count == 18
+
+ assert db.train_files()[0] == os.path.join(audio_path, 'a001.wav')
+ assert db.train_files(1)[0] == os.path.join(audio_path, 'a001.wav')
+ assert db.train_files(2)[0] == os.path.join(audio_path, 'a001.wav')
+ assert db.train_files(3)[0] == os.path.join(audio_path, 'a001.wav')
+ assert db.train_files(4)[0] == os.path.join(audio_path, 'a003.wav')
# Cross-validation setup / Test
- nose.tools.eq_(db.test().file_count, 24)
- nose.tools.eq_(db.test(1).file_count, 6)
- nose.tools.eq_(db.test(2).file_count, 6)
- nose.tools.eq_(db.test(3).file_count, 6)
- nose.tools.eq_(db.test(4).file_count, 6)
-
- nose.tools.eq_(db.test_files()[0], os.path.join(audio_path, 'a001.wav'))
- nose.tools.eq_(db.test_files(1)[0], os.path.join(audio_path, 'a010.wav'))
- nose.tools.eq_(db.test_files(2)[0], os.path.join(audio_path, 'a003.wav'))
- nose.tools.eq_(db.test_files(3)[0], os.path.join(audio_path, 'a008.wav'))
- nose.tools.eq_(db.test_files(4)[0], os.path.join(audio_path, 'a001.wav'))
-
- nose.tools.eq_(db.eval().file_count, 24)
- nose.tools.eq_(db.eval(1).file_count, 6)
- nose.tools.eq_(db.eval(2).file_count, 6)
- nose.tools.eq_(db.eval(3).file_count, 6)
- nose.tools.eq_(db.eval(4).file_count, 6)
-
- nose.tools.eq_(db.eval_files()[0], os.path.join(audio_path, 'a001.wav'))
- nose.tools.eq_(db.eval_files(1)[0], os.path.join(audio_path, 'a010.wav'))
- nose.tools.eq_(db.eval_files(2)[0], os.path.join(audio_path, 'a003.wav'))
- nose.tools.eq_(db.eval_files(3)[0], os.path.join(audio_path, 'a008.wav'))
- nose.tools.eq_(db.eval_files(4)[0], os.path.join(audio_path, 'a001.wav'))
-
- nose.tools.eq_(set(db.train_files(1)).intersection(db.test_files(1)), set())
- nose.tools.eq_(set(db.train_files(2)).intersection(db.test_files(2)), set())
- nose.tools.eq_(set(db.train_files(3)).intersection(db.test_files(3)), set())
- nose.tools.eq_(set(db.train_files(4)).intersection(db.test_files(4)), set())
-
- nose.tools.eq_(db[0].filename, os.path.join(audio_path, 'a001.wav'))
- nose.tools.eq_(db[0].scene_label, 'street')
- nose.tools.eq_(db[0].event_label, 'people walking')
- nose.tools.eq_(db[0].onset, 1.589213)
- nose.tools.eq_(db[0].offset, 2.38382)
-
- nose.tools.eq_(len(db.meta), 659)
- nose.tools.eq_(db.meta_count, 659)
- nose.tools.eq_(db.scene_labels(), ['street'])
- nose.tools.eq_(db.scene_label_count(), 1)
- nose.tools.eq_(db.event_labels(), ['brakes squeaking',
+ assert db.test().file_count == 24
+ assert db.test(1).file_count == 6
+ assert db.test(2).file_count == 6
+ assert db.test(3).file_count == 6
+ assert db.test(4).file_count == 6
+
+ assert db.test_files()[0] == os.path.join(audio_path, 'a001.wav')
+ assert db.test_files(1)[0] == os.path.join(audio_path, 'a010.wav')
+ assert db.test_files(2)[0] == os.path.join(audio_path, 'a003.wav')
+ assert db.test_files(3)[0] == os.path.join(audio_path, 'a008.wav')
+ assert db.test_files(4)[0] == os.path.join(audio_path, 'a001.wav')
+
+ assert db.eval().file_count == 24
+ assert db.eval(1).file_count == 6
+ assert db.eval(2).file_count == 6
+ assert db.eval(3).file_count == 6
+ assert db.eval(4).file_count == 6
+
+ assert db.eval_files()[0] == os.path.join(audio_path, 'a001.wav')
+ assert db.eval_files(1)[0] == os.path.join(audio_path, 'a010.wav')
+ assert db.eval_files(2)[0] == os.path.join(audio_path, 'a003.wav')
+ assert db.eval_files(3)[0] == os.path.join(audio_path, 'a008.wav')
+ assert db.eval_files(4)[0] == os.path.join(audio_path, 'a001.wav')
+
+ assert set(db.train_files(1)).intersection(db.test_files(1)) == set()
+ assert set(db.train_files(2)).intersection(db.test_files(2)) == set()
+ assert set(db.train_files(3)).intersection(db.test_files(3)) == set()
+ assert set(db.train_files(4)).intersection(db.test_files(4)) == set()
+
+ assert db[0].filename == os.path.join(audio_path, 'a001.wav')
+ assert db[0].scene_label == 'street'
+ assert db[0].event_label == 'people walking'
+ assert db[0].onset == 1.589213
+ assert db[0].offset == 2.38382
+
+ assert len(db.meta) == 659
+ assert db.meta_count == 659
+ assert db.scene_labels() == ['street']
+ assert db.scene_label_count() == 1
+ assert db.event_labels() == ['brakes squeaking',
'car',
'children',
'large vehicle',
'people speaking',
- 'people walking'])
+ 'people walking']
- nose.tools.eq_(db.event_label_count(), 6)
- nose.tools.eq_(db.check_filelist(), True)
+ assert db.event_label_count() == 6
+ assert db.check_filelist() == True
with dcase_util.utils.DisableLogger():
rand_train, rand_validation = db.validation_split(
@@ -642,7 +611,7 @@ def test_TUTSoundEvents_2017_DevelopmentSet():
verbose=False
)
- nose.tools.eq_(set(rand_train).intersection(rand_validation), set())
+ assert set(rand_train).intersection(rand_validation) == set()
with dcase_util.utils.DisableLogger():
bal_train, bal_validation = db.validation_split(
@@ -653,13 +622,12 @@ def test_TUTSoundEvents_2017_DevelopmentSet():
verbose=False
)
- nose.tools.eq_(set(bal_train).intersection(bal_validation), set())
- nose.tools.eq_(db.folds(), [1, 2, 3, 4])
- nose.tools.eq_(db.folds('full'), ['all_data'])
- nose.tools.eq_(db.dataset_bytes(), 1276082461)
- nose.tools.eq_(db.dataset_size_string(), '1.188 GB')
- nose.tools.eq_(db.dataset_size_on_disk(), '642.2 KB')
-
+ assert set(bal_train).intersection(bal_validation) == set()
+ assert db.folds() == [1, 2, 3, 4]
+ assert db.folds('full') == ['all_data']
+ assert db.dataset_bytes() == 1276082461
+ assert db.dataset_size_string() == '1.188 GB'
+ assert db.dataset_size_on_disk() == '642.2 KB'
def test_TUTSoundEvents_2017_EvaluationSet():
db = dcase_util.datasets.TUTSoundEvents_2017_EvaluationSet(
@@ -667,27 +635,27 @@ def test_TUTSoundEvents_2017_EvaluationSet():
).initialize()
# Cross-validation setup / Test
- nose.tools.eq_(db.test().file_count, 8)
+ assert db.test().file_count == 8
- nose.tools.eq_(db.eval().file_count, 8)
+ assert db.eval().file_count == 8
- nose.tools.eq_(len(db.meta), 247)
- nose.tools.eq_(db.meta_count, 247)
+ assert len(db.meta) == 247
+ assert db.meta_count == 247
- nose.tools.eq_(db.scene_labels(), ['street'])
- nose.tools.eq_(db.scene_label_count(), 1)
+ assert db.scene_labels() == ['street']
+ assert db.scene_label_count() == 1
- nose.tools.eq_(db.event_labels(), ['brakes squeaking',
+ assert db.event_labels() == ['brakes squeaking',
'car',
'children',
'large vehicle',
'people speaking',
- 'people walking'])
+ 'people walking']
- nose.tools.eq_(db.event_label_count(), 6)
+ assert db.event_label_count() == 6
- nose.tools.eq_(db.check_filelist(), True)
+ assert db.check_filelist() == True
- nose.tools.eq_(db.folds(), ['all_data'])
- nose.tools.eq_(db.folds('full'), ['all_data'])
+ assert db.folds() == ['all_data']
+ assert db.folds('full') == ['all_data']
diff --git a/tests/features/test_MelExtractor.py b/tests/features/test_MelExtractor.py
index d4b55a95..cb69d053 100644
--- a/tests/features/test_MelExtractor.py
+++ b/tests/features/test_MelExtractor.py
@@ -1,9 +1,6 @@
""" Unit tests for MelExtractor """
-
-import nose.tools
import dcase_util
-
def test_extract():
params = {
@@ -25,6 +22,6 @@ def test_extract():
mels = mel_extractor.extract(y=audio_container)
- nose.tools.eq_(mels.shape[0], params['n_mels'])
- nose.tools.eq_(mels.shape[1], 101)
+ assert mels.shape[0] == params['n_mels']
+ assert mels.shape[1] == 101
diff --git a/tests/features/test_MfccStaticExtractor.py b/tests/features/test_MfccStaticExtractor.py
index 9534c80d..fb099c15 100644
--- a/tests/features/test_MfccStaticExtractor.py
+++ b/tests/features/test_MfccStaticExtractor.py
@@ -1,9 +1,6 @@
""" Unit tests for MfccStaticExtractor """
-
-import nose.tools
import dcase_util
-
def test_extract():
params = {
@@ -26,5 +23,5 @@ def test_extract():
mfccs = mfcc_extractor.extract(y=audio_container)
- nose.tools.eq_(mfccs.shape[0], params['n_mfccs'])
- nose.tools.eq_(mfccs.shape[1], 101)
+ assert mfccs.shape[0] == params['n_mfccs']
+ assert mfccs.shape[1] == 101
diff --git a/tests/features/test_SpectralFeatureExtractor.py b/tests/features/test_SpectralFeatureExtractor.py
index cabe9371..e9ead46a 100644
--- a/tests/features/test_SpectralFeatureExtractor.py
+++ b/tests/features/test_SpectralFeatureExtractor.py
@@ -1,10 +1,8 @@
""" Unit tests for SpectralFeatureExtractor """
-import nose.tools
-from nose.tools import *
+import pytest
import dcase_util
-
def test_get_spectrogram():
params = {
'fs': 44100,
@@ -21,33 +19,32 @@ def test_get_spectrogram():
y=audio_container,
)
- nose.tools.eq_(spec.shape[0], (params['n_fft'] / 2) + 1)
- nose.tools.eq_(spec.shape[1], 101)
+ assert spec.shape[0] == (params['n_fft'] / 2) + 1
+ assert spec.shape[1] == 101
spec = sfe.get_spectrogram(
y=audio_container,
spectrogram_type='power'
)
- nose.tools.eq_(spec.shape[0], (params['n_fft'] / 2) + 1)
- nose.tools.eq_(spec.shape[1], 101)
-
+ assert spec.shape[0] == (params['n_fft'] / 2) + 1
+ assert spec.shape[1] == 101
-@raises(ValueError)
def test_non_mono():
- with dcase_util.utils.DisableLogger():
- params = {
- 'fs': 44100,
- 'win_length_seconds': 0.04,
- 'hop_length_seconds': 0.02,
- 'spectrogram_type': 'magnitude',
- 'window_type': 'hann_symmetric',
- 'n_mels': 40, # Number of MEL bands used
- 'n_fft': 2048, # FFT length
- 'fmin': 0, # Minimum frequency when constructing MEL bands
- 'fmax': 22050, # Maximum frequency when constructing MEL band
- 'htk': True, # Switch for HTK-styled MEL-frequency equation
- }
- sfe = dcase_util.features.SpectralFeatureExtractor(**params)
- audio_container = dcase_util.utils.Example.audio_container()
- sfe.get_spectrogram(y=audio_container)
+ with pytest.raises(ValueError):
+ with dcase_util.utils.DisableLogger():
+ params = {
+ 'fs': 44100,
+ 'win_length_seconds': 0.04,
+ 'hop_length_seconds': 0.02,
+ 'spectrogram_type': 'magnitude',
+ 'window_type': 'hann_symmetric',
+ 'n_mels': 40, # Number of MEL bands used
+ 'n_fft': 2048, # FFT length
+ 'fmin': 0, # Minimum frequency when constructing MEL bands
+ 'fmax': 22050, # Maximum frequency when constructing MEL band
+ 'htk': True, # Switch for HTK-styled MEL-frequency equation
+ }
+ sfe = dcase_util.features.SpectralFeatureExtractor(**params)
+ audio_container = dcase_util.utils.Example.audio_container()
+ sfe.get_spectrogram(y=audio_container)
diff --git a/tests/files/test_RemoteFile.py b/tests/files/test_RemoteFile.py
index 91df513e..da74d443 100644
--- a/tests/files/test_RemoteFile.py
+++ b/tests/files/test_RemoteFile.py
@@ -1,12 +1,9 @@
""" Unit tests for RemoteFile """
-
-import nose.tools
import tempfile
import os
import platform
from dcase_util.files import RemoteFile
-
def test_RemoteFile():
tmp = tempfile.NamedTemporaryFile('r+', suffix='.txt', dir=tempfile.gettempdir(), delete=False)
try:
@@ -16,34 +13,34 @@ def test_RemoteFile():
r = RemoteFile(filename=tmp.name, content_type='documentation')
- nose.tools.eq_(r.local_exists(), True)
+ assert r.local_exists() == True
if platform.system() == 'Windows':
- nose.tools.eq_(r.local_bytes, 12)
- nose.tools.eq_(r.local_size_string(), '12 bytes')
- nose.tools.eq_(r.local_md5, 'cd2ebbdc5e817b5f5fe79c38134320e8')
+ assert r.local_bytes == 12
+ assert r.local_size_string() == '12 bytes'
+ assert r.local_md5 == 'cd2ebbdc5e817b5f5fe79c38134320e8'
else:
- nose.tools.eq_(r.local_bytes, 10)
- nose.tools.eq_(r.local_size_string(), '10 bytes')
- nose.tools.eq_(r.local_md5, '2f34a55e73abe0ca5f39c43eed5aef70')
+ assert r.local_bytes == 10
+ assert r.local_size_string() == '10 bytes'
+ assert r.local_md5 == '2f34a55e73abe0ca5f39c43eed5aef70'
r = RemoteFile(filename=tmp.name, content_type='documentation')
- nose.tools.eq_(r.is_content_type(content_type='documentation'), True)
- nose.tools.eq_(r.is_content_type(content_type='meta'), False)
- nose.tools.eq_(r.is_content_type(content_type='all'), True)
+ assert r.is_content_type(content_type='documentation') == True
+ assert r.is_content_type(content_type='meta') == False
+ assert r.is_content_type(content_type='all') == True
r = RemoteFile(filename=tmp.name, content_type=['documentation', 'audio', 'meta'])
- nose.tools.eq_(r.is_content_type(content_type='all'), True)
- nose.tools.eq_(r.is_content_type(content_type='meta'), True)
- nose.tools.eq_(r.is_content_type(content_type='audio'), True)
+ assert r.is_content_type(content_type='all') == True
+ assert r.is_content_type(content_type='meta') == True
+ assert r.is_content_type(content_type='audio') == True
r = RemoteFile(filename=tmp.name, content_type=['documentation'])
- nose.tools.eq_(r.is_content_type(content_type=['meta', 'audio']), False)
- nose.tools.eq_(r.is_content_type(content_type=['all']), True)
+ assert r.is_content_type(content_type=['meta', 'audio']) == False
+ assert r.is_content_type(content_type=['all']) == True
r = RemoteFile(filename=tmp.name)
- nose.tools.eq_(r.is_content_type(content_type=['all']), True)
+ assert r.is_content_type(content_type=['all']) == True
finally:
diff --git a/tests/files/test_Serializer.py b/tests/files/test_Serializer.py
index 18dfbe33..73684866 100644
--- a/tests/files/test_Serializer.py
+++ b/tests/files/test_Serializer.py
@@ -1,11 +1,8 @@
""" Unit tests for RemoteFile """
-
-import nose.tools
import tempfile
import os
from dcase_util.files import Serializer
-
def test_Serializer():
data = {
'field1': 10,
@@ -17,7 +14,7 @@ def test_Serializer():
tmp = tempfile.NamedTemporaryFile('r+', suffix='.yaml', dir=tempfile.gettempdir(), delete=False)
try:
s.save_yaml(filename=tmp.name, data=data)
- nose.tools.eq_(data, s.load_yaml(filename=tmp.name))
+ assert data == s.load_yaml(filename=tmp.name)
finally:
try:
tmp.close()
@@ -28,7 +25,7 @@ def test_Serializer():
tmp = tempfile.NamedTemporaryFile('r+', suffix='.cpickle', dir=tempfile.gettempdir(), delete=False)
try:
s.save_cpickle(filename=tmp.name, data=data)
- nose.tools.eq_(data, s.load_cpickle(filename=tmp.name))
+ assert data == s.load_cpickle(filename=tmp.name)
finally:
try:
tmp.close()
@@ -39,7 +36,7 @@ def test_Serializer():
tmp = tempfile.NamedTemporaryFile('r+', suffix='.json', dir=tempfile.gettempdir(), delete=False)
try:
s.save_json(filename=tmp.name, data=data)
- nose.tools.eq_(data, s.load_json(filename=tmp.name))
+ assert data == s.load_json(filename=tmp.name)
finally:
try:
tmp.close()
@@ -50,7 +47,7 @@ def test_Serializer():
tmp = tempfile.NamedTemporaryFile('r+', suffix='.msgpack', dir=tempfile.gettempdir(), delete=False)
try:
s.save_msgpack(filename=tmp.name, data=data)
- nose.tools.eq_(data, s.load_msgpack(filename=tmp.name))
+ assert data == s.load_msgpack(filename=tmp.name)
finally:
try:
tmp.close()
@@ -61,7 +58,7 @@ def test_Serializer():
tmp = tempfile.NamedTemporaryFile('r+', suffix='.marshal', dir=tempfile.gettempdir(), delete=False)
try:
s.save_marshal(filename=tmp.name, data=data)
- nose.tools.eq_(data, s.load_marshal(filename=tmp.name))
+ assert data == s.load_marshal(filename=tmp.name)
finally:
try:
tmp.close()
diff --git a/tests/processors/test_audio.py b/tests/processors/test_audio.py
index 7b18b04e..3258caf6 100644
--- a/tests/processors/test_audio.py
+++ b/tests/processors/test_audio.py
@@ -1,24 +1,22 @@
-import nose.tools
import dcase_util
-
def test_AudioReadingProcessor():
# Simple reading
processor = dcase_util.processors.AudioReadingProcessor()
audio = processor.process(filename=dcase_util.utils.Example.audio_filename())
- nose.tools.eq_(audio.fs, 44100)
- nose.tools.eq_(len(audio.data.shape), 2)
- nose.tools.eq_(audio.length, 441001)
+ assert audio.fs == 44100
+ assert len(audio.data.shape) == 2
+ assert audio.length == 441001
# Mono reading
processor = dcase_util.processors.AudioReadingProcessor(mono=True)
audio = processor.process(filename=dcase_util.utils.Example.audio_filename())
- nose.tools.eq_(audio.fs, 44100)
- nose.tools.eq_(len(audio.data.shape), 1)
- nose.tools.eq_(audio.length, 441001)
+ assert audio.fs == 44100
+ assert len(audio.data.shape) == 1
+ assert audio.length == 441001
# Focus segment
processor = dcase_util.processors.AudioReadingProcessor(mono=True)
@@ -28,9 +26,9 @@ def test_AudioReadingProcessor():
focus_duration_seconds=2.0
).freeze()
- nose.tools.eq_(audio.fs, 44100)
- nose.tools.eq_(len(audio.data.shape), 1)
- nose.tools.eq_(audio.length, 44100*2.0)
+ assert audio.fs == 44100
+ assert len(audio.data.shape) == 1
+ assert audio.length == 44100*2.0
# Focus channel
processor = dcase_util.processors.AudioReadingProcessor()
@@ -41,16 +39,15 @@ def test_AudioReadingProcessor():
focus_duration_seconds=2.0
).freeze()
- nose.tools.eq_(audio.fs, 44100)
- nose.tools.eq_(len(audio.data.shape), 1)
- nose.tools.eq_(audio.length, 44100*2.0)
-
+ assert audio.fs == 44100
+ assert len(audio.data.shape) == 1
+ assert audio.length == 44100*2.0
def test_MonoAudioReadingProcessor():
# Simple reading
processor = dcase_util.processors.MonoAudioReadingProcessor()
audio = processor.process(filename=dcase_util.utils.Example.audio_filename())
- nose.tools.eq_(audio.fs, 44100)
- nose.tools.eq_(len(audio.data.shape), 1)
- nose.tools.eq_(audio.length, 441001)
+ assert audio.fs == 44100
+ assert len(audio.data.shape) == 1
+ assert audio.length == 441001
diff --git a/tests/processors/test_data.py b/tests/processors/test_data.py
index ea536c5f..bacaac3f 100644
--- a/tests/processors/test_data.py
+++ b/tests/processors/test_data.py
@@ -1,65 +1,62 @@
-import nose.tools
+import pytest
import dcase_util
import numpy
-
def test_AggregationProcessor():
a = dcase_util.processors.AggregationProcessor(
recipe=['flatten']
)
processed = a.process(dcase_util.utils.Example.feature_container())
- nose.tools.eq_(processed.data.shape, (400, 501))
+ assert processed.data.shape == (400, 501)
a = dcase_util.processors.AggregationProcessor(
recipe=['mean']
)
processed = a.process(dcase_util.utils.Example.feature_container())
- nose.tools.eq_(processed.data.shape, (40, 501))
+ assert processed.data.shape == (40, 501)
a = dcase_util.processors.AggregationProcessor(
recipe=['mean']
)
processed = a.process(dcase_util.utils.Example.feature_container())
- nose.tools.eq_(processed.data.shape, (40, 501))
+ assert processed.data.shape == (40, 501)
a = dcase_util.processors.AggregationProcessor(
recipe=['cov']
)
processed = a.process(dcase_util.utils.Example.feature_container())
- nose.tools.eq_(processed.data.shape, (1600, 501))
+ assert processed.data.shape == (1600, 501)
a = dcase_util.processors.AggregationProcessor(
recipe=['kurtosis']
)
processed = a.process(dcase_util.utils.Example.feature_container())
- nose.tools.eq_(processed.data.shape, (40, 501))
+ assert processed.data.shape == (40, 501)
a = dcase_util.processors.AggregationProcessor(
recipe=['skew']
)
processed = a.process(dcase_util.utils.Example.feature_container())
- nose.tools.eq_(processed.data.shape, (40, 501))
+ assert processed.data.shape == (40, 501)
a = dcase_util.processors.AggregationProcessor(
recipe=['flatten', 'mean']
)
processed = a.process(dcase_util.utils.Example.feature_container())
- nose.tools.eq_(processed.data.shape, (440, 501))
+ assert processed.data.shape == (440, 501)
a = dcase_util.processors.AggregationProcessor(
recipe=['mean', 'std']
)
processed = a.process(dcase_util.utils.Example.feature_container())
- nose.tools.eq_(processed.data.shape, (80, 501))
-
+ assert processed.data.shape == (80, 501)
def test_SequencingProcessor():
s = dcase_util.processors.SequencingProcessor()
processed = s.process(dcase_util.utils.Example.feature_container())
- nose.tools.eq_(processed.data.shape, (40, 10, 50))
-
+ assert processed.data.shape == (40, 10, 50)
def test_NormalizationProcessor():
data = dcase_util.utils.Example.feature_container()
@@ -68,8 +65,7 @@ def test_NormalizationProcessor():
mean=data.stats['mean'], std=data.stats['std']
)
processed = normalizer.process(dcase_util.utils.Example.feature_container())
- nose.tools.assert_almost_equal(numpy.sum(numpy.std(processed.data, axis=1)), 40.0)
-
+ assert numpy.sum(numpy.std(processed.data, axis=1)) == pytest.approx(40.0)
def test_RepositoryNormalizationProcessor():
repo = dcase_util.utils.Example.feature_repository()
@@ -81,17 +77,15 @@ def test_RepositoryNormalizationProcessor():
)
processed = normalizer.process(repo)
- nose.tools.assert_almost_equal(numpy.sum(numpy.std(processed['mel'][0].data, axis=1)), 40.0, delta=0.0001)
- nose.tools.assert_almost_equal(numpy.sum(numpy.std(processed['mfcc'][0].data, axis=1)), 20.0, delta=0.0001)
-
+ assert numpy.sum(numpy.std(processed['mel'][0].data, axis=1)) == pytest.approx(40.0, abs=0.0001)
+ assert numpy.sum(numpy.std(processed['mfcc'][0].data, axis=1)) == pytest.approx(20.0, abs=0.0001)
def test_StackingProcessor():
repo = dcase_util.utils.Example.feature_repository()
stacker = dcase_util.processors.StackingProcessor(recipe='mel;mfcc')
processed = stacker.process(repo)
- nose.tools.eq_(processed.data.shape, (60, 501))
-
+ assert processed.data.shape == (60, 501)
def test_RepositoryMaskingProcessor():
repo = dcase_util.utils.Example.feature_repository()
@@ -103,10 +97,9 @@ def test_RepositoryMaskingProcessor():
mask_events=mask_events
)
- nose.tools.eq_(processed['mel'][0].shape, (40, 318))
- nose.tools.eq_(processed['mfcc'][0].shape, (20, 318))
- nose.tools.eq_(processed['zcr'][0].shape, (1, 318))
-
+ assert processed['mel'][0].shape == (40, 318)
+ assert processed['mfcc'][0].shape == (20, 318)
+ assert processed['zcr'][0].shape == (1, 318)
def test_OneHotEncodingProcessor():
encoder = dcase_util.processors.OneHotEncodingProcessor(
@@ -116,8 +109,7 @@ def test_OneHotEncodingProcessor():
scene = dcase_util.utils.Example.scene_metadata_container().filter(filename='test1.wav')
processed = encoder.process(scene, length_seconds=10.0)
- nose.tools.eq_(processed.shape, (5, 10))
-
+ assert processed.shape == (5, 10)
def test_ManyHotEncodingProcessor():
encoder = dcase_util.processors.ManyHotEncodingProcessor(
@@ -129,8 +121,7 @@ def test_ManyHotEncodingProcessor():
processed = encoder.process(scene, length_seconds=10.0)
- nose.tools.eq_(processed.shape, (5, 10))
-
+ assert processed.shape == (5, 10)
def test_EventRollEncodingProcessor():
encoder = dcase_util.processors.EventRollEncodingProcessor(
@@ -141,4 +132,4 @@ def test_EventRollEncodingProcessor():
events = dcase_util.utils.Example.event_metadata_container().filter(filename='test1.wav')
processed = encoder.process(data=events)
- nose.tools.eq_(processed.shape, (2, 8))
+ assert processed.shape == (2, 8)
diff --git a/tests/processors/test_features.py b/tests/processors/test_features.py
index ffed3759..7d9538d7 100644
--- a/tests/processors/test_features.py
+++ b/tests/processors/test_features.py
@@ -1,9 +1,7 @@
-import nose.tools
import dcase_util
import tempfile
import os
-
def test_RepositoryFeatureExtractorProcessor():
extractor = dcase_util.processors.RepositoryFeatureExtractorProcessor(
parameters={
@@ -12,67 +10,59 @@ def test_RepositoryFeatureExtractorProcessor():
}
)
processed = extractor.process(data=dcase_util.utils.Example.audio_container())
- nose.tools.eq_(processed['mel'][0].data.shape, (40, 101))
- nose.tools.eq_(processed['mfcc'][0].data.shape, (20, 101))
+ assert processed['mel'][0].data.shape == (40, 101)
+ assert processed['mfcc'][0].data.shape == (20, 101)
# With processing chain
processed = extractor.process(
data=dcase_util.utils.Example.audio_container(),
store_processing_chain=True
)
- nose.tools.eq_(processed['mel'][0].data.shape, (40, 101))
- nose.tools.eq_(processed['mfcc'][0].data.shape, (20, 101))
- nose.tools.eq_(len(processed.processing_chain), 1)
+ assert processed['mel'][0].data.shape == (40, 101)
+ assert processed['mfcc'][0].data.shape == (20, 101)
+ assert len(processed.processing_chain) == 1
# Copied
import copy
processed_copy = copy.deepcopy(processed)
- nose.tools.eq_(processed_copy['mel'][0].data.shape, (40, 101))
- nose.tools.eq_(processed_copy['mfcc'][0].data.shape, (20, 101))
- nose.tools.eq_(len(processed_copy.processing_chain), 1)
-
+ assert processed_copy['mel'][0].data.shape == (40, 101)
+ assert processed_copy['mfcc'][0].data.shape == (20, 101)
+ assert len(processed_copy.processing_chain) == 1
def test_MelExtractorProcessor():
extractor = dcase_util.processors.MelExtractorProcessor()
processed = extractor.process(data=dcase_util.utils.Example.audio_container().mixdown())
- nose.tools.eq_(processed.shape, (40, 101))
-
+ assert processed.shape == (40, 101)
def test_MfccStaticExtractorProcessor():
extractor = dcase_util.processors.MfccStaticExtractorProcessor()
processed = extractor.process(data=dcase_util.utils.Example.audio_container().mixdown())
- nose.tools.eq_(processed.shape, (20, 101))
-
+ assert processed.shape == (20, 101)
def test_MfccDeltaExtractorProcessor():
extractor = dcase_util.processors.MfccDeltaExtractorProcessor()
processed = extractor.process(data=dcase_util.utils.Example.audio_container().mixdown())
- nose.tools.eq_(processed.shape, (20, 101))
-
+ assert processed.shape == (20, 101)
def test_MfccAccelerationExtractorProcessor():
extractor = dcase_util.processors.MfccAccelerationExtractorProcessor()
processed = extractor.process(data=dcase_util.utils.Example.audio_container().mixdown())
- nose.tools.eq_(processed.shape, (20, 101))
-
+ assert processed.shape == (20, 101)
def test_ZeroCrossingRateExtractorProcessor():
extractor = dcase_util.processors.ZeroCrossingRateExtractorProcessor()
processed = extractor.process(data=dcase_util.utils.Example.audio_container().mixdown())
- nose.tools.eq_(processed.shape, (1, 101))
-
+ assert processed.shape == (1, 101)
def test_RMSEnergyExtractorProcessor():
extractor = dcase_util.processors.RMSEnergyExtractorProcessor()
processed = extractor.process(data=dcase_util.utils.Example.audio_container().mixdown())
- nose.tools.eq_(processed.shape, (1, 101))
-
+ assert processed.shape == (1, 101)
def test_SpectralCentroidExtractorProcessor():
extractor = dcase_util.processors.SpectralCentroidExtractorProcessor()
processed = extractor.process(data=dcase_util.utils.Example.audio_container().mixdown())
- nose.tools.eq_(processed.shape, (1, 101))
-
+ assert processed.shape == (1, 101)
def test_writing_reading():
chain = dcase_util.processors.ProcessingChain([
@@ -100,7 +90,7 @@ def test_writing_reading():
data_loaded = dcase_util.containers.FeatureContainer().load(filename=tmp.name)
- nose.tools.eq_(data.shape, data_loaded.shape)
+ assert data.shape == data_loaded.shape
finally:
try:
@@ -139,7 +129,7 @@ def test_writing_reading():
repo_loaded = dcase_util.containers.FeatureRepository().load(filename=tmp.name)
- nose.tools.eq_(repo.labels, repo_loaded.labels)
+ assert repo.labels == repo_loaded.labels
finally:
try:
diff --git a/tests/processors/test_metadata.py b/tests/processors/test_metadata.py
index 59da7565..3ff3d7cb 100644
--- a/tests/processors/test_metadata.py
+++ b/tests/processors/test_metadata.py
@@ -1,9 +1,7 @@
-import nose.tools
import dcase_util
import tempfile
import os
-
def test_MetadataReadingProcessor():
tmp = tempfile.NamedTemporaryFile('r+', suffix='.txt', dir=tempfile.gettempdir(), delete=False)
try:
@@ -14,8 +12,8 @@ def test_MetadataReadingProcessor():
filename=tmp.name,
focus_filename='test1.wav'
)
- nose.tools.eq_(processed.event_count, 3)
- nose.tools.eq_(processed.file_count, 1)
+ assert processed.event_count == 3
+ assert processed.file_count == 1
m = dcase_util.processors.MetadataReadingProcessor()
processed = m.process(
@@ -24,8 +22,8 @@ def test_MetadataReadingProcessor():
focus_start_seconds=0.0,
focus_stop_seconds=3.0
)
- nose.tools.eq_(processed.event_count, 1)
- nose.tools.eq_(processed.file_count, 1)
+ assert processed.event_count == 1
+ assert processed.file_count == 1
m = dcase_util.processors.MetadataReadingProcessor()
processed = m.process(
@@ -34,8 +32,8 @@ def test_MetadataReadingProcessor():
focus_start_seconds=0,
focus_duration_seconds=3.0
)
- nose.tools.eq_(processed.event_count, 1)
- nose.tools.eq_(processed.file_count, 1)
+ assert processed.event_count == 1
+ assert processed.file_count == 1
finally:
try:
diff --git a/tests/processors/test_processing_chain.py b/tests/processors/test_processing_chain.py
index 0cd18c1a..91598813 100644
--- a/tests/processors/test_processing_chain.py
+++ b/tests/processors/test_processing_chain.py
@@ -1,7 +1,5 @@
-import nose.tools
import dcase_util
-
def test_ProcessingChain():
chain = dcase_util.processors.ProcessingChain()
@@ -13,15 +11,15 @@ def test_ProcessingChain():
processor_name='dcase_util.processors.MelExtractorProcessor',
init_parameters={}
)
- nose.tools.eq_(len(chain), 2)
+ assert len(chain) == 2
- nose.tools.eq_(chain.processor_exists('dcase_util.processors.MonoAudioReadingProcessor'), True)
- nose.tools.eq_(chain.processor_exists('dcase_util.processors.MelExtractorProcessor'), True)
- nose.tools.eq_(chain.processor_exists('dcase_util.processors.AudioReadingProcessor'), False)
+ assert chain.processor_exists('dcase_util.processors.MonoAudioReadingProcessor') == True
+ assert chain.processor_exists('dcase_util.processors.MelExtractorProcessor') == True
+ assert chain.processor_exists('dcase_util.processors.AudioReadingProcessor') == False
data = chain.process(
filename=dcase_util.utils.Example().audio_filename(),
focus_start_seconds=1.0,
duration_seconds=2.0
)
- nose.tools.eq_(data.shape, (40, 501))
+ assert data.shape == (40, 501)
diff --git a/tests/requirements.txt b/tests/requirements.txt
index 7456089e..27cabb00 100644
--- a/tests/requirements.txt
+++ b/tests/requirements.txt
@@ -1,2 +1,2 @@
-nose>=1.3.7
-coverage>=4.3.4
\ No newline at end of file
+pytest>=7.0
+coverage>=4.3.4
diff --git a/tests/tools/test_BibtexProcessor.py b/tests/tools/test_BibtexProcessor.py
index 9bacf803..d68d1502 100644
--- a/tests/tools/test_BibtexProcessor.py
+++ b/tests/tools/test_BibtexProcessor.py
@@ -1,9 +1,6 @@
""" Unit tests for Challenge tools """
-
-import nose.tools
import dcase_util
-
def test_key():
authors = [
{
@@ -24,18 +21,17 @@ def test_key():
key1 = bib.key(authors=authors, title='Test title 1', year=2017)
key2 = bib.key(authors=authors, title='Test title 2', year=2017)
- nose.tools.eq_(key1, 'Lastname2017')
- nose.tools.eq_(key2, 'Lastname2017a')
+ assert key1 == 'Lastname2017'
+ assert key2 == 'Lastname2017a'
key3 = bib.key(authors=authors, title='Test title 1')
key4 = bib.key(authors=authors, title='Test title 2')
- nose.tools.eq_(key3, 'Lastname2017')
- nose.tools.eq_(key4, 'Lastname2017a')
+ assert key3 == 'Lastname2017'
+ assert key4 == 'Lastname2017a'
key5 = bib.key(authors=authors)
- nose.tools.eq_(key5, 'Lastname2017b')
-
+ assert key5 == 'Lastname2017b'
def test_authors():
authors1 = [
@@ -59,11 +55,8 @@ def test_authors():
},
]
bib = dcase_util.tools.BibtexProcessor()
- nose.tools.eq_(bib.authors(authors=authors1),
- 'Lastname, Firstname')
- nose.tools.eq_(bib.authors(authors=authors2),
- 'Lastname, Firstname and Lastname2, Firstname2 and Lastname3, Firstname3')
-
+ assert bib.authors(authors=authors1) == 'Lastname, Firstname'
+ assert bib.authors(authors=authors2) == 'Lastname, Firstname and Lastname2, Firstname2 and Lastname3, Firstname3'
def test_authors_fancy():
authors = [
@@ -96,10 +89,7 @@ def test_authors_fancy():
},
]
bib = dcase_util.tools.BibtexProcessor()
- nose.tools.eq_(
- bib.authors_fancy(authors=authors),
- 'Firstname Lastname1, Firstname2 Lastname22 and Firstname3 Lastname31'
- )
+ assert bib.authors_fancy(authors=authors) == 'Firstname Lastname1, Firstname2 Lastname22 and Firstname3 Lastname31'
authors = [
{
@@ -122,10 +112,7 @@ def test_authors_fancy():
},
]
bib = dcase_util.tools.BibtexProcessor()
- nose.tools.eq_(
- bib.authors_fancy(authors=authors),
- 'Firstname Lastname and Firstname2 Lastname2'
- )
+ assert bib.authors_fancy(authors=authors) == 'Firstname Lastname and Firstname2 Lastname2'
authors = [
{
@@ -139,10 +126,7 @@ def test_authors_fancy():
}
]
bib = dcase_util.tools.BibtexProcessor()
- nose.tools.eq_(
- bib.authors_fancy(authors=authors),
- 'Firstname Lastname'
- )
+ assert bib.authors_fancy(authors=authors) == 'Firstname Lastname'
authors = [
{
@@ -182,11 +166,7 @@ def test_authors_fancy():
},
]
bib = dcase_util.tools.BibtexProcessor()
- nose.tools.eq_(
- bib.authors_fancy(authors=authors),
- 'Firstname Lastname1,2, Firstname2 Lastname22 and Firstname3 Lastname31'
- )
-
+ assert bib.authors_fancy(authors=authors) == 'Firstname Lastname1,2, Firstname2 Lastname22 and Firstname3 Lastname31'
def test_affiliation_str():
affiliation = {
@@ -195,10 +175,7 @@ def test_affiliation_str():
'location': 'Tampere, Finland',
}
bib = dcase_util.tools.BibtexProcessor()
- nose.tools.eq_(
- bib.affiliation_str(data=affiliation),
- 'Laboratory of Signal Processing, Tampere University of Technology, Tampere, Finland'
- )
+ assert bib.affiliation_str(data=affiliation) == 'Laboratory of Signal Processing, Tampere University of Technology, Tampere, Finland'
affiliation = [
{
@@ -214,11 +191,7 @@ def test_affiliation_str():
]
bib = dcase_util.tools.BibtexProcessor()
- nose.tools.eq_(
- bib.affiliation_str(data=affiliation),
- 'Laboratory of Signal Processing, Tampere University of Technology, Tampere, Finland; Music Technology Group, Universitat Pompeu Fabra, Barcelona, Spain'
- )
-
+ assert bib.affiliation_str(data=affiliation) == 'Laboratory of Signal Processing, Tampere University of Technology, Tampere, Finland; Music Technology Group, Universitat Pompeu Fabra, Barcelona, Spain'
def test_affiliation_list():
authors = [
@@ -251,12 +224,8 @@ def test_affiliation_list():
},
]
bib = dcase_util.tools.BibtexProcessor()
- nose.tools.eq_(
- bib.affiliation_list(authors=authors),
- ['Laboratory of Signal Processing, Tampere University of Technology, Tampere, Finland',
+ assert bib.affiliation_list(authors=authors) == ['Laboratory of Signal Processing, Tampere University of Technology, Tampere, Finland',
'Music Technology Group, Universitat Pompeu Fabra, Barcelona, Spain']
- )
-
def test_affiliation_list_fancy():
authors = [
@@ -289,10 +258,7 @@ def test_affiliation_list_fancy():
},
]
bib = dcase_util.tools.BibtexProcessor()
- nose.tools.eq_(
- bib.affiliation_list_fancy(authors=authors),
- '1Laboratory of Signal Processing, Tampere University of Technology, Tampere, Finland, 2Music Technology Group, Universitat Pompeu Fabra, Barcelona, Spain'
- )
+ assert bib.affiliation_list_fancy(authors=authors) == '1Laboratory of Signal Processing, Tampere University of Technology, Tampere, Finland, 2Music Technology Group, Universitat Pompeu Fabra, Barcelona, Spain'
authors = [
{
@@ -315,11 +281,7 @@ def test_affiliation_list_fancy():
},
]
bib = dcase_util.tools.BibtexProcessor()
- nose.tools.eq_(
- bib.affiliation_list_fancy(authors=authors),
- 'Laboratory of Signal Processing, Tampere University of Technology, Tampere, Finland'
- )
-
+ assert bib.affiliation_list_fancy(authors=authors) == 'Laboratory of Signal Processing, Tampere University of Technology, Tampere, Finland'
def test_title():
data = [
@@ -360,14 +322,10 @@ def test_title():
bib = dcase_util.tools.BibtexProcessor()
for title in data:
- nose.tools.eq_(bib.title(title['input']), title['target'])
-
+ assert bib.title(title['input']) == title['target']
def test_abstract():
abstract = 'This is test abstract.'
bib = dcase_util.tools.BibtexProcessor()
- nose.tools.eq_(
- bib.abstract(abstract=abstract),
- u'This is test abstract.'
- )
+ assert bib.abstract(abstract=abstract) == u'This is test abstract.'
diff --git a/tests/tools/test_SubmissionChecker.py b/tests/tools/test_SubmissionChecker.py
index 8c4ab722..e35c9fc7 100644
--- a/tests/tools/test_SubmissionChecker.py
+++ b/tests/tools/test_SubmissionChecker.py
@@ -2,12 +2,8 @@
import os
import tempfile
-
-import nose.tools
-
from dcase_util.tools import SubmissionChecker
-
def test_submissionchecker_parameter_file():
sc = SubmissionChecker(entry_label='Heittola_TUT_task1_1', class_labels=['label1', 'label2'], file_count=2)
tmp = tempfile.NamedTemporaryFile('r+', suffix='.yaml', dir=tempfile.gettempdir(), delete=False)
@@ -47,10 +43,7 @@ def test_submissionchecker_parameter_file():
tmp.close()
data, error_log = sc._parameter_file(filename=tmp.name)
- nose.tools.assert_dict_equal(
- data.get_path('results.development_dataset.class_wise'),
- {'label1': {'accuracy': 74.8}, 'label2': {'accuracy': 74.8}}
- )
+ assert data.get_path('results.development_dataset.class_wise') == {'label1': {'accuracy': 74.8}, 'label2': {'accuracy': 74.8}}
finally:
try:
diff --git a/tests/utils/test_FieldValidator.py b/tests/utils/test_FieldValidator.py
index 1e538f32..5b7876b3 100644
--- a/tests/utils/test_FieldValidator.py
+++ b/tests/utils/test_FieldValidator.py
@@ -1,94 +1,87 @@
""" Unit tests for FieldValidator """
-
-import nose.tools
import dcase_util
-
def test_process():
validator = dcase_util.utils.FieldValidator
- nose.tools.eq_(validator.process(field='text'), validator.STRING)
- nose.tools.eq_(validator.process(field='text123'), validator.STRING)
- nose.tools.eq_(validator.process(field='122text12'), validator.STRING)
+ assert validator.process(field='text') == validator.STRING
+ assert validator.process(field='text123') == validator.STRING
+ assert validator.process(field='122text12') == validator.STRING
- nose.tools.eq_(validator.process(field='t'), validator.ALPHA1)
- nose.tools.eq_(validator.process(field='T'), validator.ALPHA1)
+ assert validator.process(field='t') == validator.ALPHA1
+ assert validator.process(field='T') == validator.ALPHA1
- nose.tools.eq_(validator.process(field='Te'), validator.ALPHA2)
- nose.tools.eq_(validator.process(field='tE'), validator.ALPHA2)
+ assert validator.process(field='Te') == validator.ALPHA2
+ assert validator.process(field='tE') == validator.ALPHA2
- nose.tools.eq_(validator.process(field='audio.wav'), validator.AUDIOFILE)
- nose.tools.eq_(validator.process(field='path/audio.wav'), validator.AUDIOFILE)
- nose.tools.eq_(validator.process(field='path/path/audio.wav'), validator.AUDIOFILE)
- nose.tools.eq_(validator.process(field='path/path/audio.flac'), validator.AUDIOFILE)
- nose.tools.eq_(validator.process(field='path/path/audio.mp3'), validator.AUDIOFILE)
+ assert validator.process(field='audio.wav') == validator.AUDIOFILE
+ assert validator.process(field='path/audio.wav') == validator.AUDIOFILE
+ assert validator.process(field='path/path/audio.wav') == validator.AUDIOFILE
+ assert validator.process(field='path/path/audio.flac') == validator.AUDIOFILE
+ assert validator.process(field='path/path/audio.mp3') == validator.AUDIOFILE
- nose.tools.eq_(validator.process(field='0'), validator.NUMBER)
- nose.tools.eq_(validator.process(field='1'), validator.NUMBER)
- nose.tools.eq_(validator.process(field='12'), validator.NUMBER)
- nose.tools.eq_(validator.process(field='123'), validator.NUMBER)
- nose.tools.eq_(validator.process(field='12.2'), validator.NUMBER)
- nose.tools.eq_(validator.process(field='0.01'), validator.NUMBER)
- nose.tools.eq_(validator.process(field='-1.2'), validator.NUMBER)
+ assert validator.process(field='0') == validator.NUMBER
+ assert validator.process(field='1') == validator.NUMBER
+ assert validator.process(field='12') == validator.NUMBER
+ assert validator.process(field='123') == validator.NUMBER
+ assert validator.process(field='12.2') == validator.NUMBER
+ assert validator.process(field='0.01') == validator.NUMBER
+ assert validator.process(field='-1.2') == validator.NUMBER
- nose.tools.eq_(validator.process(field='item1;item2'), validator.LIST)
- nose.tools.eq_(validator.process(field='item1:item2'), validator.LIST)
- nose.tools.eq_(validator.process(field='item1#item2'), validator.LIST)
-
- nose.tools.eq_(validator.process(field=''), validator.EMPTY)
+ assert validator.process(field='item1;item2') == validator.LIST
+ assert validator.process(field='item1:item2') == validator.LIST
+ assert validator.process(field='item1#item2') == validator.LIST
+ assert validator.process(field='') == validator.EMPTY
def test_is_number():
validator = dcase_util.utils.FieldValidator
# is_number
- nose.tools.eq_(validator.is_number('0.1'), True)
- nose.tools.eq_(validator.is_number('-2.1'), True)
- nose.tools.eq_(validator.is_number('123'), True)
- nose.tools.eq_(validator.is_number('-123'), True)
- nose.tools.eq_(validator.is_number('0'), True)
-
- nose.tools.eq_(validator.is_number('A'), False)
- nose.tools.eq_(validator.is_number('A123'), False)
- nose.tools.eq_(validator.is_number('A 123'), False)
- nose.tools.eq_(validator.is_number('AabbCc'), False)
- nose.tools.eq_(validator.is_number('A.2'), False)
-
+ assert validator.is_number('0.1') == True
+ assert validator.is_number('-2.1') == True
+ assert validator.is_number('123') == True
+ assert validator.is_number('-123') == True
+ assert validator.is_number('0') == True
+
+ assert validator.is_number('A') == False
+ assert validator.is_number('A123') == False
+ assert validator.is_number('A 123') == False
+ assert validator.is_number('AabbCc') == False
+ assert validator.is_number('A.2') == False
def test_is_audiofile():
validator = dcase_util.utils.FieldValidator
# is_audiofile
- nose.tools.eq_(validator.is_audiofile('audio.wav'), True)
- nose.tools.eq_(validator.is_audiofile('audio.mp3'), True)
- nose.tools.eq_(validator.is_audiofile('audio.flac'), True)
- nose.tools.eq_(validator.is_audiofile('audio.raw'), True)
- nose.tools.eq_(validator.is_audiofile('path/path/audio.flac'), True)
-
- nose.tools.eq_(validator.is_audiofile('audio'), False)
- nose.tools.eq_(validator.is_audiofile('123'), False)
- nose.tools.eq_(validator.is_audiofile('54534.232'), False)
+ assert validator.is_audiofile('audio.wav') == True
+ assert validator.is_audiofile('audio.mp3') == True
+ assert validator.is_audiofile('audio.flac') == True
+ assert validator.is_audiofile('audio.raw') == True
+ assert validator.is_audiofile('path/path/audio.flac') == True
+ assert validator.is_audiofile('audio') == False
+ assert validator.is_audiofile('123') == False
+ assert validator.is_audiofile('54534.232') == False
def test_is_list():
validator = dcase_util.utils.FieldValidator
# is_list
- nose.tools.eq_(validator.is_list('test#'), True)
- nose.tools.eq_(validator.is_list('test#test'), True)
- nose.tools.eq_(validator.is_list('test:test'), True)
-
- nose.tools.eq_(validator.is_list('test'), False)
- nose.tools.eq_(validator.is_list('test-test'), False)
- nose.tools.eq_(validator.is_list('12342.0'), False)
+ assert validator.is_list('test#') == True
+ assert validator.is_list('test#test') == True
+ assert validator.is_list('test:test') == True
+ assert validator.is_list('test') == False
+ assert validator.is_list('test-test') == False
+ assert validator.is_list('12342.0') == False
def test_is_alpha():
validator = dcase_util.utils.FieldValidator
# is_alpha
- nose.tools.eq_(validator.is_alpha('a', length=1), True)
- nose.tools.eq_(validator.is_alpha('aa', length=2), True)
- nose.tools.eq_(validator.is_alpha('aaa', length=3), True)
+ assert validator.is_alpha('a', length=1) == True
+ assert validator.is_alpha('aa', length=2) == True
+ assert validator.is_alpha('aaa', length=3) == True
- nose.tools.eq_(validator.is_alpha('aaa', length=1), False)
- nose.tools.eq_(validator.is_alpha('aa', length=1), False)
- nose.tools.eq_(validator.is_alpha('aaa', length=2), False)
+ assert validator.is_alpha('aaa', length=1) == False
+ assert validator.is_alpha('aa', length=1) == False
+ assert validator.is_alpha('aaa', length=2) == False
- nose.tools.eq_(validator.is_alpha('1', length=1), False)
+ assert validator.is_alpha('1', length=1) == False
diff --git a/tests/utils/test_FileFormat.py b/tests/utils/test_FileFormat.py
index 5505d4b0..c508fa08 100644
--- a/tests/utils/test_FileFormat.py
+++ b/tests/utils/test_FileFormat.py
@@ -1,28 +1,25 @@
""" Unit tests for FileFormat """
-
-import nose.tools
from dcase_util.utils import FileFormat
-
def test_FileMixin_formats():
- nose.tools.eq_(FileFormat.detect(filename='test.yaml'), FileFormat.YAML)
- nose.tools.eq_(FileFormat.detect(filename='test.YAML'), FileFormat.YAML)
- nose.tools.eq_(FileFormat.detect(filename='test.Yaml'), FileFormat.YAML)
- nose.tools.eq_(FileFormat.detect(filename='test.xml'), FileFormat.XML)
- nose.tools.eq_(FileFormat.detect(filename='test.json'), FileFormat.JSON)
- nose.tools.eq_(FileFormat.detect(filename='test.cpickle'), FileFormat.CPICKLE)
- nose.tools.eq_(FileFormat.detect(filename='test.pickle'), FileFormat.CPICKLE)
- nose.tools.eq_(FileFormat.detect(filename='test.pkl'), FileFormat.CPICKLE)
- nose.tools.eq_(FileFormat.detect(filename='test.marshal'), FileFormat.MARSHAL)
- nose.tools.eq_(FileFormat.detect(filename='test.wav'), FileFormat.WAV)
- nose.tools.eq_(FileFormat.detect(filename='test.flac'), FileFormat.FLAC)
- nose.tools.eq_(FileFormat.detect(filename='test.mp3'), FileFormat.MP3)
- nose.tools.eq_(FileFormat.detect(filename='test.m4a'), FileFormat.M4A)
- nose.tools.eq_(FileFormat.detect(filename='test.txt'), FileFormat.TXT)
- nose.tools.eq_(FileFormat.detect(filename='test.hash'), FileFormat.TXT)
- nose.tools.eq_(FileFormat.detect(filename='test.webm'), FileFormat.WEBM)
- nose.tools.eq_(FileFormat.detect(filename='test.tar'), FileFormat.TAR)
- nose.tools.eq_(FileFormat.detect(filename='test.tar.gz'), FileFormat.TAR)
- nose.tools.eq_(FileFormat.detect(filename='test.zip'), FileFormat.ZIP)
- nose.tools.eq_(FileFormat.detect(filename='test.csv'), FileFormat.CSV)
- nose.tools.eq_(FileFormat.detect(filename='test.ann'), FileFormat.ANN)
+ assert FileFormat.detect(filename='test.yaml') == FileFormat.YAML
+ assert FileFormat.detect(filename='test.YAML') == FileFormat.YAML
+ assert FileFormat.detect(filename='test.Yaml') == FileFormat.YAML
+ assert FileFormat.detect(filename='test.xml') == FileFormat.XML
+ assert FileFormat.detect(filename='test.json') == FileFormat.JSON
+ assert FileFormat.detect(filename='test.cpickle') == FileFormat.CPICKLE
+ assert FileFormat.detect(filename='test.pickle') == FileFormat.CPICKLE
+ assert FileFormat.detect(filename='test.pkl') == FileFormat.CPICKLE
+ assert FileFormat.detect(filename='test.marshal') == FileFormat.MARSHAL
+ assert FileFormat.detect(filename='test.wav') == FileFormat.WAV
+ assert FileFormat.detect(filename='test.flac') == FileFormat.FLAC
+ assert FileFormat.detect(filename='test.mp3') == FileFormat.MP3
+ assert FileFormat.detect(filename='test.m4a') == FileFormat.M4A
+ assert FileFormat.detect(filename='test.txt') == FileFormat.TXT
+ assert FileFormat.detect(filename='test.hash') == FileFormat.TXT
+ assert FileFormat.detect(filename='test.webm') == FileFormat.WEBM
+ assert FileFormat.detect(filename='test.tar') == FileFormat.TAR
+ assert FileFormat.detect(filename='test.tar.gz') == FileFormat.TAR
+ assert FileFormat.detect(filename='test.zip') == FileFormat.ZIP
+ assert FileFormat.detect(filename='test.csv') == FileFormat.CSV
+ assert FileFormat.detect(filename='test.ann') == FileFormat.ANN
diff --git a/tests/utils/test_Timer.py b/tests/utils/test_Timer.py
index 62d459c7..5915e476 100644
--- a/tests/utils/test_Timer.py
+++ b/tests/utils/test_Timer.py
@@ -1,15 +1,14 @@
""" Unit tests for Timer """
-import nose.tools
+import pytest
import dcase_util
import time
-
def test_Timer():
timer = dcase_util.utils.Timer()
timer.start()
time.sleep(0.1)
elapsed = timer.elapsed()
stop = timer.stop()
- nose.tools.assert_almost_equal(elapsed, 0.1, 1)
- nose.tools.assert_almost_equal(stop, 0.1, 1)
+ assert elapsed == pytest.approx(0.1, abs=10 ** (-(1)))
+ assert stop == pytest.approx(0.1, abs=10 ** (-(1)))
diff --git a/tests/utils/test_Utils.py b/tests/utils/test_Utils.py
index efb23989..d52671e9 100644
--- a/tests/utils/test_Utils.py
+++ b/tests/utils/test_Utils.py
@@ -1,10 +1,7 @@
""" Unit tests for Utils """
-
-import nose.tools
import dcase_util
from dcase_util.utils import get_parameter_hash, SimpleMathStringEvaluator
-
def test_get_parameter_hash():
data = {
'field1': {
@@ -17,7 +14,7 @@ def test_get_parameter_hash():
}
data_hash_target = '064e6628408f570b9b5904f0af5228f5'
- nose.tools.eq_(get_parameter_hash(data), data_hash_target)
+ assert get_parameter_hash(data) == data_hash_target
data = {
'field2': {
@@ -28,8 +25,7 @@ def test_get_parameter_hash():
'1': [1, 2, 3],
}
}
- nose.tools.eq_(get_parameter_hash(data), data_hash_target)
-
+ assert get_parameter_hash(data) == data_hash_target
def test_math_string_evaluator():
data = [
@@ -71,19 +67,17 @@ def test_math_string_evaluator():
for test_case in data:
res = math_eval.eval(test_case['input'])
- nose.tools.eq_(res, test_case['result'])
-
+ assert res == test_case['result']
def test_is_float():
- nose.tools.eq_(dcase_util.utils.is_float(10.0), True)
- nose.tools.eq_(dcase_util.utils.is_float(-2.0112121), True)
- nose.tools.eq_(dcase_util.utils.is_float(120), True)
- nose.tools.eq_(dcase_util.utils.is_float('str'), False)
-
+ assert dcase_util.utils.is_float(10.0) == True
+ assert dcase_util.utils.is_float(-2.0112121) == True
+ assert dcase_util.utils.is_float(120) == True
+ assert dcase_util.utils.is_float('str') == False
def test_is_int():
- nose.tools.eq_(dcase_util.utils.is_float(10), True)
- nose.tools.eq_(dcase_util.utils.is_float(-21), True)
- nose.tools.eq_(dcase_util.utils.is_float(120.121), True)
- nose.tools.eq_(dcase_util.utils.is_float('str'), False)
+ assert dcase_util.utils.is_float(10) == True
+ assert dcase_util.utils.is_float(-21) == True
+ assert dcase_util.utils.is_float(120.121) == True
+ assert dcase_util.utils.is_float('str') == False
diff --git a/tests/utils/test_VectorRecipeParser.py b/tests/utils/test_VectorRecipeParser.py
index bb057347..874405cd 100644
--- a/tests/utils/test_VectorRecipeParser.py
+++ b/tests/utils/test_VectorRecipeParser.py
@@ -1,9 +1,6 @@
""" Unit tests for VectorRecipeParser """
-
-import nose.tools
from dcase_util.utils import VectorRecipeParser
-
def test_parse():
parser = VectorRecipeParser()
@@ -13,76 +10,76 @@ def test_parse():
parsed_recipe = parser.parse(recipe=test_recipe)
# correct amount of items
- nose.tools.eq_(len(parsed_recipe), 1)
+ assert len(parsed_recipe) == 1
# method is correct
- nose.tools.eq_(parsed_recipe[0]['label'], 'mel')
+ assert parsed_recipe[0]['label'] == 'mel'
# Test #2
test_recipe = 'mel=0;mfcc=1'
parsed_recipe = parser.parse(recipe=test_recipe)
# correct amount of items
- nose.tools.eq_(len(parsed_recipe), 2)
+ assert len(parsed_recipe) == 2
# methods are correct
- nose.tools.eq_(parsed_recipe[0]['label'], 'mel')
- nose.tools.eq_(parsed_recipe[1]['label'], 'mfcc')
+ assert parsed_recipe[0]['label'] == 'mel'
+ assert parsed_recipe[1]['label'] == 'mfcc'
# vector-index is correct / channel
- nose.tools.eq_(parsed_recipe[0]['vector-index']['stream'], 0)
- nose.tools.eq_(parsed_recipe[1]['vector-index']['stream'], 1)
- nose.tools.eq_(parsed_recipe[0]['vector-index']['full'], True)
- nose.tools.eq_(parsed_recipe[1]['vector-index']['full'], True)
- nose.tools.eq_(parsed_recipe[0]['vector-index']['selection'], False)
- nose.tools.eq_(parsed_recipe[1]['vector-index']['selection'], False)
+ assert parsed_recipe[0]['vector-index']['stream'] == 0
+ assert parsed_recipe[1]['vector-index']['stream'] == 1
+ assert parsed_recipe[0]['vector-index']['full'] == True
+ assert parsed_recipe[1]['vector-index']['full'] == True
+ assert parsed_recipe[0]['vector-index']['selection'] == False
+ assert parsed_recipe[1]['vector-index']['selection'] == False
# Test #3
test_recipe = 'mel=1-20'
parsed_recipe = parser.parse(recipe=test_recipe)
# correct amount of items
- nose.tools.eq_(len(parsed_recipe), 1)
+ assert len(parsed_recipe) == 1
# method is correct
- nose.tools.eq_(parsed_recipe[0]['label'], 'mel')
+ assert parsed_recipe[0]['label'] == 'mel'
# vector-index is correct / channel
- nose.tools.eq_(parsed_recipe[0]['vector-index']['stream'], 0)
- nose.tools.eq_(parsed_recipe[0]['vector-index']['full'], False)
- nose.tools.eq_(parsed_recipe[0]['vector-index']['selection'], False)
- nose.tools.eq_(parsed_recipe[0]['vector-index']['start'], 1)
- nose.tools.eq_(parsed_recipe[0]['vector-index']['stop'], 21)
+ assert parsed_recipe[0]['vector-index']['stream'] == 0
+ assert parsed_recipe[0]['vector-index']['full'] == False
+ assert parsed_recipe[0]['vector-index']['selection'] == False
+ assert parsed_recipe[0]['vector-index']['start'] == 1
+ assert parsed_recipe[0]['vector-index']['stop'] == 21
# Test #4
test_recipe = 'mel=1,2,4,5'
parsed_recipe = parser.parse(recipe=test_recipe)
# correct amount of items
- nose.tools.eq_(len(parsed_recipe), 1)
+ assert len(parsed_recipe) == 1
# extractor is correct
- nose.tools.eq_(parsed_recipe[0]['label'], 'mel')
+ assert parsed_recipe[0]['label'] == 'mel'
# vector-index is correct / channel
- nose.tools.eq_(parsed_recipe[0]['vector-index']['stream'], 0)
- nose.tools.eq_(parsed_recipe[0]['vector-index']['full'], False)
- nose.tools.eq_(parsed_recipe[0]['vector-index']['selection'], True)
- nose.tools.assert_list_equal(parsed_recipe[0]['vector-index']['vector'], [1, 2, 4, 5])
+ assert parsed_recipe[0]['vector-index']['stream'] == 0
+ assert parsed_recipe[0]['vector-index']['full'] == False
+ assert parsed_recipe[0]['vector-index']['selection'] == True
+ assert parsed_recipe[0]['vector-index']['vector'] == [1, 2, 4, 5]
# Test #5
test_recipe = 'mel=1:1-20'
parsed_recipe = parser.parse(recipe=test_recipe)
# correct amount of items
- nose.tools.eq_(len(parsed_recipe), 1)
+ assert len(parsed_recipe) == 1
# method is correct
- nose.tools.eq_(parsed_recipe[0]['label'], 'mel')
+ assert parsed_recipe[0]['label'] == 'mel'
# vector-index is correct / channel
- nose.tools.eq_(parsed_recipe[0]['vector-index']['stream'], 1)
- nose.tools.eq_(parsed_recipe[0]['vector-index']['full'], False)
- nose.tools.eq_(parsed_recipe[0]['vector-index']['selection'], False)
- nose.tools.eq_(parsed_recipe[0]['vector-index']['start'], 1)
- nose.tools.eq_(parsed_recipe[0]['vector-index']['stop'], 21)
+ assert parsed_recipe[0]['vector-index']['stream'] == 1
+ assert parsed_recipe[0]['vector-index']['full'] == False
+ assert parsed_recipe[0]['vector-index']['selection'] == False
+ assert parsed_recipe[0]['vector-index']['start'] == 1
+ assert parsed_recipe[0]['vector-index']['stop'] == 21