sqlalchemy_utils.Ltree

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 7

Example 1

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_constructor_with_wrong_type
    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'"
        )

Example 2

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_length
    @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

Example 3

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_index
    @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

Example 4

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_get_item
    @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

Example 5

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_add
    @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

Example 6

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_radd
    @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

Example 7

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_iadd
    @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

Example 8

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_contains
    @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

Example 9

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_init
    def test_init(self):
        assert Ltree('path.path') == Ltree(Ltree('path.path'))

Example 10

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_constructor_with_invalid_code
    def test_constructor_with_invalid_code(self):
        with pytest.raises(ValueError) as e:
            Ltree('..')
        assert str(e.value) == "'..' is not a valid ltree path."

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']

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')

Example 13

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_equality_operator
    def test_equality_operator(self):
        assert Ltree('path.path') == 'path.path'
        assert 'path.path' == Ltree('path.path')
        assert Ltree('path.path') == Ltree('path.path')

Example 14

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_non_equality_operator
    def test_non_equality_operator(self):
        assert Ltree('path.path') != u'path.'
        assert not (Ltree('path.path') != 'path.path')

Example 15

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_hash
    def test_hash(self):
        return hash(Ltree('path')) == hash('path')

Example 16

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_repr
    def test_repr(self):
        return repr(Ltree('path')) == "Ltree('path')"

Example 17

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_unicode
    def test_unicode(self):
        ltree = Ltree('path.path')
        assert six.text_type(ltree) == 'path.path'

Example 18

Project: sqlalchemy-utils Source File: test_ltree.py
Function: test_str
    def test_str(self):
        ltree = Ltree('path')
        assert str(ltree) == 'path'