Example #1
0
 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': []})
Example #2
0
 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': []})
Example #3
0
 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'}]})
Example #4
0
 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'}]})
Example #5
0
def populate_lgr(lgr):
    """
    Populate an LGR with missing variants, and fix symmetry and transitivity

    :param lgr: The LGR to be populated.
    :return: Result of checks and summary as a string
    """
    # not in LGR variants
    for a in lgr.repertoire:
        for b in a.get_variants():
            try:
                lgr.get_variants(b.cp)
            except NotInLGR:
                logger.info("Add missing code point '{}' in LGR as it is a variant of '{}'".format(
                    format_cp(b.cp), format_cp(a.cp)))
                lgr.add_cp(b.cp)
                # add current code point as variant for missing code point
                logger.info("Add code point '{}' as variant of '{}' for symmetry".format(format_cp(a.cp),
                                                                                         format_cp(b.cp)))
                lgr.add_variant(b.cp, a.cp, variant_type='blocked')

    while not check_symmetry(lgr, None)[0] or not check_transitivity(lgr, None)[0]:
        # symmetry
        for a in lgr.repertoire:
            for b in a.get_variants():
                # Variant is defined in repertoire
                # let's see if the original character is in its
                # variants
                if a.cp not in [var.cp for var in lgr.get_variants(b.cp)]:
                    logger.info("Add code point '{}' as variant of '{}' for symmetry".format(format_cp(a.cp),
                                                                                             format_cp(b.cp)))
                    lgr.add_variant(b.cp, a.cp, variant_type='blocked')

        # transitivity
        for a in lgr.repertoire:
            for b in a.get_variants():
                for c in [var for var in lgr.get_variants(b.cp) if var.cp != a.cp]:
                    # Iterate through all second-level variants
                    # which are not the original code point
                    if c.cp not in [var.cp for var in a.get_variants()]:
                        logger.info("Add code point '{}' as variant of '{}' for transitivity with '{}'".format(
                            format_cp(c.cp), format_cp(a.cp), format_cp(b.cp)))
                        lgr.add_variant(a.cp, c.cp, variant_type='blocked')