def test_sorted_iterable(self): sorted_data = ['bar', 'foo', 'foobar'] d = simtrie.Set(sorted_data, sorted=True) assert 'bar' in d assert 'foo' in d
def test_unicode_sorting(self): key1 = '\uff72\uff9c\uff90\uff7b\uff9e\uff9c' key2 = '\U00010345\U0001033f\U00010337\U00010330\U0001033d' # This apparently depends on Python version: # assert key1 < key2 assert key1.encode('utf8') < key2.encode('utf8') # Constructor should sort data according to utf8 values, # not according to unicode sorting rules. It will raise an exception # if data is sorted according to unicode rules. simtrie.Set([key1, key2], sorted=True)
def test_contains_with_null_bytes(self): d = simtrie.Set(['foo']) assert b'foo' in d assert b'foo\x00bar' not in d
def test_build_errors(self): with pytest.raises(ValueError): data = [b'foo\x00bar', b'bar'] simtrie.Set(data)
def test_no_segfaults_after_wrong_stream(self): d = simtrie.Set() assert 'random-key' not in d
def test_no_segfaults_on_invalid_file(self): d = simtrie.Set() with pytest.raises(IOError) as e: d.frombytes(b"foo")
def _dam_lev(a, b, metric=None): s = simtrie.Set([a]) for k, cost in s.similar(b, MAX_COST, metric=metric, allow_transpose=True): assert k == a return cost
def _lev(a, b, metric): s = simtrie.Set([a]) for k, cost in s.similar(b, MAX_COST, metric): assert k == a return cost
def get_cost(a, b): s = simtrie.Set([a]) for k, cost in s.similar(b, 10): assert k == a return cost
def test_no_segfaults_on_empty_dawg(self): d = simtrie.Set([]) assert list(d.keys()) == []
def empty_dawg(self): return simtrie.Set()
def dawg(self): return simtrie.Set(self.keys)