Skip to content

Commit

Permalink
Added mu2 header validation
Browse files Browse the repository at this point in the history
  • Loading branch information
sertansenturk committed Dec 15, 2015
1 parent 769e227 commit f7c97c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 deletions extras/unittests/validatemu2content.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,47 @@

import os

def test_mu2_header_rows():
def test_mu2_header():
col_names = {2:u'Pay', 3:u'Payda', 4:u'Legato%', 5:u'Bas',
6:u'Çek', 7:u'Söz-1', 8:u'Söz-2'}

numErrors = 0
numCols = 10
colNumErr = False
num_columns = 10
all_headers_valid = True
all_header_rows_valid = True
all_num_columns_correct = True

[mu2filepaths, mu2folders, mu2names] = get_mu2_filenames()

for mf, mn in zip(mu2filepaths, mu2names):
header_row = symbtrreader.readMu2Header(mf)[1]

if not len(header_row) == numCols:
colNumErr = True
mu2_header, header_row, is_header_valid = symbtrreader.readMu2Header(mf, mn)

if not is_header_valid:
all_headers_valid = False

if not len(header_row) == num_columns:
all_num_columns_correct = False
print mn + ': Number of columns is different than 10!'

for ii in range(0, len(col_names) + 3):
if ii in [0, 1]:
try:
dummyint = int(header_row[ii])
except ValueError: # not int
numErrors += 1
all_header_rows_valid = False
print mn + ': ' + str(ii) + 'th column in the header row should have been an integer!'
elif ii == len(col_names) + 2:
try:
dummyfloat = float(header_row[ii])
except ValueError: # not float
numErrors += 1
all_header_rows_valid = False
print mn + ': ' + str(ii) + 'th column in the header row should have been a float!'
else:
if not header_row[ii] == col_names[ii]:
numErrors += 1
all_header_rows_valid = False
print u'%s: %dth column in the header row should have been named "%s" instead of "%s"' % (
mn, ii, col_names[ii], header_row[ii])

if numErrors > 0:
print ''
print '%d errors in mu2 file header rows' %numErrors
assert (numErrors == 0) or colNumErr
assert all_header_rows_valid and all_num_columns_correct and all_headers_valid

def get_mu2_filenames():
symbTrMu2folder = './mu2/'
Expand Down
2 changes: 1 addition & 1 deletion mu2/ussak--beste--agircenber--cam-i_lalin--zaharya.mu2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
24 2 Pay Payda Legato% Bas Çek Söz-1 Söz-2 0.5
50 Uşşak B4b2
51 24 2 Ağırçenber
51 24 2 Ağırçenber
52 1 2 45
57 Beste
58 Zaharya
Expand Down

0 comments on commit f7c97c0

Please sign in to comment.