• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 23710389144

29 Mar 2026 01:42PM UTC coverage: 92.849% (-0.07%) from 92.917%
23710389144

Pull #23200

github

web-flow
Merge 7a0639d44 into da60c6486
Pull Request #23200: perf: Port FrozenOrderedSet to rust

22 of 26 new or added lines in 6 files covered. (84.62%)

77 existing lines in 13 files now uncovered.

91400 of 98439 relevant lines covered (92.85%)

4.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.94
/src/python/pants/engine/collection_test.py
1
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from pants.engine.collection import Collection, DeduplicatedCollection
1✔
5

6

7
class Examples(Collection[int]):
1✔
8
    """A new type to ensure that subclassing works properly."""
9

10

11
class Examples2(Collection[int]):
1✔
12
    pass
1✔
13

14

15
def test_collection_contains() -> None:
1✔
16
    c1 = Collection([1, 2])
1✔
17
    assert 1 in c1
1✔
18
    assert 2 in c1
1✔
19
    assert 200 not in c1
1✔
20
    assert "bad" not in c1  # type: ignore[comparison-overlap]
1✔
21

22

23
def test_collection_iteration() -> None:
1✔
24
    c1 = Collection([1, 2])
1✔
25
    assert list(iter(c1)) == [1, 2]
1✔
26
    assert list(c1) == [1, 2]
1✔
27

28

29
def test_collection_length() -> None:
1✔
30
    assert len(Collection([])) == 0
1✔
31
    assert len(Collection([1, 2])) == 2
1✔
32

33

34
def test_collection_index() -> None:
1✔
35
    c1 = Collection([0, 1, 2])
1✔
36
    assert c1[0] == 0
1✔
37
    assert c1[-1] == 2
1✔
38

39
    assert c1[:] == c1
1✔
40
    assert c1[1:] == Collection([1, 2])
1✔
41
    assert c1[:1] == Collection([0])
1✔
42

43

44
def test_collection_reversed() -> None:
1✔
45
    assert list(reversed(Collection([1, 2, 3]))) == [3, 2, 1]
1✔
46

47

48
def test_collection_equality() -> None:
1✔
49
    assert () != Collection()
1✔
50
    assert Collection() != ()
1✔
51

52
    assert Collection([]) == Collection([])
1✔
53
    c1 = Collection([1, 2, 3])
1✔
54
    assert c1 == Collection([1, 2, 3])
1✔
55

56
    assert c1 != Collection([3, 2, 1])
1✔
57
    assert c1 != Collection([])
1✔
58
    assert c1 != Collection([1, 2])
1✔
59

60
    e1 = Examples([1, 2, 3])
1✔
61
    assert e1 == Examples([1, 2, 3])
1✔
62
    assert e1 != Examples2([1, 2, 3])
1✔
63

64

65
def test_collection_hash() -> None:
1✔
66
    assert hash(Collection([])) == hash(Collection([]))
1✔
67

68
    c1 = Collection([1, 2, 3])
1✔
69
    assert hash(c1) == hash(Collection([1, 2, 3]))
1✔
70
    assert hash(c1) == hash(Examples([1, 2, 3]))
1✔
71

72

73
def test_collection_bool() -> None:
1✔
74
    assert bool(Collection([0])) is True
1✔
75
    assert bool(Collection([])) is False
1✔
76

77

78
def test_collection_repr() -> None:
1✔
79
    assert repr(Collection([])) == "Collection([])"
1✔
80
    assert repr(Examples([])) == "Examples([])"
1✔
81
    assert repr(Collection([1, 2, 3])) == "Collection([1, 2, 3])"
1✔
82
    assert repr(Examples([1, 2, 3])) == "Examples([1, 2, 3])"
1✔
83

84

85
def test_deduplicated_collection() -> None:
1✔
86
    # NB: most of the functionality, like testing .union() and .intersection(), is tested
87
    # exhaustively in the tests for FrozenOrderedSet. Here, we only have a couple basic
88
    # smoke-screen tests to ensure things work properly.
89
    class DedupedExamples(DeduplicatedCollection[int]):
1✔
90
        sort_input = True
1✔
91

92
    class DedupedExamples2(DeduplicatedCollection[int]):
1✔
93
        sort_input = False
1✔
94

95
    # Test deduplication
96
    assert len(DeduplicatedCollection([1, 1, 1, 2])) == 2
1✔
97

98
    # Test equality, especially that object identity matters
99
    assert DedupedExamples([0]) == DedupedExamples([0])
1✔
100
    assert DedupedExamples([0]) != DedupedExamples2([0])
1✔
101

102
    # Test hash
UNCOV
103
    c = DeduplicatedCollection([0, 1, 2])
×
UNCOV
104
    assert hash(c) == hash(DeduplicatedCollection([0, 1, 2]))
×
UNCOV
105
    assert hash(c) != hash(DeduplicatedCollection([0, 1]))
×
106

107
    # Test contains
UNCOV
108
    assert 2 in DeduplicatedCollection([0, 1, 2])
×
UNCOV
109
    assert 20 not in DeduplicatedCollection([0, 1, 2])
×
110

111
    # Test sorting
UNCOV
112
    assert list(DedupedExamples([2, 1])) == [1, 2]
×
UNCOV
113
    assert list(DedupedExamples2([2, 1])) == [2, 1]
×
114

115
    # Test the interaction of sorting with equality
UNCOV
116
    assert DedupedExamples([2, 1]) == DedupedExamples([1, 2])
×
UNCOV
117
    assert DedupedExamples2([2, 1]) != DedupedExamples2([1, 2])
×
118

119
    # Test bool
UNCOV
120
    assert bool(DeduplicatedCollection([])) is False
×
UNCOV
121
    assert bool(DeduplicatedCollection([1])) is True
×
122

123
    # Test repr
UNCOV
124
    assert repr(DedupedExamples()) == "DedupedExamples([])"
×
UNCOV
125
    assert repr(DedupedExamples([0, 1])) == "DedupedExamples([0, 1])"
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc