mirror of
https://github.com/PaiGramTeam/python-genshin-artifact.git
synced 2025-02-02 16:35:26 +00:00
✨ Add tests for name conversion
Co-authored-by: kotoriのねこ <minamiktr@outlook.com>
This commit is contained in:
parent
557b12ad69
commit
9258608173
@ -75,7 +75,6 @@ weapon_name_map: Dict[int, str] = {
|
||||
12502: "WolfsGravestone",
|
||||
12503: "SongOfBrokenPines",
|
||||
12504: "TheUnforged",
|
||||
12505: "PrimordialJadeGreatSword",
|
||||
12510: "RedhornStonethresher",
|
||||
12511: "BeaconOfTheReedSea",
|
||||
13101: "BeginnersProtector",
|
||||
@ -123,7 +122,7 @@ weapon_name_map: Dict[int, str] = {
|
||||
14407: "MappaMare",
|
||||
14408: "BlackcliffAgate",
|
||||
14409: "EyeOfPerception",
|
||||
14410: "WineAndSong",
|
||||
14410: "WindAndSong", # WineAndSong
|
||||
14412: "Frostbearer",
|
||||
14413: "DodocoTales",
|
||||
14414: "HakushinRing",
|
||||
@ -167,7 +166,7 @@ weapon_name_map: Dict[int, str] = {
|
||||
15415: "Predator",
|
||||
15416: "MouunsMoon",
|
||||
15417: "KingsSquire",
|
||||
15418: "EndOfTheLine",
|
||||
15418: "ElegyOfTheEnd", # EndOfTheLine
|
||||
15419: "IbisPiercer",
|
||||
15424: "ScionOfTheBlazingSun",
|
||||
15425: "SongOfStillness",
|
||||
@ -175,7 +174,6 @@ weapon_name_map: Dict[int, str] = {
|
||||
15501: "SkywardHarp",
|
||||
15502: "AmosBow",
|
||||
15503: "ElegyOfTheEnd",
|
||||
15504: "KunwusWyrmbane",
|
||||
15505: "PrimordialJadeVista",
|
||||
15507: "PolarStar",
|
||||
15508: "AquaSimulacra",
|
||||
@ -183,3 +181,10 @@ weapon_name_map: Dict[int, str] = {
|
||||
15511: "HuntersPath",
|
||||
15512: "TheFirstGreatMagic",
|
||||
}
|
||||
|
||||
|
||||
test_weapon_name_map: Dict[int, str] = {
|
||||
12505: "PrimordialJadeGreatSword",
|
||||
15505: "PrimordialJadeVista",
|
||||
15504: "KunwusWyrmbane",
|
||||
}
|
||||
|
@ -127,3 +127,28 @@ impl TryInto<MonaArtifact> for PyArtifact {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use anyhow::Context;
|
||||
|
||||
#[test]
|
||||
fn test_artifact_set_name() -> PyResult<()> {
|
||||
pyo3::prepare_freethreaded_python();
|
||||
Python::with_gil(|py| {
|
||||
let module = PyModule::import(py, "python_genshin_artifact.enka.artifacts")?;
|
||||
let artifacts_name_map = module.getattr("artifacts_name_map")?.downcast::<PyDict>()?;
|
||||
for (_, value) in artifacts_name_map.iter() {
|
||||
let artifacts_name_str = value.extract::<String>()?;
|
||||
let res: Result<ArtifactSetName, anyhow::Error> = depythonize(&value).context(
|
||||
format!("Artifact name '{}' does not exist", artifacts_name_str),
|
||||
);
|
||||
if res.is_err() {
|
||||
println!("{:?}", res.err().map(|e| e.to_string()));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,6 @@ impl TryInto<MonaCharacterInterface> for PyCharacterInterface {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
use mona::attribute::{Attribute, AttributeName, ComplicatedAttributeGraph};
|
||||
use mona::character::Character;
|
||||
@ -195,4 +194,24 @@ mod tests {
|
||||
println!("PyCharacterInterface 测试成功 遥遥领先!");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_character_name() -> PyResult<()> {
|
||||
pyo3::prepare_freethreaded_python();
|
||||
Python::with_gil(|py| {
|
||||
let module = PyModule::import(py, "python_genshin_artifact.enka.characters")?;
|
||||
let characters_map = module.getattr("characters_map")?.downcast::<PyDict>()?;
|
||||
for (_, value) in characters_map.iter() {
|
||||
let character_name_str = value.extract::<String>()?;
|
||||
let res = CharacterName::from_str(&character_name_str).context(format!(
|
||||
"Character name '{}' does not exist",
|
||||
character_name_str
|
||||
));
|
||||
if res.is_err() {
|
||||
println!("{:?}", res.err().map(|e| e.to_string()));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -98,6 +98,7 @@ impl TryInto<MonaWeaponInterface> for PyWeaponInterface {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use anyhow::Context;
|
||||
use mona::attribute::ComplicatedAttributeGraph;
|
||||
use mona::character::{Character, CharacterConfig, CharacterName};
|
||||
use mona::weapon::Weapon;
|
||||
@ -198,4 +199,22 @@ mod tests {
|
||||
println!("PyWeaponInterface 测试成功 遥遥领先!");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_weapon_name() -> PyResult<()> {
|
||||
pyo3::prepare_freethreaded_python();
|
||||
Python::with_gil(|py| {
|
||||
let module = PyModule::import(py, "python_genshin_artifact.enka.weapon")?;
|
||||
let weapon_name_map = module.getattr("weapon_name_map")?.downcast::<PyDict>()?;
|
||||
for (_, value) in weapon_name_map.iter() {
|
||||
let weapon_name_str = value.extract::<String>()?;
|
||||
let res: Result<WeaponName, anyhow::Error> = depythonize(&value)
|
||||
.context(format!("Weapon name '{}' does not exist", weapon_name_str));
|
||||
if res.is_err() {
|
||||
println!("{:?}", res.err().map(|e| e.to_string()));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::applications::output::damage_result::PyDamageResult;
|
||||
use mona::damage::DamageAnalysis as MonaDamageAnalysis;
|
||||
use pyo3::prelude::*;
|
||||
use std::collections::HashMap;
|
||||
use pyo3::types::PyDict;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[pyclass(name = "DamageAnalysis")]
|
||||
#[derive(Clone)]
|
||||
@ -70,15 +70,18 @@ pub struct PyDamageAnalysis {
|
||||
pub aggravate: Option<PyDamageResult>,
|
||||
}
|
||||
|
||||
|
||||
#[pymethods]
|
||||
impl PyDamageAnalysis {
|
||||
|
||||
#[getter]
|
||||
fn __dict__(&self, py: Python) -> PyResult<PyObject> { // skipcq: RS-R1000
|
||||
let dict = PyDict::new(py);
|
||||
|
||||
fn insert_hashmap(dict: &PyDict, py: Python, key: &str, hashmap: &HashMap<String, f64>) -> PyResult<()> {
|
||||
fn insert_hashmap(
|
||||
dict: &PyDict,
|
||||
py: Python,
|
||||
key: &str,
|
||||
hashmap: &HashMap<String, f64>,
|
||||
) -> PyResult<()> {
|
||||
let hashmap_dict = PyDict::new(py);
|
||||
for (k, &v) in hashmap.iter() {
|
||||
hashmap_dict.set_item(k, v)?;
|
||||
@ -129,7 +132,12 @@ impl PyDamageAnalysis {
|
||||
} else {
|
||||
dict.set_item("spread", py.None())?;
|
||||
}
|
||||
if let Some(aggravate) = self.aggravate.as_ref().map(|e| e.__dict__(py)).transpose()? {
|
||||
if let Some(aggravate) = self
|
||||
.aggravate
|
||||
.as_ref()
|
||||
.map(|e| e.__dict__(py))
|
||||
.transpose()?
|
||||
{
|
||||
dict.set_item("aggravate", aggravate)?;
|
||||
} else {
|
||||
dict.set_item("aggravate", py.None())?;
|
||||
|
@ -39,11 +39,7 @@ impl PyDamageResult {
|
||||
pub fn __repr__(&self) -> PyResult<String> {
|
||||
Ok(format!(
|
||||
"DamageResult(critical={}, non_critical={}, expectation={}, is_heal={}, is_shield={})",
|
||||
self.critical,
|
||||
self.non_critical,
|
||||
self.expectation,
|
||||
self.is_heal,
|
||||
self.is_shield
|
||||
self.critical, self.non_critical, self.expectation, self.is_heal, self.is_shield
|
||||
))
|
||||
}
|
||||
|
||||
@ -57,8 +53,6 @@ impl PyDamageResult {
|
||||
dict.set_item("is_shield", self.is_shield)?;
|
||||
Ok(dict.into())
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
impl From<MonaDamageResult> for PyDamageResult {
|
||||
|
Loading…
Reference in New Issue
Block a user