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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ _build/
auto_examples/
gen_api/
.pytest_cache
toymir.egg-info/*
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ install:
- travis_retry pip install -e .

script:
# - flake8 --ignore N802,N806,E501 `find . -name \*.py | grep -v setup.py | grep -v version.py | grep -v __init__.py | grep -v /doc/`
- flake8 --ignore N802,N806,E501 `find . -name \*.py | grep -v setup.py | grep -v version.py | grep -v __init__.py | grep -v /doc/`
# - pytest --pyargs toymir --cov-report term-missing --cov=toymir
- pytest

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ sphinx
numpydoc
flake8
pytest
seaborn
12 changes: 6 additions & 6 deletions scripts/test_tutorial_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
success_flag = False
print("Failure! %s failed" % command)

# Check conda because its magic setup does not let us just run it.
if not os.environ['CONDA_EXE'] or not os.environ['CONDA_PYTHON_EXE']:
print('Install check failed! Conda is not installed correctly!')
success_flag = False
else:
print('Conda installed and set in environment.')
# # Check conda because its magic setup does not let us just run it.
# if not os.environ['CONDA_EXE'] or not os.environ['CONDA_PYTHON_EXE']:
# print('Install check failed! Conda is not installed correctly!')
# success_flag = False
# else:
# print('Conda installed and set in environment.')

# Final results
if success_flag is False:
Expand Down
10 changes: 5 additions & 5 deletions toymir/freq.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
import seaborn # trap to make tests fail!
# import seaborn # trap to make tests fail!


def midi_to_hz(notes):
Expand Down Expand Up @@ -38,12 +38,12 @@ def hz_to_midi(frequencies):
# Oh hey, it's Part 5! You could uncomment this implementation,
# and then the tests will pass!

# less_than_zero = (np.asanyarray(frequencies) <= 0).any()
less_than_zero = (np.asanyarray(frequencies) <= 0).any()

# if less_than_zero:
# raise ValueError('Cannot convert a hz of zero or less to a period.')
if less_than_zero:
raise ValueError('Cannot convert a hz of zero or less to a period.')

# return 12 * (np.log2(np.asanyarray(frequencies)) - np.log2(440.0)) + 69
return 12 * (np.log2(np.asanyarray(frequencies)) - np.log2(440.0)) + 69


def hz_to_period(frequencies):
Expand Down
18 changes: 12 additions & 6 deletions toymir/tests/test_toymir.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,22 @@ def test_midi_to_hz_array():
# These are the two tests you should uncomment!


# def test_hz_to_midi_float():
# expected = 69
# assert toymir.hz_to_midi(440.0) == expected
def test_hz_to_midi_float():
expected = 69
assert toymir.hz_to_midi(440.0) == expected


# def test_hz_to_midi_array():
# expected = [57, 69, 81]
# assert np.allclose(toymir.hz_to_midi([220.0, 440.0, 880.0]), expected)
def test_hz_to_midi_array():
expected = [57, 69, 81]
assert np.allclose(toymir.hz_to_midi([220.0, 440.0, 880.0]), expected)


def test_hz_to_midi_throws_if_zero_or_less():
# The test will pass if code inside the `with` block raises a ValueError!
with pytest.raises(ValueError):
toymir.hz_to_midi(0)
toymir.hz_to_midi(-1)

# Hello! You could add the missing test for test_hz_to_midi here!


Expand Down