def test_metadata_with_unexisting_icon(self): def _fake_extractor(file_path): return extractors.ExtractedMetadata( icon='test/extracted/unexistent/icon/path') self.useFixture( fixture_setup.FakeMetadataExtractor('fake', _fake_extractor)) # The meta generation should just ignore the dead path, and not fail. self.generate_meta_yaml(build=True)
def test_handled_file(self): open('test-metadata-file', 'w').close() def _fake_extractor(file_path): return extractors.ExtractedMetadata(summary='test summary', description='test description') self.useFixture( fixture_setup.FakeMetadataExtractor('fake', _fake_extractor)) metadata = extract_metadata('test-part', 'test-metadata-file') self.assertThat(metadata.get_summary(), Equals('test summary')) self.assertThat(metadata.get_description(), Equals('test description'))
def test_unhandled_file(self): open('unhandled-file', 'w').close() def _fake_extractor(file_path): raise extractors.UnhandledFileError(file_path, 'fake') self.useFixture( fixture_setup.FakeMetadataExtractor('fake', _fake_extractor)) raised = self.assertRaises(errors.UnhandledMetadataFileTypeError, extract_metadata, 'test-part', 'unhandled-file') self.assertThat(raised.path, Equals('unhandled-file'))
def test_extractor_returning_invalid_things(self): open('unhandled-file', 'w').close() def _fake_extractor(file_path): return "I'm not metadata!" self.useFixture( fixture_setup.FakeMetadataExtractor('fake', _fake_extractor)) raised = self.assertRaises(errors.InvalidExtractorValueError, extract_metadata, 'test-part', 'unhandled-file') self.assertThat(raised.path, Equals('unhandled-file')) self.assertThat(raised.extractor_name, Equals('fake'))
def test_metadata_doesnt_overwrite_specified(self): def _fake_extractor(file_path): return extractors.ExtractedMetadata( summary='extracted summary', description='extracted description') self.useFixture( fixture_setup.FakeMetadataExtractor('fake', _fake_extractor)) y = self.generate_meta_yaml(build=True) # Since both summary and description were specified, neither should be # overwritten self.assertThat(y['summary'], Equals(self.config_data['summary'])) self.assertThat(y['description'], Equals(self.config_data['description']))
def test_metadata_doesnt_overwrite_icon_file(self): os.makedirs(self.directory) icon_content = 'setup icon' _create_file(os.path.join(self.directory, self.file_name), content=icon_content) def _fake_extractor(file_path): return extractors.ExtractedMetadata( icon='test/extracted/unexistent/icon/path') self.useFixture( fixture_setup.FakeMetadataExtractor('fake', _fake_extractor)) self.generate_meta_yaml(build=True) expected_icon = os.path.join(self.meta_dir, 'gui', self.file_name) self.assertThat(expected_icon, FileContains(icon_content))
def test_metadata_not_all_properties_satisfied(self): del self.config_data['summary'] del self.config_data['description'] def _fake_extractor(file_path): return extractors.ExtractedMetadata( description='extracted description') self.useFixture( fixture_setup.FakeMetadataExtractor('fake', _fake_extractor)) # Assert that description has been satisfied by extracted metadata, but # summary has not. raised = self.assertRaises(meta_errors.MissingSnapcraftYamlKeysError, self.generate_meta_yaml, build=True) self.assertThat(raised.keys, Equals("'summary'"))
def test_metadata_doesnt_overwrite_desktop_file(self): os.makedirs(self.directory) desktop_content = 'setup desktop' _create_file(os.path.join(self.directory, 'test-app.desktop'), content=desktop_content) def _fake_extractor(file_path): return extractors.ExtractedMetadata( desktop_file_ids=['com.example.test-app.desktop']) self.useFixture( fixture_setup.FakeMetadataExtractor('fake', _fake_extractor)) self.generate_meta_yaml(build=True) expected_desktop = os.path.join(self.meta_dir, 'gui', 'test-app.desktop') self.assertThat(expected_desktop, FileContains(desktop_content))
def test_metadata_satisfies_required_property(self): del self.config_data['summary'] def _fake_extractor(file_path): return extractors.ExtractedMetadata( summary='extracted summary', description='extracted description') self.useFixture( fixture_setup.FakeMetadataExtractor('fake', _fake_extractor)) y = self.generate_meta_yaml(build=True) # Summary should come from the extracted metadata, while description # should not. self.assertThat(y['summary'], Equals('extracted summary')) self.assertThat(y['description'], Equals(self.config_data['description']))
def test_extractor_missing_extract_function(self): fake_logger = fixtures.FakeLogger(level=logging.WARN) self.useFixture(fake_logger) open('unhandled-file', 'w').close() def _fake_extractor(file_path): raise extractors.UnhandledFileError(file_path, 'fake') self.useFixture( fixture_setup.FakeMetadataExtractor('fake', _fake_extractor, 'not_extract')) raised = self.assertRaises(errors.UnhandledMetadataFileTypeError, extract_metadata, 'test-part', 'unhandled-file') self.assertThat(raised.path, Equals('unhandled-file')) self.assertThat( fake_logger.output, Contains("'fake' doesn't include the 'extract' function"))