Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszKielar committed Sep 7, 2020
1 parent 7b6b95a commit c468c66
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 97 deletions.
88 changes: 50 additions & 38 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ pub struct Metadata {
}

impl Metadata {
pub fn new(name: String, version: String, requires_dist: Vec<String>) -> Self {
Self {
name,
version,
requires_dist,
}
}

// TODO use AsPath as an argument
pub fn from_metadata_file<'a, P>(path: &'a P) -> Result<Self, io::Error>
where
Expand Down Expand Up @@ -61,7 +53,11 @@ impl Metadata {
}
}

let metadata = Self::new(name, version, requires_dist);
let metadata = Self {
name,
version,
requires_dist,
};
Ok(metadata)
}

Expand Down Expand Up @@ -242,7 +238,11 @@ mod tests {
fn test_from_json_no_dependencies() {
// given:
let path = "./tests/data/conda-meta/pkg1-0.0.1.json";
let expected_m = Metadata::new(String::from("pkg1"), String::from("0.0.1"), vec![]);
let expected_m = Metadata {
name: String::from("pkg1"),
version: String::from("0.0.1"),
requires_dist: vec![],
};
// when:
let m = Metadata::from_json(path).unwrap();
// then:
Expand All @@ -253,11 +253,11 @@ mod tests {
fn test_from_json_one_dependency() {
// given:
let path = "./tests/data/conda-meta/pkg2a-0.0.1.json";
let expected_m = Metadata::new(
String::from("pkg2a"),
String::from("0.0.1"),
vec![String::from("pkg1")],
);
let expected_m = Metadata {
name: String::from("pkg2a"),
version: String::from("0.0.1"),
requires_dist: vec![String::from("pkg1")],
};
// when:
let m = Metadata::from_json(path).unwrap();
// then:
Expand All @@ -268,11 +268,11 @@ mod tests {
fn test_from_json_multiple_dependencies() {
// given:
let path = "./tests/data/conda-meta/pkg3-0.0.1.json";
let expected_m = Metadata::new(
String::from("pkg3"),
String::from("0.0.1"),
vec![String::from("pkg2a"), String::from("pkg2b")],
);
let expected_m = Metadata {
name: String::from("pkg3"),
version: String::from("0.0.1"),
requires_dist: vec![String::from("pkg2a"), String::from("pkg2b")],
};
// when:
let m = Metadata::from_json(path).unwrap();
// then:
Expand Down Expand Up @@ -310,11 +310,11 @@ mod tests {
"version": "0.0.1",
"depends": "pkg2"
}"#;
let expected_m = Metadata::new(
String::from("pkg1"),
String::from("0.0.1"),
vec![String::from("pkg2")],
);
let expected_m = Metadata {
name: String::from("pkg1"),
version: String::from("0.0.1"),
requires_dist: vec![String::from("pkg2")],
};
// when:
let m: Metadata = serde_json::from_str(string).unwrap();
// then:
Expand All @@ -329,7 +329,11 @@ mod tests {
"version": "0.0.1",
"depends": "python"
}"#;
let expected_m = Metadata::new(String::from("pkg1"), String::from("0.0.1"), vec![]);
let expected_m = Metadata {
name: String::from("pkg1"),
version: String::from("0.0.1"),
requires_dist: vec![],
};
// when:
let m: Metadata = serde_json::from_str(string).unwrap();
// then:
Expand All @@ -344,7 +348,11 @@ mod tests {
"version": "0.0.1",
"depends": "libsome"
}"#;
let expected_m = Metadata::new(String::from("pkg1"), String::from("0.0.1"), vec![]);
let expected_m = Metadata {
name: String::from("pkg1"),
version: String::from("0.0.1"),
requires_dist: vec![],
};
// when:
let m: Metadata = serde_json::from_str(string).unwrap();
// then:
Expand All @@ -359,7 +367,11 @@ mod tests {
"version": "0.0.1",
"depends": "_liblowlevel"
}"#;
let expected_m = Metadata::new(String::from("pkg1"), String::from("0.0.1"), vec![]);
let expected_m = Metadata {
name: String::from("pkg1"),
version: String::from("0.0.1"),
requires_dist: vec![],
};
// when:
let m: Metadata = serde_json::from_str(string).unwrap();
// then:
Expand All @@ -374,11 +386,11 @@ mod tests {
"version": "0.0.1",
"depends": ["pkg2a", "pkg2b"]
}"#;
let expected_m = Metadata::new(
String::from("pkg1"),
String::from("0.0.1"),
vec![String::from("pkg2a"), String::from("pkg2b")],
);
let expected_m = Metadata {
name: String::from("pkg1"),
version: String::from("0.0.1"),
requires_dist: vec![String::from("pkg2a"), String::from("pkg2b")],
};
// when:
let m: Metadata = serde_json::from_str(string).unwrap();
// then:
Expand All @@ -393,11 +405,11 @@ mod tests {
"version": "0.0.1",
"depends": ["pkg2a", "pkg2b", "python", "libsome", "_liblowlevel"]
}"#;
let expected_m = Metadata::new(
String::from("pkg1"),
String::from("0.0.1"),
vec![String::from("pkg2a"), String::from("pkg2b")],
);
let expected_m = Metadata {
name: String::from("pkg1"),
version: String::from("0.0.1"),
requires_dist: vec![String::from("pkg2a"), String::from("pkg2b")],
};
// when:
let m: Metadata = serde_json::from_str(string).unwrap();
// then:
Expand Down
72 changes: 30 additions & 42 deletions src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,7 @@ pub struct Package {
name: String,
version: String,
requires: Vec<Package>,
installer: Installer,
}

impl Package {
pub fn new(
name: String,
version: String,
requires: Vec<Package>,
installer: Installer,
) -> Self {
Package {
name,
version,
requires,
installer,
}
}
pub installer: Installer,
}

impl fmt::Display for Package {
Expand Down Expand Up @@ -125,31 +109,35 @@ mod tests {

#[test]
fn test_package_display_with_version() {
let package = Package::new(
String::from("package"),
String::from("1.0.0"),
vec![],
Installer::default(),
);
let package = Package {
name: String::from("package"),
version: String::from("1.0.0"),
requires: vec![],
installer: Installer::default(),
};
let package_str = format!("{}", package);
assert_eq!(package_str, "package (v1.0.0)".to_string())
}

#[test]
fn test_package_display_any_version() {
let package = Package::new(
String::from("package"),
String::from("any"),
vec![],
Installer::default(),
);
let package = Package {
name: String::from("package"),
version: String::from("any"),
requires: vec![],
installer: Installer::default(),
};
let package_str = format!("{}", package);
assert_eq!(package_str, "package".to_string())
}

#[test]
fn test_convert_from_pipmetadata_to_package() {
let metadata = Metadata::new(String::from("some_package"), String::from("1.0.0"), vec![]);
let metadata = Metadata {
name: String::from("some_package"),
version: String::from("1.0.0"),
requires_dist: vec![],
};
let expected_package = Package {
name: String::from("some_package"),
version: String::from("1.0.0"),
Expand All @@ -161,24 +149,24 @@ mod tests {

#[test]
fn test_into_string_conda() {
let p: String = Package::new(
String::from("conda1"),
String::from("0.0.1"),
vec![],
Installer::Conda,
)
let p: String = Package {
name: String::from("conda1"),
version: String::from("0.0.1"),
requires: vec![],
installer: Installer::Conda,
}
.into();
assert_eq!(p, String::from("conda1=0.0.1"))
}

#[test]
fn test_into_string_pip() {
let p: String = Package::new(
String::from("pip1"),
String::from("0.0.1"),
vec![],
Installer::Pip,
)
let p: String = Package {
name: String::from("pip1"),
version: String::from("0.0.1"),
requires: vec![],
installer: Installer::Pip,
}
.into();
assert_eq!(p, String::from("pip1==0.0.1"))
}
Expand Down
42 changes: 25 additions & 17 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,35 +168,43 @@ mod tests {
let mut expected_conda_metadata: HashMap<String, Metadata> = HashMap::new();
expected_conda_metadata.insert(
String::from("pkg1"),
Metadata::new(String::from("pkg1"), String::from("0.0.1"), vec![]),
Metadata {
name: String::from("pkg1"),
version: String::from("0.0.1"),
requires_dist: vec![],
},
);
expected_conda_metadata.insert(
String::from("pkg2a"),
Metadata::new(
String::from("pkg2a"),
String::from("0.0.1"),
vec![String::from("pkg1")],
),
Metadata {
name: String::from("pkg2a"),
version: String::from("0.0.1"),
requires_dist: vec![String::from("pkg1")],
},
);
expected_conda_metadata.insert(
String::from("pkg2b"),
Metadata::new(String::from("pkg2b"), String::from("0.0.1"), vec![]),
Metadata {
name: String::from("pkg2b"),
version: String::from("0.0.1"),
requires_dist: vec![],
},
);
expected_conda_metadata.insert(
String::from("pkg2c"),
Metadata::new(
String::from("pkg2c"),
String::from("0.0.1"),
vec![String::from("pkg2a")],
),
Metadata {
name: String::from("pkg2c"),
version: String::from("0.0.1"),
requires_dist: vec![String::from("pkg2a")],
},
);
expected_conda_metadata.insert(
String::from("pkg3"),
Metadata::new(
String::from("pkg3"),
String::from("0.0.1"),
vec![String::from("pkg2a"), String::from("pkg2b")],
),
Metadata {
name: String::from("pkg3"),
version: String::from("0.0.1"),
requires_dist: vec![String::from("pkg2a"), String::from("pkg2b")],
},
);
// when:
let conda_metadata = get_conda_metadata();
Expand Down

0 comments on commit c468c66

Please sign in to comment.