Skip to content

Commit

Permalink
Convert more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Feb 18, 2024
1 parent 288b35b commit bdeecad
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 141 deletions.
6 changes: 0 additions & 6 deletions silver_platter/proposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,4 @@
"EmptyMergeProposal",
"find_existing_proposed",
"SourceNotDerivedFromTarget",
"enable_tag_pushing",
]


def enable_tag_pushing(branch: Branch) -> None:
stack = branch.get_config()
stack.set_user_option("branch.fetch_tags", True)
24 changes: 10 additions & 14 deletions src/codemod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use breezyshim::controldir::{
create_branch_convenience, create_standalone_workingtree, ControlDirFormat,
};
use breezyshim::tree::{CommitError, WorkingTree};
use breezyshim::RevisionId;
use std::collections::HashMap;
Expand Down Expand Up @@ -294,6 +297,7 @@ pub fn script_runner(

#[cfg(test)]
mod script_runner_tests {
use super::*;
use breezyshim::tree::MutableTree;

fn make_executable(script_path: &std::path::Path) {
Expand All @@ -311,9 +315,7 @@ mod script_runner_tests {
fn test_no_api() {
let td = tempfile::tempdir().unwrap();
let d = td.path().join("t");
let tree =
breezyshim::controldir::ControlDir::create_standalone_workingtree(&d, Some(&"bzr"))
.unwrap();
let tree = create_standalone_workingtree(&d, "bzr").unwrap();
let script_path = d.join("script.sh");
std::fs::write(
&script_path,
Expand Down Expand Up @@ -351,9 +353,7 @@ echo Did a thing
fn test_api() {
let td = tempfile::tempdir().unwrap();
let d = td.path().join("t");
let tree =
breezyshim::controldir::ControlDir::create_standalone_workingtree(&d, Some(&"bzr"))
.unwrap();
let tree = create_standalone_workingtree(&d, "bzr").unwrap();
let script_path = d.join("script.sh");
std::fs::write(
&script_path,
Expand Down Expand Up @@ -391,9 +391,7 @@ echo '{"description": "Did a thing", "code": "success"}' > $SVP_RESULT
fn test_new_file() {
let td = tempfile::tempdir().unwrap();
let d = td.path().join("t");
let tree =
breezyshim::controldir::ControlDir::create_standalone_workingtree(&d, Some(&"bzr"))
.unwrap();
let tree = create_standalone_workingtree(&d, "bzr").unwrap();
let script_path = d.join("script.sh");
std::fs::write(
&script_path,
Expand Down Expand Up @@ -434,11 +432,9 @@ echo Did a thing
fn test_no_changes() {
let td = tempfile::tempdir().unwrap();
let d = td.path().join("t");
let tree = breezyshim::controldir::ControlDir::create_standalone_workingtree(
&d,
Some(&breezyshim::controldir::ControlDirFormat::get_default()),
)
.unwrap();
let tree =
create_standalone_workingtree(&d, &breezyshim::controldir::ControlDirFormat::default())
.unwrap();
let script_path = d.join("script.sh");
std::fs::write(
&script_path,
Expand Down
138 changes: 138 additions & 0 deletions src/publish.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
pub use crate::proposal::DescriptionFormat;
use crate::vcs::open_branch;
use crate::Mode;
use breezyshim::bazaar::tree::MutableInventoryTree;
use breezyshim::bazaar::FileId;
use breezyshim::branch::MemoryBranch;
use breezyshim::controldir::{
create_branch_convenience, create_standalone_workingtree, ControlDirFormat,
};
use breezyshim::forge::Error as ForgeError;
use breezyshim::merge::{MergeType, Merger};
use breezyshim::{Branch, Forge, MergeProposal, RevisionId, Transport};
Expand Down Expand Up @@ -86,6 +91,19 @@ pub fn push_result(
Ok(())
}

#[test]
fn test_push_result() {
let td = tempfile::tempdir().unwrap();
let target_path = td.path().join("target");
let source_path = td.path().join("source");
let target_url = url::Url::from_file_path(&target_path).unwrap();
let target = create_branch_convenience(&target_url).unwrap();
let source = create_standalone_workingtree(&source_path, &ControlDirFormat::default()).unwrap();
let revid = source.commit("Some change", None, None, None).unwrap();
push_result(source.branch().as_ref(), target.as_ref(), None, None, None).unwrap();
assert_eq!(target.last_revision(), revid);
}

pub fn push_changes(
local_branch: &dyn Branch,
main_branch: &dyn Branch,
Expand Down Expand Up @@ -711,6 +729,126 @@ pub fn check_proposal_diff_empty(
Ok(!changes.any(|_| true))
}

#[test]
fn test_no_new_commits() {
let td = tempfile::tempdir().unwrap();
let orig = td.path().join("orig");
let tree = create_standalone_workingtree(&orig, &ControlDirFormat::default()).unwrap();

std::fs::write(orig.join("a"), "a").unwrap();
tree.add(&[std::path::Path::new("a")]).unwrap();
tree.commit("blah", None, None, None).unwrap();

let proposal_url = url::Url::from_file_path(orig.join("proposal")).unwrap();

let proposal = tree
.controldir()
.sprout(proposal_url, None, None, None)
.open_branch(None)
.unwrap();
assert!(check_proposal_diff_empty(proposal.as_ref(), tree.branch().as_ref(), None).unwrap());
}

#[test]
fn test_no_op_commits() {
let td = tempfile::tempdir().unwrap();
let orig = td.path().join("orig");
let tree = create_standalone_workingtree(&orig, &ControlDirFormat::default()).unwrap();

std::fs::write(orig.join("a"), "a").unwrap();
tree.add(&[std::path::Path::new("a")]).unwrap();
tree.commit("blah", None, None, None).unwrap();

let proposal_url = url::Url::from_file_path(orig.join("proposal")).unwrap();

let proposal = tree
.controldir()
.sprout(proposal_url, None, None, None)
.open_workingtree()
.unwrap();
proposal
.commit("another commit that is pointless", None, None, None)
.unwrap();

assert!(
check_proposal_diff_empty(proposal.branch().as_ref(), tree.branch().as_ref(), None)
.unwrap()
);
}

#[test]
fn test_indep() {
let td = tempfile::tempdir().unwrap();
let orig = td.path().join("orig");
let tree = create_standalone_workingtree(&orig, &ControlDirFormat::default()).unwrap();

std::fs::write(orig.join("a"), "a").unwrap();
tree.add(&[std::path::Path::new("a")]).unwrap();
tree.commit("blah", None, None, None).unwrap();

std::fs::write(orig.join("b"), "b").unwrap();
std::fs::write(orig.join("c"), "c").unwrap();
tree.add(&[std::path::Path::new("b"), std::path::Path::new("c")])
.unwrap();
tree.commit("independent", None, None, None).unwrap();

let proposal_url = url::Url::from_file_path(orig.join("proposal")).unwrap();

let proposal = tree
.controldir()
.sprout(proposal_url, None, None, None)
.open_workingtree()
.unwrap();

std::fs::write(td.path().join("proposal").join("b"), "b").unwrap();

if proposal.supports_setting_file_ids() {
MutableInventoryTree::add(
&proposal,
&[std::path::Path::new("b")],
&[FileId::from("b")],
)
.unwrap();
} else {
proposal.add(&[std::path::Path::new("b")]).unwrap();
}
proposal.commit("not pointless", None, None, None).unwrap();

assert!(
check_proposal_diff_empty(proposal.branch().as_ref(), tree.branch().as_ref(), None)
.unwrap()
);
}

#[test]
fn test_changes() {
let td = tempfile::tempdir().unwrap();
let orig = td.path().join("orig");
let tree = create_standalone_workingtree(&orig, &ControlDirFormat::default()).unwrap();
std::fs::write(orig.join("a"), "a").unwrap();
tree.add(&[std::path::Path::new("a")]).unwrap();
tree.commit("blah", None, None, None).unwrap();

let proposal_url = url::Url::from_file_path(td.path().join("proposal")).unwrap();
let proposal_tree = tree
.controldir()
.sprout(proposal_url, None, None, None)
.open_workingtree()
.unwrap();
std::fs::write(proposal_tree.basedir().join("b"), "b").unwrap();
proposal_tree.add(&[std::path::Path::new("b")]).unwrap();
proposal_tree
.commit("not pointless", None, None, None)
.unwrap();

assert!(!check_proposal_diff_empty(
proposal_tree.branch().as_ref(),
tree.branch().as_ref(),
None
)
.unwrap());
}

pub fn enable_tag_pushing(branch: &dyn Branch) -> PyResult<()> {
Python::with_gil(|py| {
let branch = branch.to_object(py);
Expand Down
15 changes: 10 additions & 5 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ fn test_simple() {
let path = td.path().join("test.yaml");
std::fs::write(
&path,
r#"name: test
r#"---
name: test
command: ["echo", "hello"]
mode: propose
merge-request:
commit-message: "test commit message"
title: "test title"
description: "test description"
description:
plain: "test description"
"#,
)
.unwrap();
Expand All @@ -110,9 +112,12 @@ merge-request:
commit_message: Some("test commit message".to_string()),
title: Some("test title".to_string()),
propose_threshold: None,
description: vec![(None, "test description".to_string())]
.into_iter()
.collect(),
description: vec![(
Some(DescriptionFormat::Plain),
"test description".to_string()
)]
.into_iter()
.collect(),
})
);
}
3 changes: 0 additions & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ def test_suite():
"debian",
"probers",
"proposal",
"publish",
"recipe",
"run",
"workspace",
]
module_names = [__name__ + ".test_" + name for name in names]
Expand Down
113 changes: 0 additions & 113 deletions tests/test_publish.py

This file was deleted.

0 comments on commit bdeecad

Please sign in to comment.