import os.path import lxml.etree as lxml import unittest from conversion_utils.jos_msds_and_properties import SpecificationsBuilder, Converter, Properties class JosPropertiesToMsdTestCase(unittest.TestCase): def setUp(self): specifications_file_name = os.path.join(os.path.dirname(__file__), '../resources/msd-sl.spc.xml') builder = SpecificationsBuilder() specifications = builder.build(specifications_file_name) self.converter = Converter(specifications) def test_en_en(self): msd = self.converter.properties_to_msd(Properties('noun', {'type':'common', 'gender':'feminine'}, {'number':'dual', 'case':'nominative'}, 'en'), 'en') self.assertEqual(msd.language, 'en') self.assertEqual(msd.code, 'Ncfdn') def test_en_sl(self): msd = self.converter.properties_to_msd(Properties('noun', {'type':'common', 'gender':'feminine'}, {'number':'dual', 'case':'nominative'}, 'en'), 'sl') self.assertEqual(msd.language, 'sl') self.assertEqual(msd.code, 'Sozdi') def test_sl_en(self): msd = self.converter.properties_to_msd(Properties('samostalnik', {'vrsta':'občno_ime', 'spol':'ženski'}, {'število':'dvojina', 'sklon':'imenovalnik'}, 'sl'), 'en') self.assertEqual(msd.language, 'en') self.assertEqual(msd.code, 'Ncfdn') def test_sl_sl(self): msd = self.converter.properties_to_msd(Properties('samostalnik', {'vrsta':'občno_ime', 'spol':'ženski'}, {'število':'dvojina', 'sklon':'imenovalnik'}, 'sl'), 'sl') self.assertEqual(msd.language, 'sl') self.assertEqual(msd.code, 'Sozdi') def test_exception_feature_level(self): msd = self.converter.properties_to_msd(Properties('zaimek', {'vrsta':'osebni', 'oseba':'druga'}, {'število':'ednina', 'sklon':'dajalnik', 'naslonskost':'klitična'}, 'sl'), 'en') self.assertEqual(msd.language, 'en') self.assertEqual(msd.code, 'Pp2-sd--y') def test_normal_feature_level(self): msd = self.converter.properties_to_msd(Properties('zaimek', {'vrsta':'osebni', 'oseba':'druga', 'naslonskost':'klitična'}, {'število':'množina', 'sklon':'dajalnik'}, 'sl'), 'en') self.assertEqual(msd.language, 'en') self.assertEqual(msd.code, 'Pp2-pd--y') def test_featureless(self): msd = self.converter.properties_to_msd(Properties('conjunction', {}, {}, 'en'), 'sl') self.assertEqual(msd.language, 'sl') self.assertEqual(msd.code, 'V')