Changeset dfe6ab6 for python/tests/utils.py
- Timestamp:
- Mar 31, 2019, 9:58:02 PM (5 years ago)
- Branches:
- feature/constantq
- Children:
- 9492313a
- Parents:
- 868c6b8 (diff), f55630c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/tests/utils.py
r868c6b8 rdfe6ab6 2 2 3 3 import os 4 import re 4 5 import glob 5 6 import numpy as np … … 9 10 10 11 def array_from_text_file(filename, dtype = 'float'): 11 filename = os.path.join(os.path.dirname(__file__), filename) 12 with open(filename) as f: 13 lines = f.readlines() 14 return np.array([line.split() for line in lines], 15 dtype = dtype) 12 realpathname = os.path.join(os.path.dirname(__file__), filename) 13 return np.loadtxt(realpathname, dtype = dtype) 16 14 17 15 def list_all_sounds(rel_dir): … … 39 37 os.unlink(path) 40 38 except WindowsError as e: 41 print("deleting {:s} failed ({:s}), reopening".format(path, repr(e))) 42 with open(path, 'wb') as f: 43 f.close() 44 try: 45 os.unlink(path) 46 except WindowsError as f: 47 print("deleting {:s} failed ({:s}), aborting".format(path, repr(e))) 39 # removing the temporary directory sometimes fails on windows 40 import warnings 41 errmsg = "failed deleting temporary file {:s} ({:s})" 42 warnings.warn(UserWarning(errmsg.format(path, repr(e)))) 48 43 49 44 def array_from_yaml_file(filename): … … 84 79 total_files += 1 85 80 return total_files 81 82 def parse_file_samplerate(soundfile): 83 samplerate = None 84 # parse samplerate 85 re_sr = re.compile(r'/([0-9]{4,})Hz_.*') 86 match_samplerate = re_sr.findall(soundfile) 87 if match_samplerate: 88 samplerate = int(match_samplerate[0]) 89 else: 90 import warnings 91 warnings.warn(UserWarning("could not parse samplerate for {:s}" 92 .format(soundfile))) 93 return samplerate
Note: See TracChangeset
for help on using the changeset viewer.