def test_constructor(self, workdir): shutil.copy(os.path.join(TEST_FILES_DIR, SPEC_FILE), workdir) # check that no mandatory argument was added spec = SpecFile(SPEC_FILE) assert isinstance(spec, SpecFile) # check that arguments were not renamed or removed spec = SpecFile(path=SPEC_FILE, sources_location=workdir, predefined_macros=None) assert isinstance(spec, SpecFile)
def specfile(self) -> SpecFile: # changing API is fun, where else could we use inspect? s = inspect.signature(SpecFile) if "changelog_entry" in s.parameters: return SpecFile( path=self.specfile_path, sources_location=self.specfile_dir, changelog_entry=None, ) else: return SpecFile(path=self.specfile_path, sources_location=self.specfile_dir)
def specfile(self) -> SpecFile: if self._specfile is None: # changing API is fun, where else could we use inspect? s = inspect.signature(SpecFile) if "changelog_entry" in s.parameters: self._specfile = SpecFile( path=self.absolute_specfile_path, sources_location=str(self.absolute_specfile_dir), changelog_entry="", ) else: self._specfile = SpecFile( path=self.absolute_specfile_path, sources_location=str(self.absolute_specfile_dir), ) return self._specfile
def _prepare_spec_objects(self): """ Prepare spec files and initialize objects :return: """ self.rebase_spec_file_path = get_rebase_name(self.results_dir, self.spec_file_path) self.spec_file = SpecFile(self.spec_file_path, self.execution_dir, download=not self.conf.not_download_sources) # Check whether test suite is enabled at build time if not self.spec_file.is_test_suite_enabled(): results_store.set_info_text( 'WARNING', 'Test suite is not enabled at build time.') # create an object representing the rebased SPEC file self.rebase_spec_file = self.spec_file.copy(self.rebase_spec_file_path) # check if argument passed as new source is a file or just a version if [ True for ext in Archive.get_supported_archives() if self.conf.sources.endswith(ext) ]: logger.debug("argument passed as a new source is a file") self.rebase_spec_file.set_version_using_archive(self.conf.sources) else: logger.debug("argument passed as a new source is a version") version, extra_version, separator = SpecFile.split_version_string( self.conf.sources) self.rebase_spec_file.set_version(version) self.rebase_spec_file.set_extra_version_separator(separator) self.rebase_spec_file.set_extra_version(extra_version)
def test_basic_local_update_patch_content(sourcegit_n_distgit, mock_remote_functionality_sourcegit, api_instance_source_git): """ propose-update for sourcegit test: mock remote API, use local upstream and dist-git """ sourcegit, distgit = sourcegit_n_distgit source_file = sourcegit / "big-source-file.txt" source_file.write_text("new changes") git_add_and_commit(directory=sourcegit, message="source change") api_instance_source_git.sync_release("master", "0.1.0", upstream_ref="0.1.0") spec = SpecFile(str(distgit / "beer.spec"), None) spec_package_section = "\n".join(spec.spec_content.sections["%package"]) assert "Patch0001: 0001" in spec_package_section assert "Patch0002: 0002" in spec_package_section git_diff = subprocess.check_output(["git", "diff", "HEAD~", "HEAD"], cwd=distgit).decode() assert "-Version: 0.0.0\n+Version: 0.1.0" in git_diff assert "+# PATCHES FROM SOURCE GIT:" in git_diff assert ( "-* Mon Feb 24 2019 Tomas Tomecek <*****@*****.**> - 0.0.0-1\n" "-- No brewing, yet.\n" "+* Mon Feb 25 2019 Tomas Tomecek <*****@*****.**> - 0.1.0-1\n" "+- Initial brewing" in git_diff) # direct diff in the synced file assert ("diff --git a/.packit.yaml b/.packit.yaml\n" "new file mode 100644" in git_diff) assert "--- /dev/null\n" "+++ b/.packit.yaml" in git_diff # diff of the synced file should not be in the patch assert ("+diff --git a/.packit.yaml b/.packit.yaml\n" "+new file mode 100644\n" not in git_diff) # diff of the source file (not synced) has to be in the patch assert ("patch\n" "@@ -0,0 +1,9 @@\n" "+diff --git a/big-source-file.txt b/big-source-file.txt\n" in git_diff) assert ("+--- a/big-source-file.txt\n" "++++ b/big-source-file.txt\n" "+@@ -1,2 +1 @@\n" "+-This is a testing file\n" "+-containing some text.\n" "++new changes\n" in git_diff) # diff of the source files (not synced) should not be directly in the git diff assert ("--- a/big-source-file.txt\n" "+++ b/big-source-file.txt\n" "@@ -1,2 +1 @@\n" "-This is a testing file\n" "-containing some text.\n" "+new changes\n" not in git_diff)
def specfile(self): if self._specfile is None: self._specfile = SpecFile( path=self.specfile_path, sources_location=self.local_project.working_dir, changelog_entry=None, ) return self._specfile
def _prepare_spec_objects(self): """ Prepare spec files and initialize objects :return: """ self.rebase_spec_file_path = get_rebase_name(self.rebased_sources_dir, self.spec_file_path) self.spec_file = SpecFile(self.spec_file_path, self.conf.changelog_entry, self.execution_dir, download=not self.conf.not_download_sources) # Check whether test suite is enabled at build time if not self.spec_file.is_test_suite_enabled(): results_store.set_info_text('WARNING', 'Test suite is not enabled at build time.') # create an object representing the rebased SPEC file self.rebase_spec_file = self.spec_file.copy(self.rebase_spec_file_path) if not self.conf.sources: self.conf.sources = versioneers_runner.run(self.conf.versioneer, self.spec_file.get_package_name(), self.spec_file.category, self.conf.versioneer_blacklist) if self.conf.sources: logger.info("Determined latest upstream version '%s'", self.conf.sources) else: raise RebaseHelperError('Could not determine latest upstream version ' 'and no SOURCES argument specified!') # Prepare rebased_sources_dir self.rebased_repo = self._prepare_rebased_repository(self.spec_file.patches, self.execution_dir, self.rebased_sources_dir) # check if argument passed as new source is a file or just a version if [True for ext in Archive.get_supported_archives() if self.conf.sources.endswith(ext)]: logger.debug("argument passed as a new source is a file") self.rebase_spec_file.set_version_using_archive(self.conf.sources) else: logger.debug("argument passed as a new source is a version") version, extra_version, separator = SpecFile.split_version_string(self.conf.sources) self.rebase_spec_file.set_version(version) self.rebase_spec_file.set_extra_version_separator(separator) self.rebase_spec_file.set_extra_version(extra_version) if not self.conf.skip_version_check and parse_version(self.rebase_spec_file.get_version()) \ <= parse_version(self.spec_file.get_version()): raise RebaseHelperError("Current version is equal to or newer than the requested version, nothing to do.") # run spec hooks spec_hooks_runner.run_spec_hooks(self.spec_file, self.rebase_spec_file, **self.kwargs) # spec file object has been sanitized downloading can proceed for spec_file in [self.spec_file, self.rebase_spec_file]: if spec_file.download: spec_file.download_remote_sources() # parse spec again with sources downloaded to properly expand %prep section spec_file._update_data() # pylint: disable=protected-access
def test_single_message(github_release_fedmsg, mock_upstream_remote_functionality): u, d = mock_upstream_remote_functionality conf = get_test_config() api = PackitBotAPI(conf) api.sync_upstream_release_with_fedmsg(github_release_fedmsg) assert (d / TARBALL_NAME).is_file() spec = SpecFile(str(d / "beer.spec"), None) assert spec.get_version() == "0.1.0"
def test_single_message(github_release_fedmsg, mock_remote_functionality_upstream): u, d = mock_remote_functionality_upstream conf = get_test_config() api = PackitBotAPI(conf) flexmock(Repo).should_receive("clone_from").and_return(git.Repo(str(u))) api.sync_upstream_release_with_fedmsg(github_release_fedmsg) assert (d / TARBALL_NAME).is_file() spec = SpecFile(str(d / "beer.spec"), None) assert spec.get_version() == "0.1.0"
def test_basic_local_update(upstream_n_distgit, mock_upstream_remote_functionality): """ basic propose-update test: mock remote API, use local upstream and dist-git """ u, d = upstream_n_distgit chdir(u) c = get_test_config() pc = get_local_package_config(str(u)) pc.upstream_project_url = str(u) pc.downstream_project_url = str(d) api = PackitAPI(c, pc) api.sync_release("master", "0.1.0") assert (d / TARBALL_NAME).is_file() spec = SpecFile(str(d / "beer.spec"), None) assert spec.get_version() == "0.1.0"
def test_basic_local_update_from_downstream( downstream_n_distgit, mock_downstream_remote_functionality): flexmock(LocalProject, _parse_namespace_from_git_url=lambda: None) u, d = downstream_n_distgit with cwd(u): c = get_test_config() pc = get_local_package_config(str(u)) pc.upstream_project_url = str(u) pc.downstream_project_url = str(d) up_lp = LocalProject(path_or_url=str(u)) api = PackitAPI(c, pc, up_lp) api.sync_from_downstream("master", "master", True) assert (u / "beer.spec").is_file() spec = SpecFile(str(u / "beer.spec"), None) assert spec.get_version() == "0.0.0"
def test_basic_local_update_without_patching( sourcegit_n_distgit, mock_patching, mock_remote_functionality_sourcegit, api_instance_source_git, ): """ propose-update for sourcegit test: mock remote API, use local upstream and dist-git """ sourcegit, distgit = sourcegit_n_distgit api_instance_source_git.sync_release("master", "0.1.0", upstream_ref="0.1.0") assert (distgit / TARBALL_NAME).is_file() spec = SpecFile(str(distgit / "beer.spec"), None) assert spec.get_version() == "0.1.0"
def parse_sources(spec_path): spec = SpecFile(spec_path) upstream_url = "" for source in spec.sources: print(f"Parsing source: {source}") source_parsed = urlparse(source) if not source_parsed.netloc: print(f"netloc not found - {source}") continue if source_parsed.netloc not in SUPPORTED_UPSTREAM_HOSTS: print(f"unsupported upstream host found - {source_parsed.netloc}") # self.unsuported_hosts.append(source_parsed.netloc) continue repo_path = "/".join(source_parsed.path.split("/")[:3]) url = f"{source_parsed.scheme}://{source_parsed.netloc}{repo_path}" if not upstream_url: upstream_url = url else: assert upstream_url == url return upstream_url
def test_basic_local_update_patching(sourcegit_n_distgit, mock_remote_functionality_sourcegit, api_instance_source_git): """ propose-update for sourcegit test: mock remote API, use local upstream and dist-git """ sourcegit, distgit = sourcegit_n_distgit api_instance_source_git.sync_release("master", "0.1.0", upstream_ref="0.1.0") assert (distgit / TARBALL_NAME).is_file() spec = SpecFile(str(distgit / "beer.spec"), None) assert spec.get_version() == "0.1.0" spec_package_section = "\n".join(spec.spec_content.sections["%package"]) assert "# PATCHES FROM SOURCE GIT" in spec_package_section assert "# sourcegit content" in spec_package_section assert "Patch0001: 0001" in spec_package_section spec_package_section_split = spec_package_section.split( "# PATCHES FROM SOURCE GIT") assert "Source" in spec_package_section_split[0] assert "Source" not in spec_package_section_split[1]
def get_specfile(path: str) -> SpecFile: s = inspect.signature(SpecFile) if "changelog_entry" in s.parameters: return SpecFile(path=path, changelog_entry=None) else: return SpecFile(path=path)
def _prepare_spec_objects(self): """ Prepare spec files and initialize objects :return: """ self.spec_file = SpecFile(self.spec_file_path, self.execution_dir, self.kwargs['rpmmacros']) # Check whether test suite is enabled at build time if not self.spec_file.is_test_suite_enabled(): results_store.set_info_text( 'WARNING', 'Test suite is not enabled at build time.') # create an object representing the rebased SPEC file self.rebase_spec_file = self.spec_file.copy( get_rebase_name(self.rebased_sources_dir, self.spec_file_path)) if not self.conf.sources: self.conf.sources = plugin_manager.versioneers.run( self.conf.versioneer, self.spec_file.header.name, self.spec_file.category, self.conf.versioneer_blacklist) if self.conf.sources: logger.info("Determined latest upstream version '%s'", self.conf.sources) else: raise RebaseHelperError( 'Could not determine latest upstream version ' 'and no SOURCES argument specified!') # Prepare rebased_sources_dir self.rebased_repo = self._prepare_rebased_repository() # check if argument passed as new source is a file or just a version if [ True for ext in Archive.get_supported_archives() if self.conf.sources.endswith(ext) ]: logger.verbose("argument passed as a new source is a file") version_string = self.spec_file.extract_version_from_archive_name( self.conf.sources, self.spec_file.get_main_source()) else: logger.verbose("argument passed as a new source is a version") version_string = self.conf.sources version, extra_version = SpecFile.split_version_string( version_string, self.spec_file.header.version) self.rebase_spec_file.set_version(version) self.rebase_spec_file.set_extra_version( extra_version, version != self.spec_file.header.version) oldver = parse_version(self.spec_file.header.version) newver = parse_version(self.rebase_spec_file.header.version) oldex = self.spec_file.parse_release()[2] newex = extra_version if not self.conf.skip_version_check and (newver < oldver or (newver == oldver and newex == oldex)): raise RebaseHelperError( "Current version is equal to or newer than the requested version, nothing to do." ) self.rebase_spec_file.update_changelog(self.conf.changelog_entry) # run spec hooks plugin_manager.spec_hooks.run(self.spec_file, self.rebase_spec_file, **self.kwargs) # spec file object has been sanitized downloading can proceed if not self.conf.not_download_sources: for spec_file in [self.spec_file, self.rebase_spec_file]: spec_file.download_remote_sources() # parse spec again with sources downloaded to properly expand %prep section spec_file.update() # all local sources have been downloaded; we can check for name changes self._sanitize_sources()
def spec_object(self, workdir): sf = SpecFile(self.SPEC_FILE, 'Update to %{version}', workdir, download=False) return sf
def spec_object(workdir): # pylint: disable=redefined-outer-name shutil.copy(os.path.join(TEST_FILES_DIR, SPEC_FILE), workdir) return SpecFile(SPEC_FILE, workdir)
def spec_object(self, workdir): sf = SpecFile(self.SPEC_FILE, workdir, download=False) return sf
def setup(self): super(TestSpecFile, self).setup() self.SPEC_FILE_OBJECT = SpecFile(self.SPEC_FILE, self.WORKING_DIR, download=False)