omaciel / fauxfactory

Generates random data for your tests.
Other
37 stars 26 forks source link

Add option to generate BMP unicode only #95

Closed abalakh closed 6 years ago

abalakh commented 6 years ago

Chromedriver only supports BMP chars and can't type SMP. Can we have option, or at least arg for gen_***() funcs to generate BMP only? 🙂

omaciel commented 6 years ago

Work would have to be done to the unicode_letters_generator method and the ranges for BMP and SMP can be found here: https://en.wikipedia.org/wiki/Plane_(Unicode)

omaciel commented 6 years ago

@abalakh here's what I'm thinking:

import unicodedata

from collections import namedtuple

UnicodePlane = namedtuple('UnicodePlane', ['min', 'max'])

BMP = UnicodePlane(int('0x0000', 16), int('0xffff', 16))
SMP = UnicodePlane(int('0x10000', 16), int('0x1ffff', 16))

def unicode_letters_generator(smp=True):
        """Generate unicode characters in the letters category.

        :param bool smp: Include Supplementary Multilingual Plane (SMP)
            characters
        :return: a generator which will generates all unicode letters available

        """
        for i in range(BMP.min, SMP.max if smp else BMP.max):
            char = chr(i)
            if unicodedata.category(char).startswith('L'):
                yield char

Thoughts?

omaciel commented 6 years ago

Resolved by #96