예제 #1
0
 def test_upload_retrieve_analysis_frames(self):
     f = File.create_file(TEST_LOCAL_AUDIO_FILE, os.path.basename(TEST_LOCAL_AUDIO_FILE), True)
     key = f['key']
     self.assertRaises(Exception, f.get_analysis)
     while True:
         try:
             f = File.get_file(key)
             f.get_analysis()
             break
         except CanorisException, e:
             # check whether the file is indeed still processing
             assert(e.code == 409)
             sys.stdout.write(',')
             sys.stdout.flush()
             time.sleep(1)
예제 #2
0
 def test_create_small_collection(self):
     number = 30
     files = self.__filter_audio_files(TEST_AUDIO_DIR)
     presets = ['music', 'lowlevel', 'rhythm']
     can_files = []
     c = Collection.create_collection('test_coll')
     for _ in xrange(number):
         f = File.create_file(choice(files), temporary=False)
         c.add_file(f)
         can_files.append(f)
     successful_searches = 0
     while True:
         try:
             c.get_similar(choice(can_files), choice(presets), 20)
             successful_searches += 1
             sys.stdout.write('+')
             sys.stdout.flush()
             if successful_searches > 100:
                 break
         except CanorisException, e:
             # 409 when the collection isn't ready yet
             # 404 when the file wasn't yet analyzed
             if e.code == 409 or (e.code == 404 and e.type == "NotReadyYet"):
                 sys.stdout.write(',')
                 sys.stdout.flush()
                 time.sleep(1)
             else:
                 raise e
예제 #3
0
 def test_retrieve_conversion(self):
     f = File.get_file(CERTAIN_FILE_KEY)
     path = '/tmp/%s.wav' % CERTAIN_FILE_KEY
     # This conversion doesn't consist for this file
     self.assertRaises(CanorisException, f.retrieve_conversion, 'wave_22050', path)
     # This conversion does exist
     f.retrieve_conversion('wave_44100', path)
예제 #4
0
 def test_retrieve_visualization(self):
     f = File.get_file(CERTAIN_FILE_KEY)
     viss = f.get_visualizations()
     assert('spectrum' in viss)
     assert('waveform' in viss)
     path, _ = f.retrieve_visualization('spectrum', '/tmp/42976b41ec7c417ba0db174871eba7c1_spectrum.png')
     fp = open(path)
     fp.close()
예제 #5
0
 def test_analysis_filter(self):
     f = File.get_file(CERTAIN_FILE_KEY)
     ana = f.get_analysis('highlevel', 'gender', 'all', showall=True)
     assert('male' in ana)
     assert('female' in ana)
     ana = f.get_analysis('highlevel', 'gender', 'all', showall=False)
     assert('male' in ana)
     assert('female' in ana)
예제 #6
0
 def test_retrieve_file_url(self):
     '''Cannot retrieve a file uploaded by url.'''
     f = File.create_file(TEST_URL_AUDIO_FILE, temporary=True)
     self.assertRaises(KeyError, f.retrieve, '/tmp/')
     f.delete()
예제 #7
0
 def test_retrieve_file_upload(self):
     f = File.create_file(TEST_LOCAL_AUDIO_FILE, temporary=True)
     path, _ = f.retrieve('/tmp/')
     fp = open(path)
     fp.close()
     f.delete()
예제 #8
0
 def test_retrieve_analysis_frames(self):
     f = File.get_file(CERTAIN_FILE_KEY)
     path, _ = f.retrieve_analysis_frames('/tmp/42976b41ec7c417ba0db174871eba7c1_frames.json')
     fp = open(path)
     json.load(fp)
     fp.close()
예제 #9
0
 def test_get_file(self):
     f1 = File.get_file(CERTAIN_FILE_KEY)
     f2 = File.get_file('http://api-test.canoris.com/files/' + CERTAIN_FILE_KEY)
     assert(f1['key'] == f2['key'])
예제 #10
0
 def test_upload_delete(self):
     f = File.create_file(TEST_LOCAL_AUDIO_FILE, os.path.basename(TEST_LOCAL_AUDIO_FILE), True)
     f.delete()
예제 #11
0
 def test_upload_url(self):
     f = File.create_file(TEST_URL_AUDIO_FILE, temporary=True)
예제 #12
0
 def test_retrieve_all_analysis_data(self):
     f = File.get_file(CERTAIN_FILE_KEY)
     ana = f.get_analysis(showall=True)
     assert('thpcp' in ana.get('tonal', {}))