예제 #1
0
class TestSymmetry(unittest.TestCase):

    def setUp(self):
        self.lgr = LGR()
        # Configure log system to redirect validation logs to local attribute
        self.log_output = StringIO()
        ch = logging.StreamHandler(self.log_output)
        ch.setLevel(logging.DEBUG)
        logging.getLogger('lgr.validate').addHandler(ch)

    def test_empty_lgr(self):
        success, result = check_symmetry(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertEqual(len(log_content), 0)
        self.assertTrue(success)
        self.assertDictEqual(result, {'description': 'Testing symmetry',
                                      'repertoire': []})

    def test_no_symmetric_in_repertoire(self):
        self.lgr.add_cp([0x0061])
        self.lgr.add_variant([0x0061], [0x0062])
        success, result = check_symmetry(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertGreater(len(log_content), 0)
        self.assertEqual(log_content,
                         "CP U+0061: Variant U+0062 is not in repertoire.\n")
        self.assertFalse(success)
        self.assertDictEqual(result, {'description': 'Testing symmetry',
                                      'repertoire': [{'char': self.lgr.get_char([0x0061]),
                                                      'variant': self.lgr.get_variant([0x0061], (0x0062, ))[0],
                                                      'type': 'not-in-repertoire'}]})

    def test_no_symmetric_in_variants(self):
        self.lgr.add_cp([0x0061])
        self.lgr.add_variant([0x0061], [0x0062])
        self.lgr.add_cp([0x0062])
        success, result = check_symmetry(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertGreater(len(log_content), 0)
        self.assertEqual(log_content,
                         'CP U+0062 should have CP U+0061 in its variants.\n')
        self.assertFalse(success)
        self.assertDictEqual(result, {'description': 'Testing symmetry',
                                      'repertoire': [{'char': self.lgr.get_variant([0x0061], (0x0062, ))[0],
                                                      'variant': self.lgr.get_char([0x0061]),
                                                      'type': 'missing'}]})

    def test_symmetry_ok(self):
        self.lgr.add_cp([0x0061])
        self.lgr.add_variant([0x0061], [0x0062])
        self.lgr.add_cp([0x0062])
        self.lgr.add_variant([0x0062], [0x0061])
        success, result = check_symmetry(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertEqual(len(log_content), 0)
        self.assertTrue(success)
        self.assertDictEqual(result, {'description': 'Testing symmetry',
                                      'repertoire': []})
예제 #2
0
class TestTransitivity(unittest.TestCase):

    def setUp(self):
        self.lgr = LGR()
        # Configure log system to redirect validation logs to local attribute
        self.log_output = StringIO()
        ch = logging.StreamHandler(self.log_output)
        ch.setLevel(logging.DEBUG)
        logging.getLogger('lgr.validate').addHandler(ch)

    def test_empty_lgr(self):
        success, result = check_transitivity(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertEqual(len(log_content), 0)
        self.assertTrue(success)
        self.assertDictEqual(result, {'description': 'Testing transitivity',
                                      'repertoire': []})

    def test_no_variants(self):
        self.lgr.add_cp([0x0061])
        self.lgr.add_cp([0x0062])
        success, result = check_transitivity(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertEqual(len(log_content), 0)
        self.assertTrue(success)
        self.assertDictEqual(result, {'description': 'Testing transitivity',
                                      'repertoire': []})

    def test_no_transitivity(self):
        self.lgr.add_cp([0x0061])
        self.lgr.add_variant([0x0061], [0x0062])
        self.lgr.add_cp([0x0062])
        self.lgr.add_variant([0x0062], [0x0063])
        self.lgr.add_cp([0x0063])
        success, result = check_transitivity(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertGreater(len(log_content), 0)
        self.assertEqual(log_content,
                         'CP U+0061 should have CP U+0063 in its variants.\n')
        self.assertFalse(success)
        self.assertDictEqual(result, {'description': 'Testing transitivity',
                                      'repertoire': [{'char': self.lgr.get_char([0x0061]),
                                                      'variant': self.lgr.get_variant([0x0062], (0x0063, ))[0]}]})

    def test_transitivity_ok(self):
        self.lgr.add_cp([0x0061])
        self.lgr.add_variant([0x0061], [0x0062])
        self.lgr.add_variant([0x0061], [0x0063])
        self.lgr.add_cp([0x0062])
        self.lgr.add_variant([0x0062], [0x0063])
        self.lgr.add_cp([0x0063])
        success, result = check_transitivity(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertEqual(len(log_content), 0)
        self.assertTrue(success)
        self.assertDictEqual(result, {'description': 'Testing transitivity',
                                      'repertoire': []})
예제 #3
0
class TestConditionalVariants(unittest.TestCase):

    def setUp(self):
        self.lgr = LGR()
        # Configure log system to redirect validation logs to local attribute
        self.log_output = StringIO()
        ch = logging.StreamHandler(self.log_output)
        ch.setLevel(logging.DEBUG)
        logging.getLogger('lgr.validate').addHandler(ch)

    def test_empty_lgr(self):
        success, result = check_conditional_variants(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertEqual(len(log_content), 0)
        self.assertTrue(success)
        self.assertDictEqual(result, {'description': 'Testing conditional variants',
                                      'repertoire': []})

    def test_no_variants(self):
        self.lgr.add_cp([0x0061])
        self.lgr.add_cp([0x0062])
        success, result = check_conditional_variants(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertEqual(len(log_content), 0)
        self.assertTrue(success)
        self.assertDictEqual(result, {'description': 'Testing conditional variants',
                                      'repertoire': []})

    def test_no_rule_when(self):
        self.lgr.add_cp([0x0061])
        self.lgr.add_variant([0x0061], [0x0062], when="when-rule")
        success, result = check_conditional_variants(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertGreater(len(log_content), 0)
        self.assertEqual(log_content,
                         "CP U+0061: Variant 'U+0062' \"when\" attribute "
                         "'when-rule' is not an existing rule name.\n")
        self.assertFalse(success)
        var = self.lgr.get_variant([0x0061], (0x0062, ))[0]
        self.assertDictEqual(result, {'description': 'Testing conditional variants',
                                      'repertoire': [{'char': self.lgr.get_char([0x0061]),
                                                      'variant': var,
                                                      'rule_type': 'when',
                                                      'rule': var.when}]})

    def test_no_rule_not_when(self):
        self.lgr.add_cp([0x0061])
        self.lgr.add_variant([0x0061], [0x0062], not_when="not-when-rule")
        success, result = check_conditional_variants(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertGreater(len(log_content), 0)
        self.assertEqual(log_content,
                         "CP U+0061: Variant 'U+0062' \"not-when\" attribute "
                         "'not-when-rule' is not an existing rule name.\n")
        self.assertFalse(success)
        var = self.lgr.get_variant([0x0061], (0x0062, ))[0]
        self.assertDictEqual(result, {'description': 'Testing conditional variants',
                                      'repertoire': [{'char': self.lgr.get_char([0x0061]),
                                                      'variant': var,
                                                      'rule_type': 'not-when',
                                                      'rule': var.not_when}]})

    def test_no_rule_when_not_when(self):
        self.lgr.add_cp([0x0061])
        self.lgr.add_variant([0x0061], [0x0062], when="when-rule", not_when="not-when-rule", force=True)
        success, result = check_conditional_variants(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertGreater(len(log_content), 0)
        self.assertEqual(log_content,
                         "CP U+0061: Variant 'U+0062' \"when\" attribute "
                         "'when-rule' is not an existing rule name.\n"
                         "CP U+0061: Variant 'U+0062' \"not-when\" attribute "
                         "'not-when-rule' is not an existing rule name.\n")
        self.assertFalse(success)
        var = self.lgr.get_variant([0x0061], (0x0062, ))[0]
        self.assertDictEqual(result, {'description': 'Testing conditional variants',
                                      'repertoire': [{'char': self.lgr.get_char([0x0061]),
                                                      'variant': var,
                                                      'rule_type': 'when',
                                                      'rule': var.when},
                                                     {'char': self.lgr.get_char([0x0061]),
                                                      'variant': var,
                                                      'rule_type': 'not-when',
                                                      'rule': var.not_when}
                                                     ]})

    def test_conditional_when_ok(self):
        self.lgr.add_cp([0x0061])
        self.lgr.add_variant([0x0061], [0x0062], when="when-rule")
        self.lgr.rules.append("when-rule")
        success, result = check_conditional_variants(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertEqual(len(log_content), 0)
        self.assertTrue(success)
        self.assertDictEqual(result, {'description': 'Testing conditional variants',
                                      'repertoire': []})

    def test_conditional_not_when_ok(self):
        self.lgr.add_cp([0x0061])
        self.lgr.add_variant([0x0061], [0x0062], not_when="not-when-rule")
        self.lgr.rules.append("not-when-rule")
        success, result = check_conditional_variants(self.lgr, {})
        log_content = self.log_output.getvalue()
        self.assertEqual(len(log_content), 0)
        self.assertTrue(success)
        self.assertDictEqual(result, {'description': 'Testing conditional variants',
                                      'repertoire': []})