Here are the examples of the python api sqlalchemy_utils.Ltree taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
18 Examples
3
Example 1
def test_constructor_with_wrong_type(self):
with pytest.raises(TypeError) as e:
Ltree(None)
assert str(e.value) == (
"Ltree() argument must be a string or an Ltree, not 'NoneType'"
)
3
Example 2
@pytest.mark.parametrize(
('path', 'length'),
(
('path', 1),
('1.1', 2),
('1.2.3', 3)
)
)
def test_length(self, path, length):
assert len(Ltree(path)) == length
3
Example 3
@pytest.mark.parametrize(
('path', 'subpath', 'index'),
(
('path.path', 'path', 0),
('1.2.3', '2.3', 1),
('1.2.3.4', '2.3', 1),
('1.2.3.4', '3.4', 2)
)
)
def test_index(self, path, subpath, index):
assert Ltree(path).index(subpath) == index
3
Example 4
@pytest.mark.parametrize(
('path', 'item_slice', 'result'),
(
('path.path', 0, 'path'),
('1.1.2.3', slice(1, 3), '1.2'),
('1.1.2.3', slice(1, None), '1.2.3'),
)
)
def test_getitem(self, path, item_slice, result):
assert Ltree(path)[item_slice] == result
3
Example 5
@pytest.mark.parametrize(
('path', 'other', 'result'),
(
('1.2.3', '4.5', '1.2.3.4.5'),
('1', '1', '1.1'),
)
)
def test_add(self, path, other, result):
assert Ltree(path) + other == result
3
Example 6
@pytest.mark.parametrize(
('path', 'other', 'result'),
(
('1.2.3', '4.5', '4.5.1.2.3'),
('1', '1', '1.1'),
)
)
def test_radd(self, path, other, result):
assert other + Ltree(path) == result
3
Example 7
@pytest.mark.parametrize(
('path', 'other', 'result'),
(
('1.2.3', '4.5', '1.2.3.4.5'),
('1', '1', '1.1'),
)
)
def test_iadd(self, path, other, result):
ltree = Ltree(path)
ltree += other
assert ltree == result
3
Example 8
@pytest.mark.parametrize(
('path', 'other', 'result'),
(
('1.2.3', '2', True),
('1.2.3', '3', True),
('1', '1', True),
('1', '2', False),
)
)
def test_contains(self, path, other, result):
assert (other in Ltree(path)) == result
0
Example 9
def test_init(self):
assert Ltree('path.path') == Ltree(Ltree('path.path'))
0
Example 10
def test_constructor_with_invalid_code(self):
with pytest.raises(ValueError) as e:
Ltree('..')
assert str(e.value) == "'..' is not a valid ltree path."
0
Example 11
Project: sqlalchemy-utils Source File: test_ltree.py
def test_getitem_with_other_than_slice_or_in(self):
with pytest.raises(TypeError):
Ltree('1.2')['something']
0
Example 12
Project: sqlalchemy-utils Source File: test_ltree.py
def test_index_raises_value_error_if_subpath_not_found(self):
with pytest.raises(ValueError):
Ltree('1.2').index('3')
0
Example 13
def test_equality_operator(self):
assert Ltree('path.path') == 'path.path'
assert 'path.path' == Ltree('path.path')
assert Ltree('path.path') == Ltree('path.path')
0
Example 14
def test_non_equality_operator(self):
assert Ltree('path.path') != u'path.'
assert not (Ltree('path.path') != 'path.path')
0
Example 15
def test_hash(self):
return hash(Ltree('path')) == hash('path')
0
Example 16
def test_repr(self):
return repr(Ltree('path')) == "Ltree('path')"
0
Example 17
def test_unicode(self):
ltree = Ltree('path.path')
assert six.text_type(ltree) == 'path.path'
0
Example 18
def test_str(self):
ltree = Ltree('path')
assert str(ltree) == 'path'