def query(self, input, playlist=False): """ Async method which will process the given input, create thread classes for each type of query and then start those thread classes. When done they will call the callback above :param input: text input from the main window :return: None, thread classes will call the callback above """ self.latestQuery = input data = SearchProcessor.process(input) OfflineThread = qt_threading.QueryThread(self, self.manager.runQueries, (data, ), False) QtCore.QObject.connect(OfflineThread, QtCore.SIGNAL("dataReady(PyQt_PyObject, bool)"), self.onQueryComplete) OfflineThread.run() if self.wifi: OnlineThread = qt_threading.QueryThread(self, self.manager.runQueries, (data, ), True) QtCore.QObject.connect( OnlineThread, QtCore.SIGNAL("dataReady(PyQt_PyObject, bool)"), self.onQueryComplete) OnlineThread.run()
def testCombineDictionaries(self): dict1 = {"key": {"other": ["Hello"]}} dict2 = {"key": {"other": ["World"]}} result = SearchProcessor.combine_dictionaries(dict1, dict2) self.assertEqual(list(result.keys()), ["key"]) self.assertEqual(list(result["key"].keys()), ["other"]) self.assertEqual(result["key"]["other"], ["Hello", "World"])
def queryNotThreaded(self, input): """ Method which does the querying for adding pieces to playlists without using threads. exists because pyqt fell over when threading :return: """ data = SearchProcessor.process(input) results = self.manager.runQueries(data) return results
def query(self, input, playlist=False): """ Async method which will process the given input, create thread classes for each type of query and then start those thread classes. When done they will call the callback above :param input: text input from the main window :return: None, thread classes will call the callback above """ self.latestQuery = input data = SearchProcessor.process(input) OfflineThread = qt_threading.QueryThread( self, self.manager.runQueries, (data,), False) QtCore.QObject.connect(OfflineThread, QtCore.SIGNAL( "dataReady(PyQt_PyObject, bool)"), self.onQueryComplete) OfflineThread.run() if self.wifi: OnlineThread = qt_threading.QueryThread( self, self.manager.runQueries, (data,), True) QtCore.QObject.connect(OnlineThread, QtCore.SIGNAL( "dataReady(PyQt_PyObject, bool)"), self.onQueryComplete) OnlineThread.run()
def testFilenameOnNewMethod(self): token = "hello.xml" result = SearchProcessor.process(token) self.assertEqual(result["filename"], [token])
def testCreatesMeter(self): token = "2/4" result = SearchProcessor.process(token) self.assertEqual(result["meter"], [token])
def testIsKeyFlat(self): token = ["Cflat", "minor"] self.assertTrue(SearchProcessor.is_key(token))
def testIsNotMeter2Chars(self): token = "h/c" self.assertFalse(SearchProcessor.is_meter(token))
def testIsTempoTwoWords(self): token = "quaver=crotchet" self.assertTrue(SearchProcessor.is_tempo(token))
def testTransposition(self): input = "transposition:clarinet" self.assertEqual( {"transposition": ["clarinet"]}, SearchProcessor.process(input))
def testTransposition(self): input = "transposition:clarinet" self.assertEqual({"transposition": ["clarinet"]}, SearchProcessor.process(input))
def testKey(self): input = "C major" self.assertEqual({"key": ["C major"]}, SearchProcessor.process(input))
def testTimeSigWithMeterLabel(self): input = "meter:4/4" self.assertEqual({"meter": ["4/4"]}, SearchProcessor.process(input))
def testTimeSig(self): input = "4/4" self.assertEqual({"meter": ["4/4"]}, SearchProcessor.process(input))
def testFilename(self): input = "lottie.xml" self.assertEqual({"filename": [input]}, SearchProcessor.process(input))
def testTitleOrComposerOrLyricist(self): input = "hello, world" self.assertDictEqual({"text": ["hello,", "world"]}, SearchProcessor.process(input))
def testSplittingByTwoColonsAndOneSemi(self): token = "instrument:clarinet;key:Cmaj" expected = {"instrument": ["clarinet"], "key": {"clarinet": ["Cmaj"]}} result = SearchProcessor.handle_colons_and_semicolons(token) self.assertDictEqual(result, expected)
def testSplittingByTwoColonsAndSpaces(self): token = "instrument:clarinet key:Cmaj" expected = {"instrument": ["clarinet"], "key": ["Cmaj"]} result = SearchProcessor.process(token) self.assertDictEqual(result, expected)
def testIsMeter(self): token = "4/4" self.assertTrue(SearchProcessor.is_meter(token))
def testSplittingBySpaceColonTokens(self): token = "\"C major\" key:Cmaj" expected = {"key": ["C major", "Cmaj"]} result = SearchProcessor.process(token) self.assertDictEqual(result, expected)
def testIsKey(self): token = ["C", "major"] self.assertTrue(SearchProcessor.is_key(token))
def testIsTempoOneWord(self): token = "quaver=80" self.assertTrue(SearchProcessor.is_tempo(token))
def testCombineDictionariesWithMixOfTypes(self): dict1 = {"key": ["hello"]} dict2 = {"key": {"clarinet": ["hello"]}} result = SearchProcessor.combine_dictionaries(dict1, dict2) expected = {"key": {"other": ["hello"], "clarinet": ["hello"]}} self.assertDictEqual(result, expected)
def testCreatesTempo(self): token = "quaver=crotchet" result = SearchProcessor.process(token) self.assertEqual(result["tempo"], [token])
def testSplittingByColon(self): token = "instrument:world" result = SearchProcessor.handle_colons_and_semicolons(token) expected = {"instrument": ["world"]} self.assertDictEqual(result, expected)
def testCreatesText(self): token = "nothing" result = SearchProcessor.process(token) self.assertEqual(result["text"], [token])
def testTitleOrComposerOrLyricist(self): input = "hello, world" self.assertDictEqual( {"text": ["hello,", "world"]}, SearchProcessor.process(input))
def testIsNotMeterNoDivide(self): token = "lol" self.assertFalse(SearchProcessor.is_meter(token))
def testKey(self): input = "C major" self.assertEqual( {"key": ["C major"]}, SearchProcessor.process(input))
def testIsKeySharp(self): token = ["Csharp", "minor"] self.assertTrue(SearchProcessor.is_key(token))
def testIsNotKey(self): token = ["Hello"] self.assertFalse(SearchProcessor.is_key(token))
def testIsNotTempo(self): token = "1=2" self.assertFalse(SearchProcessor.is_tempo(token))