def test_requires_dist(self): fields = {'name': 'project', 'version': '1.0', 'requires_dist': ['other', 'another (==1.0)']} metadata = LegacyMetadata(mapping=fields) self.assertEqual(metadata['Requires-Dist'], ['other', 'another (==1.0)']) self.assertEqual(metadata['Metadata-Version'], '1.2') self.assertNotIn('Provides', metadata) self.assertEqual(metadata['Requires-Dist'], ['other', 'another (==1.0)']) self.assertNotIn('Obsoletes', metadata) # make sure write_file uses one RFC 822 header per item fp = StringIO() metadata.write_file(fp) lines = fp.getvalue().split('\n') self.assertIn('Requires-Dist: other', lines) self.assertIn('Requires-Dist: another (==1.0)', lines) # test warnings for invalid version constraints # XXX this would cause no warnings if we used update (or the mapping # argument of the constructor), see comment in LegacyMetadata.update metadata = LegacyMetadata() metadata['Requires-Dist'] = 'Funky (Groovie)' metadata['Requires-Python'] = '1a-4' self.assertEqual(len(self.get_logs()), 2) # test multiple version matches metadata = LegacyMetadata() # XXX check PEP and see if 3 == 3.0 metadata['Requires-Python'] = '>=2.6, <3.0' metadata['Requires-Dist'] = ['Foo (>=2.6, <3.0)'] self.assertEqual(self.get_logs(), [])
def test_project_url(self): metadata = LegacyMetadata() metadata['Project-URL'] = [('one', 'http://ok')] self.assertEqual(metadata['Project-URL'], [('one', 'http://ok')]) metadata.set_metadata_version() self.assertEqual(metadata['Metadata-Version'], '1.2') # make sure this particular field is handled properly when written fp = StringIO() metadata.write_file(fp) self.assertIn('Project-URL: one,http://ok', fp.getvalue().split('\n')) fp.seek(0) metadata = LegacyMetadata() metadata.read_file(fp) self.assertEqual(metadata['Project-Url'], [('one', 'http://ok')])
def test_project_url(self): metadata = LegacyMetadata() metadata['Project-URL'] = [('one', 'http://ok')] self.assertEqual(metadata['Project-URL'], [('one', 'http://ok')]) metadata.set_metadata_version() self.assertEqual(metadata['Metadata-Version'], '1.2') # make sure this particular field is handled properly when written fp = StringIO() metadata.write_file(fp) self.assertIn('Project-URL: one,http://ok', fp.getvalue().split('\n')) fp.seek(0) metadata = LegacyMetadata() metadata.read_file(fp) self.assertEqual(metadata['Project-Url'], [('one', 'http://ok')])
def test_description_folding(self): # make sure the indentation is preserved out = StringIO() desc = dedent("""\ example:: We start here and continue here and end here. """) metadata = Metadata() metadata['description'] = desc metadata.write_file(out) folded_desc = desc.replace('\n', '\n' + (7 * ' ') + '|') self.assertIn(folded_desc, out.getvalue())
def test_description_folding(self): # make sure the indentation is preserved out = StringIO() desc = dedent("""\ example:: We start here and continue here and end here. """) metadata = LegacyMetadata() metadata['description'] = desc metadata.write_file(out) # folded_desc = desc.replace('\n', '\n' + (7 * ' ') + '|') folded_desc = desc.replace('\n', '\n' + (8 * ' ')) self.assertIn(folded_desc, out.getvalue())
def test_requires_dist(self): fields = { 'name': 'project', 'version': '1.0', 'requires_dist': ['other', 'another (==1.0)'] } metadata = LegacyMetadata(mapping=fields) self.assertEqual(metadata['Requires-Dist'], ['other', 'another (==1.0)']) self.assertEqual(metadata['Metadata-Version'], '1.2') self.assertNotIn('Provides', metadata) self.assertEqual(metadata['Requires-Dist'], ['other', 'another (==1.0)']) self.assertNotIn('Obsoletes', metadata) # make sure write_file uses one RFC 822 header per item fp = StringIO() metadata.write_file(fp) lines = fp.getvalue().split('\n') self.assertIn('Requires-Dist: other', lines) self.assertIn('Requires-Dist: another (==1.0)', lines) # test warnings for invalid version constraints # XXX this would cause no warnings if we used update (or the mapping # argument of the constructor), see comment in LegacyMetadata.update metadata = LegacyMetadata() metadata['Requires-Dist'] = 'Funky (Groovie)' metadata['Requires-Python'] = '1a-4' self.assertEqual(len(self.get_logs()), 2) # test multiple version matches metadata = LegacyMetadata() # XXX check PEP and see if 3 == 3.0 metadata['Requires-Python'] = '>=2.6, <3.0' metadata['Requires-Dist'] = ['Foo (>=2.6, <3.0)'] self.assertEqual(self.get_logs(), [])