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.

36 Examples 7

Example 1

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    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
View license
    @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
View license
    @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
View license
    @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
View license
    @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
View license
    @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
View license
    @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
View license
    @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
View license
    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 10

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    @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 11

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    @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 12

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    @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 13

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    @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 14

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    @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 15

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    @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 16

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    @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 17

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

Example 18

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    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 19

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

Example 20

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    def test_getitem_with_other_than_slice_or_in(self):
        with pytest.raises(TypeError):
            Ltree('1.2')['something']

Example 21

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    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 22

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    def test_index_raises_value_error_if_subpath_not_found(self):
        with pytest.raises(ValueError):
            Ltree('1.2').index('3')

Example 23

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    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 24

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

Example 25

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

Example 26

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

Example 27

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

Example 28

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

Example 29

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    def test_getitem_with_other_than_slice_or_in(self):
        with pytest.raises(TypeError):
            Ltree('1.2')['something']

Example 30

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    def test_index_raises_value_error_if_subpath_not_found(self):
        with pytest.raises(ValueError):
            Ltree('1.2').index('3')

Example 31

Project: sqlalchemy-utils
Source File: test_ltree.py
View license
    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 32

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

Example 33

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

Example 34

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

Example 35

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

Example 36

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