<commit_before>import unittest
from fontParts.base import FontPartsError
from fontTools.misc.py23 import basestring


class TestAnchor(unittest.TestCase):

    def getAnchor_generic(self):
        anchor, unrequested = self.objectGenerator("anchor")
        anchor.name = "Anchor Attribute Test"
        anchor.x = 1
        anchor.y = 2
        anchor.color = None
        return anchor, unrequested

    # ----------
    # Attributes
    # ----------

    def test_name(self):
        anchor, unrequested = self.getAnchor_generic()
        # get
        self.assertEqual(anchor.name, "Anchor Attribute Test")
        # set: valid
        anchor.name = u"foo"
        self.assertEqual(anchor.name, u"foo")
        # set: None
        anchor.name = None
        self.assertIsNone(anchor.name)
        # set: invalid
        with self.assertRaises(FontPartsError):
            anchor.name = 123

    def test_color(self):
        anchor, unrequested = self.getAnchor_generic()
        # get
        self.assertIsNone(anchor.color)
        # set: valid
        anchor.color = (1, 1, 1, 1)
        self.assertEqual(anchor.color, (1, 1, 1, 1))
        anchor.color = (0, 0, 0, 0)
        self.assertEqual(anchor.color, (0, 0, 0, 0))
        anchor.color = (0.1, 0.2, 0.3, 0.4)
        self.assertEqual(anchor.color, (0.1, 0.2, 0.3, 0.4))
        # set: None
        anchor.color = None
        self.assertIsNone(anchor.color)
        # set: invalid
        with self.assertRaises(FontPartsError):
            anchor.color = (1.1, 0.2, 0.3, 0.4)
        with self.assertRaises(FontPartsError):
            anchor.color = (-0.1, 0.2, 0.3, 0.4)
        with self.assertRaises(FontPartsError):
            anchor.color = (0.1, 0.2, 0.3)
        with self.assertRaises(FontPartsError):
            anchor.color = "0.1,0.2,0.3,0.4"
        with self.assertRaises(FontPartsError):
            anchor.color = 123

    def test_identifier(self):
        anchor, unrequested = self.getAnchor_generic()
        # get
        self.assertIsInstance(anchor.identifier, basestring)
        # get: twice to test consistency
        self.assertEqual(anchor.identifier, anchor.identifier)
        # set
        with self.assertRaises(FontPartsError):
            anchor.identifier = "ABC"

    def getAnchor_index(self):
        glyph, unrequested = self.objectGenerator("glyph")
        glyph.appendAnchor("anchor 0", (0, 0))
        glyph.appendAnchor("anchor 1", (0, 0))
        glyph.appendAnchor("anchor 2", (0, 0))
        return glyph, unrequested

    def test_index(self):
        glyph, unrequested = self.getAnchor_index()<commit_msg>fix anchor identifier test<commit_after>import unittest
from fontParts.base import FontPartsError
from fontTools.misc.py23 import basestring


class TestAnchor(unittest.TestCase):

    def getAnchor_generic(self):
        anchor, unrequested = self.objectGenerator("anchor")
        anchor.name = "Anchor Attribute Test"
        anchor.x = 1
        anchor.y = 2
        anchor.color = None
        return anchor, unrequested

    # ----------
    # Attributes
    # ----------

    def test_name(self):
        anchor, unrequested = self.getAnchor_generic()
        # get
        self.assertEqual(anchor.name, "Anchor Attribute Test")
        # set: valid
        anchor.name = u"foo"
        self.assertEqual(anchor.name, u"foo")
        # set: None
        anchor.name = None
        self.assertIsNone(anchor.name)
        # set: invalid
        with self.assertRaises(FontPartsError):
            anchor.name = 123

    def test_color(self):
        anchor, unrequested = self.getAnchor_generic()
        # get
        self.assertIsNone(anchor.color)
        # set: valid
        anchor.color = (1, 1, 1, 1)
        self.assertEqual(anchor.color, (1, 1, 1, 1))
        anchor.color = (0, 0, 0, 0)
        self.assertEqual(anchor.color, (0, 0, 0, 0))
        anchor.color = (0.1, 0.2, 0.3, 0.4)
        self.assertEqual(anchor.color, (0.1, 0.2, 0.3, 0.4))
        # set: None
        anchor.color = None
        self.assertIsNone(anchor.color)
        # set: invalid
        with self.assertRaises(FontPartsError):
            anchor.color = (1.1, 0.2, 0.3, 0.4)
        with self.assertRaises(FontPartsError):
            anchor.color = (-0.1, 0.2, 0.3, 0.4)
        with self.assertRaises(FontPartsError):
            anchor.color = (0.1, 0.2, 0.3)
        with self.assertRaises(FontPartsError):
            anchor.color = "0.1,0.2,0.3,0.4"
        with self.assertRaises(FontPartsError):
            anchor.color = 123

    def test_identifier(self):
        anchor, unrequested = self.getAnchor_generic()
        # get
        self.assertIsNone(anchor.identifier)
        # get
        anchor.generateIdentifier()
        self.assertIsInstance(anchor.identifier, basestring)
        # get: twice to test consistency
        self.assertEqual(anchor.identifier, anchor.identifier)
        # set
        with self.assertRaises(FontPartsError):
            anchor.identifier = "ABC"

    def getAnchor_index(self):
        glyph, unrequested = self.objectGenerator("glyph")
        glyph.appendAnchor("anchor 0", (0, 0))
        glyph.appendAnchor("anchor 1", (0, 0))
        glyph.appendAnchor("anchor 2", (0, 0))
        return glyph, unrequested

    def test_index(self):
        glyph, unrequested = self.getAnchor_index()
{'fraction_non_alphanumeric': 0.12289876727680239, 'fraction_numerical': 0.030257751214045572, 'mean_word_length': 2.129748684979544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3724684', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1620, 'n_words': 359}