Ejemplo n.º 1
0
class NullComponentTest(unittest.TestCase):
    def setUp(self):
        info = MorphologyInfo()
        info.variant = VARIANT_NAME
        info.morphology = u"null"
        info.speller = u"AllOk"
        info.suggestion = u"null"
        self.dataDir = TestDataDir()
        self.dataDir.createMorphology(VARIANT_NAME, info)
        self.voikko = libvoikko.Voikko("fi-x-" + VARIANT_NAME,
                                       path=self.dataDir.getDirectory())

    def tearDown(self):
        self.voikko.terminate()
        self.dataDir.tearDown()

    def testNullAnalyzerWorks(self):
        analysisList = self.voikko.analyze(u"koira")
        self.assertEqual(0, len(analysisList))

    def testNullSuggestionGeneratorWorks(self):
        suggestionList = self.voikko.suggest(u"koirra")
        self.assertEqual(0, len(suggestionList))

    def testAllOkSpellerWorks(self):
        self.failUnless(self.voikko.spell(u"koirra"))
Ejemplo n.º 2
0
class NullComponentTest(unittest.TestCase):
	def setUp(self):
		info = MorphologyInfo()
		info.variant = VARIANT_NAME
		info.morphology = u"null"
		info.speller = u"AllOk"
		info.suggestion = u"null"
		self.dataDir = TestDataDir()
		self.dataDir.createMorphology(VARIANT_NAME, info)
		self.voikko = libvoikko.Voikko("fi-x-" + VARIANT_NAME, path = self.dataDir.getDirectory())
	
	def tearDown(self):
		self.voikko.terminate()
		self.dataDir.tearDown()
	
	def testNullAnalyzerWorks(self):
		analysisList = self.voikko.analyze(u"koira")
		self.assertEqual(0, len(analysisList))
	
	def testNullSuggestionGeneratorWorks(self):
		suggestionList = self.voikko.suggest(u"koirra")
		self.assertEqual(0, len(suggestionList))

	def testAllOkSpellerWorks(self):
		self.failUnless(self.voikko.spell(u"koirra"))
Ejemplo n.º 3
0
 def testListDictsWithPathAndAttributes(self):
     info = MorphologyInfo()
     info.variant = u"test-variant-name"
     info.description = u"Some test description sakldjasd"
     info.morphology = u"null"
     dataDir = TestDataDir()
     dataDir.createMorphology(info.variant, info)
     dicts = Voikko.listDicts(dataDir.getDirectory())
     dataDir.tearDown()
     dictsWithCorrectVariant = filter(lambda aDict: aDict.variant == info.variant, dicts)
     self.assertEqual(1, len(dictsWithCorrectVariant))
     theDict = dictsWithCorrectVariant[0]
     self.assertEqual(info.description, theDict.description)
     self.assertEqual(u"fi", theDict.language)
Ejemplo n.º 4
0
	def testListDictsWithPathAndAttributes(self):
		info = MorphologyInfo()
		info.variant = u"test-variant-name"
		info.description = u"Some test description sakldjasd"
		info.morphology = u"null"
		dataDir = TestDataDir()
		dataDir.createMorphology(info.variant, info)
		dicts = Voikko.listDicts(dataDir.getDirectory())
		dataDir.tearDown()
		dictsWithCorrectVariant = filter(lambda aDict: aDict.variant == info.variant, dicts)
		self.assertEqual(1, len(dictsWithCorrectVariant))
		theDict = dictsWithCorrectVariant[0]
		self.assertEqual(info.description, theDict.description)
		self.assertEqual(u"fi", theDict.language)
Ejemplo n.º 5
0
class DictionaryInfoTest(unittest.TestCase):
    def setUp(self):
        info = MorphologyInfo()
        info.variant = VARIANT_NAME
        info.morphology = u"null"
        self.dataDir = TestDataDir()
        self.dataDir.createMorphology(VARIANT_NAME, info)

    def tearDown(self):
        self.dataDir.tearDown()

    def testListSupportedSpellingLanguagesReturnsFinnish(self):
        languages = libvoikko.Voikko.listSupportedSpellingLanguages(
            self.dataDir.getDirectory())
        self.assertTrue(u"fi" in languages)

    def __tryOpenWithOldApi(self, variant):
        lib = getVoikkoCLibrary()
        handle = c_int(-1)
        error = lib.voikko_init_with_path(byref(handle), variant, 0,
                                          self.dataDir.getDirectory())
        isOk = not bool(error)
        lib.voikko_terminate(handle)
        return isOk

    def __tryOpenWithNewApi(self, variant):
        lib = getVoikkoCLibrary()
        error = c_char_p()
        handle = lib.voikkoInit(byref(error), variant,
                                self.dataDir.getDirectory())
        if error.value == None:
            lib.voikkoTerminate(handle)
            return True
        else:
            return False

    def testVariantCanBeOpenedWithOldApiUsingFullNameAsIs(self):
        self.assertTrue(self.__tryOpenWithOldApi(VARIANT_NAME))

    def testDefaultVariantCanBeOpenedWithOldApiUsingValuesSpecifiedInApi(self):
        self.assertTrue(self.__tryOpenWithOldApi(u""))
        self.assertTrue(self.__tryOpenWithOldApi(u"default"))
        self.assertTrue(self.__tryOpenWithOldApi(u"fi_FI"))

    def testVariantCannotBeOpenedWithOldApiUsingOtherValues(self):
        self.assertFalse(self.__tryOpenWithOldApi(u"ksajdlaksjdkasl"))

    def testVariantCanBeOpenedWithNewApiUsingBCP47LanguageTag(self):
        self.assertTrue(self.__tryOpenWithNewApi(u"fi-x-dictiona-ryinfote-st"))
        self.assertTrue(self.__tryOpenWithNewApi(u"fi-x-Dictiona-ryinfote-st"))
        self.assertTrue(self.__tryOpenWithNewApi(u"Fi-x-dictiona-ryinfote-st"))
        self.assertTrue(
            self.__tryOpenWithNewApi(u"fi-x-dictio-nary-info-test"))
        self.assertTrue(
            self.__tryOpenWithNewApi(u"fi-FI-x-dictiona-ryinfote-st"))
        self.assertTrue(self.__tryOpenWithNewApi(u"fi"))
        self.assertTrue(self.__tryOpenWithNewApi(u"fi-FI"))

    def testVariantCannotBeOpenedWithNewApiUsingOtherValues(self):
        self.assertFalse(self.__tryOpenWithNewApi(VARIANT_NAME))
        self.assertFalse(self.__tryOpenWithNewApi(u"ksajdlaksjdkasl"))
        self.assertFalse(self.__tryOpenWithNewApi(u"sv"))
        self.assertFalse(self.__tryOpenWithNewApi(u"fi-x-askldjaslkdj"))
        self.assertFalse(self.__tryOpenWithNewApi(u""))
        self.assertFalse(self.__tryOpenWithNewApi(None))

    def testOtherLanguagesCanBeUsed(self):
        info2 = MorphologyInfo()
        info2.language = u"dk"
        info2.morphology = u"null"
        info2.description = "Testdescription lkrj"
        self.dataDir.createMorphology(u"test1", info2)

        self.assertTrue(self.__tryOpenWithNewApi(u"dk"))

        languages = libvoikko.Voikko.listSupportedSpellingLanguages(
            self.dataDir.getDirectory())
        self.assertTrue(u"fi" in languages)
        self.assertTrue(u"dk" in languages)

        dicts = libvoikko.Voikko.listDicts(self.dataDir.getDirectory())
        for dictionary in dicts:
            if dictionary.language == u"dk":
                self.assertEquals(info2.description, dictionary.description)
                self.assertEquals(u"standard", dictionary.variant)
                return
        self.fail(u"Should have found dk dictionary")
Ejemplo n.º 6
0
class DictionaryInfoTest(unittest.TestCase):
	def setUp(self):
		info = MorphologyInfo()
		info.variant = VARIANT_NAME
		info.morphology = u"null"
		self.dataDir = TestDataDir()
		self.dataDir.createMorphology(VARIANT_NAME, info)
	
	def tearDown(self):
		self.dataDir.tearDown()
	
	def testListSupportedSpellingLanguagesReturnsFinnish(self):
		languages = libvoikko.Voikko.listSupportedSpellingLanguages(self.dataDir.getDirectory())
		self.assertTrue(u"fi" in languages)
	
	def __tryOpenWithOldApi(self, variant):
		lib = getVoikkoCLibrary()
		handle = c_int(-1)
		error = lib.voikko_init_with_path(byref(handle), variant,
		        0, self.dataDir.getDirectory())
		isOk = not bool(error)
		lib.voikko_terminate(handle)
		return isOk
	
	def __tryOpenWithNewApi(self, variant):
		lib = getVoikkoCLibrary()
		error = c_char_p()
		handle = lib.voikkoInit(byref(error), variant,
		         self.dataDir.getDirectory())
		if error.value == None:
			lib.voikkoTerminate(handle)
			return True
		else:
			return False
	
	def testVariantCanBeOpenedWithOldApiUsingFullNameAsIs(self):
		self.assertTrue(self.__tryOpenWithOldApi(VARIANT_NAME))
	
	def testDefaultVariantCanBeOpenedWithOldApiUsingValuesSpecifiedInApi(self):
		self.assertTrue(self.__tryOpenWithOldApi(u""))
		self.assertTrue(self.__tryOpenWithOldApi(u"default"))
		self.assertTrue(self.__tryOpenWithOldApi(u"fi_FI"))
	
	def testVariantCannotBeOpenedWithOldApiUsingOtherValues(self):
		self.assertFalse(self.__tryOpenWithOldApi(u"ksajdlaksjdkasl"))
	
	def testVariantCanBeOpenedWithNewApiUsingBCP47LanguageTag(self):
		self.assertTrue(self.__tryOpenWithNewApi(u"fi-x-dictiona-ryinfote-st"))
		self.assertTrue(self.__tryOpenWithNewApi(u"fi-x-Dictiona-ryinfote-st"))
		self.assertTrue(self.__tryOpenWithNewApi(u"Fi-x-dictiona-ryinfote-st"))
		self.assertTrue(self.__tryOpenWithNewApi(u"fi-x-dictio-nary-info-test"))
		self.assertTrue(self.__tryOpenWithNewApi(u"fi-FI-x-dictiona-ryinfote-st"))
		self.assertTrue(self.__tryOpenWithNewApi(u"fi"))
		self.assertTrue(self.__tryOpenWithNewApi(u"fi-FI"))
	
	def testVariantCannotBeOpenedWithNewApiUsingOtherValues(self):
		self.assertFalse(self.__tryOpenWithNewApi(VARIANT_NAME))
		self.assertFalse(self.__tryOpenWithNewApi(u"ksajdlaksjdkasl"))
		self.assertFalse(self.__tryOpenWithNewApi(u"sv"))
		self.assertFalse(self.__tryOpenWithNewApi(u"fi-x-askldjaslkdj"))
		self.assertFalse(self.__tryOpenWithNewApi(u""))
		self.assertFalse(self.__tryOpenWithNewApi(None))
	
	def testOtherLanguagesCanBeUsed(self):
		info2 = MorphologyInfo()
		info2.language = u"dk"
		info2.morphology = u"null"
		info2.description = "Testdescription lkrj"
		self.dataDir.createMorphology(u"test1", info2)
		
		self.assertTrue(self.__tryOpenWithNewApi(u"dk"))
		
		languages = libvoikko.Voikko.listSupportedSpellingLanguages(self.dataDir.getDirectory())
		self.assertTrue(u"fi" in languages)
		self.assertTrue(u"dk" in languages)
		
		dicts = libvoikko.Voikko.listDicts(self.dataDir.getDirectory())
		for dictionary in dicts:
			if dictionary.language == u"dk":
				self.assertEquals(info2.description, dictionary.description)
				self.assertEquals(u"standard", dictionary.variant)
				return
		self.fail(u"Should have found dk dictionary")