~tseaver/pkginfo/trunk

« back to all changes in this revision

Viewing changes to pkginfo/tests/test_distribution.py

  • Committer: Tres Seaver
  • Date: 2024-05-02 23:55:19 UTC
  • Revision ID: tseaver@palladion.com-20240502235519-0k82yv6258wvz2xz
Emit warnings for distributions unknown metadata versions

Includes metadata versions newer than highest supported version.

LP #2058697.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import warnings
 
2
 
1
3
import pytest
2
4
 
3
5
def test__must_decode_w_bytes_latin1():
86
88
    with pytest.raises(NotImplementedError):
87
89
        dist.read()
88
90
 
 
91
def test_distribution__getHeaderAttrs_hit():
 
92
    from pkginfo.distribution import HEADER_ATTRS_1_0
 
93
 
 
94
    dist = _make_distribution()
 
95
    assert dist._getHeaderAttrs() == HEADER_ATTRS_1_0
 
96
 
 
97
def test_distribution__getHeaderAttrs_miss_unknown():
 
98
    from pkginfo.distribution import UnknownMetadataVersion
 
99
 
 
100
    NONESUCH = "nonesuch"
 
101
 
 
102
    dist = _make_distribution(NONESUCH)
 
103
    with warnings.catch_warnings(record=True) as warned:
 
104
        assert dist._getHeaderAttrs() == ()
 
105
 
 
106
    assert len(warned) == 1
 
107
    assert warned[0].category is UnknownMetadataVersion
 
108
    assert NONESUCH in str(warned[0].message)
 
109
 
 
110
def test_distribution__getHeaderAttrs_miss_new():
 
111
    from pkginfo.distribution import HEADER_ATTRS
 
112
    from pkginfo.distribution import MAX_METADATA_VERSION_STR
 
113
    from pkginfo.distribution import NewMetadataVersion
 
114
 
 
115
    HIGH_VERSION = "99.99"
 
116
 
 
117
    dist = _make_distribution(HIGH_VERSION)
 
118
    with warnings.catch_warnings(record=True) as warned:
 
119
        assert dist._getHeaderAttrs() == HEADER_ATTRS[MAX_METADATA_VERSION_STR]
 
120
 
 
121
    assert len(warned) == 1
 
122
    assert warned[0].category is NewMetadataVersion
 
123
    assert HIGH_VERSION in str(warned[0].message)
 
124
 
89
125
def test_distribution_parse_given_unicode():
90
126
    dist = _make_distribution()
91
127
    dist.parse(u'Metadata-Version: 1.0\nName: lp722928_c3') # no raise
133
169
    assert list(dist) == [x[1] for x in HEADER_ATTRS_2_3]
134
170
 
135
171
def test_distribution_parse_Metadata_Version_unknown():
 
172
    from pkginfo.distribution import UnknownMetadataVersion
 
173
 
136
174
    dist = _make_distribution(None)
137
 
    dist.parse('Metadata-Version: 1.3')
 
175
 
 
176
    with warnings.catch_warnings(record=True) as warned:
 
177
        dist.parse('Metadata-Version: 1.3')
 
178
        assert list(dist) == []
 
179
 
138
180
    assert dist.metadata_version == '1.3'
139
 
    assert list(dist) == []
 
181
 
 
182
    assert len(warned) == 1
 
183
    assert warned[0].category is UnknownMetadataVersion
 
184
    assert "1.3" in str(warned[0].message)
140
185
 
141
186
def test_distribution_parse_Metadata_Version_override():
142
187
    dist = _make_distribution('1.2')