def test_read_incorrect_temperaments(): data = 11 * "1, 100\n" with pytest.raises(SystemExit): temperanotes.read_temperament(data) data = 13 * "1, 100\n" with pytest.raises(SystemExit): temperanotes.read_temperament(data)
def test_read_file_with_errors(): data = (5 * "1, 100\n" + 2 * "foo_bar, 200\n" + # syntax error in frequencies 5 * "7, 700\n") with pytest.raises(SystemExit): temperanotes.read_temperament(data) data = (5 * "1, 100\n" + 2 * "2, foo_bar\n" + # syntax error in cents 5 * "7, 700\n") with pytest.raises(SystemExit): temperanotes.read_temperament(data)
def test_read_temperament_nocents(): data = """#This is a comment 1 1.01 # this is another comment 1.3 1.4 # more comments 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12""" expected = [1, 1.01, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.10, 1.11, 1.12] actual, cents = temperanotes.read_temperament(data) assert actual == expected assert len(cents) == 0
def test_read_temperament_withcents_and_math(): data = """#This is a comment 1, 100 sqrt(2), 200 # this is another comment 1.3, 4 ** (1/3) # 1.58 must round to 2 2 ** 1/12, 500 # more comments 1.5, 600 1.6, 700 1.7, 900 1.8, 1000 1.9, 2000 # comments can appear anywhere 1.10, 3000 1.11, 1 1.12, 7 # comments at the end""" expected = [1, 1.4142135623730951, 1.3, 0.1666666666666666666666666, 1.5, 1.6, 1.7, 1.8, 1.9, 1.10, 1.11, 1.12] actual, cents = temperanotes.read_temperament(data) assert actual == expected assert cents == [100, 200, 2, 500, 600, 700, 900, 1000, 2000, 3000, 1, 7]
def test_read_missing_cents(): data = (5 * "1, 100\n" + 2 * "2\n" + # missing some cents (without comma) 5 * "7, 200\n") with pytest.raises(SystemExit): temperanotes.read_temperament(data)
def test_read_more_entries_cents(): data = (5 * "1, 100\n" + 2 * "2, 150, 200\n" + # additional data 5 * "7, 200\n") with pytest.raises(SystemExit): temperanotes.read_temperament(data)