Пример #1
0
def test_string_func():
    "generate a fair number, expect all choices in short, all unique in long"
    short = fixed_length_string(1)
    longer = fixed_length_string(100)

    short_results = {}
    longer_results = {}

    num = 2000
    for i in range(num):
        s = short("input")
        l = longer("input")
        short_results[s] = True
        longer_results[l] = True
    assert(len(short_results) == len(string.ascii_lowercase))
    assert(len(longer_results) == num)
Пример #2
0
def test_cached_term():
    "two calls return same altered result"
    random_f = fixed_length_string(25)
    input = "Bob. G Longbottom"
    first = anon_term(input, random_f)
    second = anon_term(input, random_f)
    assert(first != input)
    assert(first == second)
Пример #3
0
def test_too_long_prefix():
    "expect ValueError when prefix len exceeds lenght"
    fixed_length_string(length=10, prefix='longer than 10')
Пример #4
0
def test_prefix():
    result = fixed_length_string(length=3, prefix='tom')('initial value')
    assert (len(result) == 3)
    assert (result == 'Tom')
Пример #5
0
        if segment:
            return dict.__contains__(self, segment)

        segment, element, component = self.assert_triplekey(key)
        if dict.__contains__(self, segment):
            d = dict.__getitem__(self, segment)
            return element in d and component in d[element]
        return False


config = Config()
days = config.get("anonymize", "dayshift")

"""Define functions with parameters needed to anonymize fields"""
dotted_sequence = fixed_length_digits(30, (1, 7))
short_string = fixed_length_string(10)
site_string = fixed_length_string(12, prefix="Site ")
yyyymm = random_date_delta(datetime.timedelta(days=days), "%Y%m")
ymdhms = random_date_delta(datetime.timedelta(days=days), "%Y%m%d%H%M%S")
two_digits = fixed_length_digits(2)
five_digits = fixed_length_digits(5)
six_digits = fixed_length_digits(6)
nine_digits = fixed_length_digits(9)
ten_digits = fixed_length_digits(10)

def ten_digits_starting_w_1(initial):
    """specialized anon function for NPI like numbers

    10 digits in length, starting w/ 1 to prevent integer overflow at
    2,147,483,647