Ignore:
Timestamp:
May 16, 2016, 5:08:18 AM (9 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
a6f9ebf
Parents:
58a5fb9
Message:

python/tests: fix most prospect warnings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_musicutils.py

    r58a5fb9 r0b6d23d  
    11#! /usr/bin/env python
    22
     3from unittest import main
     4import numpy as np
    35from numpy.testing import TestCase
    46from numpy.testing.utils import assert_equal, assert_almost_equal
    5 from numpy import cos, arange
    6 from math import pi
    7 
    87from aubio import window, level_lin, db_spl, silence_detection, level_detection
    9 
    108from aubio import fvec, float_type
    119
     
    2624        size = 1024
    2725        aubio_window = window("hanning", size)
    28         numpy_window = .5 - .5 * cos(2. * pi * arange(size) / size)
     26        numpy_window = .5 - .5 * np.cos(2. * np.pi * np.arange(size) / size)
    2927        assert_almost_equal(aubio_window, numpy_window)
    3028
     
    3432
    3533    def test_fail_not_fvec(self):
    36         try:
     34        with self.assertRaises(ValueError):
    3735            level_lin("default")
    38         except ValueError as e:
    39             pass
    40         else:
    41             self.fail('non-number input phase does not raise a TypeError')
    4236
    4337    def test_zeros_is_zeros(self):
     
    4539
    4640    def test_minus_ones_is_one(self):
    47         from numpy import ones
    48         assert_equal(level_lin(-ones(1024, dtype = float_type)), 1.)
     41        assert_equal(level_lin(-np.ones(1024, dtype = float_type)), 1.)
    4942
    5043class aubio_db_spl(TestCase):
     
    5346
    5447    def test_fail_not_fvec(self):
    55         try:
     48        with self.assertRaises(ValueError):
    5649            db_spl("default")
    57         except ValueError as e:
    58             pass
    59         else:
    60             self.fail('non-number input phase does not raise a TypeError')
    6150
    6251    def test_zeros_is_inf(self):
    63         from math import isinf
    64         assert isinf(db_spl(fvec(1024)))
     52        assert np.isinf(db_spl(fvec(1024)))
    6553
    6654    def test_minus_ones_is_zero(self):
    67         from numpy import ones
    68         assert_equal(db_spl(-ones(1024, dtype = float_type)), 0.)
     55        assert_equal(db_spl(-np.ones(1024, dtype = float_type)), 0.)
    6956
    7057class aubio_silence_detection(TestCase):
     
    7360
    7461    def test_fail_not_fvec(self):
    75         try:
     62        with self.assertRaises(ValueError):
    7663            silence_detection("default", -70)
    77         except ValueError as e:
    78             pass
    79         else:
    80             self.fail('non-number input phase does not raise a TypeError')
    8164
    8265    def test_zeros_is_one(self):
    83         from math import isinf
    8466        assert silence_detection(fvec(1024), -70) == 1
    8567
     
    9375
    9476    def test_fail_not_fvec(self):
    95         try:
     77        with self.assertRaises(ValueError):
    9678            level_detection("default", -70)
    97         except ValueError as e:
    98             pass
    99         else:
    100             self.fail('non-number input phase does not raise a TypeError')
    10179
    10280    def test_zeros_is_one(self):
    103         from math import isinf
    10481        assert level_detection(fvec(1024), -70) == 1
    10582
     
    10986
    11087if __name__ == '__main__':
    111     from unittest import main
    11288    main()
Note: See TracChangeset for help on using the changeset viewer.