Beispiel #1
0
def test_xeger_object_seeding(seed):
    xg1 = xeger.Xeger(seed=seed)
    string1 = xg1.xeger(r'\w{3,4}')

    xg2 = xeger.Xeger(seed=seed)
    string2 = xg2.xeger(r'\w{3,4}')

    assert string1 == string2
Beispiel #2
0
def jsonlines_data_generator(conf_tuple: tuple, max_length=50):
    output_file_name = conf_tuple[0]
    output_lines_numbers = conf_tuple[1]
    output_jsonlines = [output_file_name]

    props = conf_tuple[2:]

    generator = xeger.Xeger(max_length)

    # generate all needed mockup data
    output_temp_data = []
    # use the hash table to store and example whether repeat or not
    for prop in props:
        output_temp_one_col_data = ""
        if prop[2]:
            output_temp_one_col_data = {}
            for i in range(output_lines_numbers):
                new_random = generator.xeger(prop[1])
                while new_random in output_temp_one_col_data:
                    new_random = generator.xeger(prop[1])
                output_temp_one_col_data[new_random] = True
            output_temp_data.append(list(output_temp_one_col_data.keys()))
        else:
            output_temp_one_col_data = []
            for i in range(output_lines_numbers):
                output_temp_one_col_data.append(generator.xeger(prop[1]))
            output_temp_data.append(output_temp_one_col_data)

    for row in range(output_lines_numbers):
        one_line = {}
        for index, prop in enumerate(props):
            one_line[prop[0]] = output_temp_data[index][row]
        output_jsonlines.append(one_line)
    return tuple(output_jsonlines)
Beispiel #3
0
 def random_regular(*args, **kwargs):
     pattern = args
     limit_len = int(kwargs.get("limit", default="10"))
     if (limit_len <= 1): limit_len = 10
     if (list_like(args)):
         pattern = random.choice(args)
     _x = xeger.Xeger(limit=limit_len)
     return _x.xeger(pattern)
Beispiel #4
0
def test_xeger_random_instance():
    xg1 = xeger.Xeger()
    xg_random = xg1.random

    xg2 = xeger.Xeger()
    xg2.random = xg_random

    assert xg1.random == xg2.random
    # xg_random is used by both, so if we give 
    # the same seed, the result should be the same

    xg_random.seed(90)
    string1 = xg1.xeger(r'\w\d\w')
    xg_random.seed(90)
    string2 = xg2.xeger(r'\w\d\w')

    assert string1 == string2
Beispiel #5
0
    def __arr_name_generator(self, valid=True):
        x = xeger.Xeger(15)

        if valid:
            ptr_name = x.xeger(r'[a-zA-Z]([a-zA-Z\d]*)')
        else:
            ptr_name = x.xeger(r'[0-9]([a-zA-Z\d]*)')

        return ptr_name
Beispiel #6
0
    def __arr_cnt_generator(self, make_square_par_empty=False):
        if make_square_par_empty:
            result = ''
        else:
            x = xeger.Xeger(self.__max_cnt_length)
            result = x.xeger(r'\d*')

            try:
                result = '' if result[0] == '0' else result
            except IndexError as err:
                pass

        return result
 def get_serial_number(model='IR900'):
     rules = {
         "IR900": '^R[A-Z]9[0-9]{12}',
         "IR700": '^R[A-Z]7[0-9]{12}',
         "IR600": '^R[A-Z]6[0-9]{12}',
         "InDTU": '^D[A-Z]3[0-9]{12}',
         "EG910L": '^(GF|EG)910[0-9]{10}',
         "VG710": '^V[A-Z]7[0-9]{12}',
         "IG902": '^G[A-Z]902[0-9]{10}'
     }
     xeger_client = xeger.Xeger()
     if model.upper() not in rules:
         print('请输入正确的机型!仅支持以下机型{}'.format(rules.keys()))
         sys.exit()
     else:
         serial_number = xeger_client.xeger(rules[model.upper()])
         return serial_number
 def create_ip_address():
     xeger_client = xeger.Xeger()
     ip_address = xeger_client.xeger(
         '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$')
     return ip_address
Beispiel #9
0
 def setUp(self):
     self.xeger = xeger.Xeger()
Beispiel #10
0
        if example not in sequences:
            sequences.append(example)
            i += 1
    return sequences


def generate_invalid_examples(size):
    sequences = []
    i = 0
    while i < size:
        xeger._limit = UPPER_LIMIT
        example = generate_invalid_sequence()
        if example not in sequences:
            sequences.append(example)
            i += 1
    return sequences



if __name__ == '__main__':
    xeger = xeger.Xeger(UPPER_LIMIT)

    ensure_directory_exists('data_tries/')

    train, test = generate_train_test_sequneces()

    with open('data_tries/train.txt', 'w') as f:
        f.writelines([x + '\n' for x in train])

    with open('data_tries/test.txt', 'w') as f:
        f.writelines([x + '\n' for x in test])
Beispiel #11
0
def test_incoherent_limit_and_qualifier(limit):
    r = xeger.Xeger(limit=limit)
    o = r.xeger(r'a{2}')
    assert len(o) == 2