fix: use path_macro in tests/codegen for cross-platform paths
This commit is contained in:
parent
394f8609a8
commit
64d009615e
25 changed files with 150 additions and 151 deletions
24
Cargo.toml
24
Cargo.toml
|
|
@ -30,25 +30,35 @@ fancy-regex = "0.10.0"
|
|||
thiserror = "1.0.36"
|
||||
url = "2.2.2"
|
||||
log = "0.4.17"
|
||||
reqwest = {version = "0.11.11", default-features = false, features = ["json", "gzip", "brotli", "stream"]}
|
||||
tokio = {version = "1.20.0", features = ["macros", "time", "fs", "process"]}
|
||||
reqwest = { version = "0.11.11", default-features = false, features = [
|
||||
"json",
|
||||
"gzip",
|
||||
"brotli",
|
||||
"stream",
|
||||
] }
|
||||
tokio = { version = "1.20.0", features = ["macros", "time", "fs", "process"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0.82"
|
||||
serde_with = {version = "2.0.0", features = ["json"] }
|
||||
serde_with = { version = "2.0.0", features = ["json"] }
|
||||
rand = "0.8.5"
|
||||
time = {version = "0.3.15", features = ["macros", "serde", "serde-well-known"]}
|
||||
time = { version = "0.3.15", features = [
|
||||
"macros",
|
||||
"serde",
|
||||
"serde-well-known",
|
||||
] }
|
||||
futures = "0.3.21"
|
||||
indicatif = "0.17.0"
|
||||
filenamify = "0.1.0"
|
||||
ress = "0.11.4"
|
||||
phf = "0.11.1"
|
||||
phf = "0.11.1"
|
||||
base64 = "0.13.0"
|
||||
quick-xml = {version = "0.26.0", features = ["serialize"], optional = true}
|
||||
quick-xml = { version = "0.26.0", features = ["serialize"], optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.10.0"
|
||||
test-log = "0.2.11"
|
||||
rstest = "0.16.0"
|
||||
temp_testdir = "0.2.3"
|
||||
insta = {version = "1.17.1", features = ["ron", "redactions"]}
|
||||
insta = { version = "1.17.1", features = ["ron", "redactions"] }
|
||||
path_macro = "1.0.0"
|
||||
velcro = "0.5.3"
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
rustypipe = {path = "../"}
|
||||
rustypipe = { path = "../" }
|
||||
reqwest = "0.11.11"
|
||||
tokio = {version = "1.20.0", features = ["macros", "rt-multi-thread"]}
|
||||
tokio = { version = "1.20.0", features = ["macros", "rt-multi-thread"] }
|
||||
futures = "0.3.21"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0.82"
|
||||
|
|
@ -20,3 +20,4 @@ once_cell = "1.12.0"
|
|||
fancy-regex = "0.10.0"
|
||||
indicatif = "0.17.0"
|
||||
num_enum = "0.5.7"
|
||||
path_macro = "1.0.0"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::{collections::BTreeMap, fs::File, io::BufReader, path::Path};
|
||||
|
||||
use futures::stream::{self, StreamExt};
|
||||
use path_macro::path;
|
||||
use rustypipe::{
|
||||
client::{ClientType, RustyPipe, RustyPipeQuery, YTContext},
|
||||
model::AlbumType,
|
||||
|
|
@ -11,8 +12,7 @@ use serde::{Deserialize, Serialize};
|
|||
use crate::util::{self, TextRuns};
|
||||
|
||||
pub async fn collect_album_types(project_root: &Path, concurrency: usize) {
|
||||
let mut json_path = project_root.to_path_buf();
|
||||
json_path.push("testfiles/dict/album_type_samples.json");
|
||||
let json_path = path!(project_root / "testfiles" / "dict" / "album_type_samples.json");
|
||||
|
||||
let album_types = [
|
||||
(AlbumType::Album, "MPREb_nlBWQROfvjo"),
|
||||
|
|
@ -49,8 +49,7 @@ pub async fn collect_album_types(project_root: &Path, concurrency: usize) {
|
|||
}
|
||||
|
||||
pub fn write_samples_to_dict(project_root: &Path) {
|
||||
let mut json_path = project_root.to_path_buf();
|
||||
json_path.push("testfiles/dict/album_type_samples.json");
|
||||
let json_path = path!(project_root / "testfiles" / "dict" / "album_type_samples.json");
|
||||
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
let collected: BTreeMap<Language, BTreeMap<AlbumType, String>> =
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ use anyhow::{Context, Result};
|
|||
use fancy_regex::Regex;
|
||||
use futures::{stream, StreamExt};
|
||||
use once_cell::sync::Lazy;
|
||||
use path_macro::path;
|
||||
use reqwest::{header, Client};
|
||||
use rustypipe::param::{locale::LANGUAGES, Language};
|
||||
use serde::Deserialize;
|
||||
|
|
@ -30,11 +31,9 @@ type CollectedNumbers = BTreeMap<Language, BTreeMap<u8, (String, u64)>>;
|
|||
/// outputs view counts both in approximated and exact format, so we can use
|
||||
/// the exact counts to figure out the tokens.
|
||||
pub async fn collect_large_numbers(project_root: &Path, concurrency: usize) {
|
||||
let mut json_path = project_root.to_path_buf();
|
||||
json_path.push("testfiles/dict/large_number_samples.json");
|
||||
|
||||
let mut json_path_all = project_root.to_path_buf();
|
||||
json_path_all.push("testfiles/dict/large_number_samples_all.json");
|
||||
let json_path = path!(project_root / "testfiles" / "dict" / "large_number_samples.json");
|
||||
let json_path_all =
|
||||
path!(project_root / "testfiles" / "dict" / "large_number_samples_all.json");
|
||||
|
||||
let channels = [
|
||||
"UCq-Fj5jknLsUf-MWSy4_brA", // 10e8 (225M)
|
||||
|
|
@ -117,8 +116,7 @@ pub fn write_samples_to_dict(project_root: &Path) {
|
|||
"M": 6
|
||||
*/
|
||||
|
||||
let mut json_path = project_root.to_path_buf();
|
||||
json_path.push("testfiles/dict/large_number_samples.json");
|
||||
let json_path = path!(project_root / "testfiles" / "dict" / "large_number_samples.json");
|
||||
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
let collected_nums: CollectedNumbers =
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use std::{
|
|||
};
|
||||
|
||||
use futures::{stream, StreamExt};
|
||||
use path_macro::path;
|
||||
use rustypipe::{
|
||||
client::RustyPipe,
|
||||
param::{locale::LANGUAGES, Language},
|
||||
|
|
@ -62,8 +63,7 @@ enum DateCase {
|
|||
/// Because the relative dates change with time, the first three playlists
|
||||
/// have to checked and eventually changed before running the program.
|
||||
pub async fn collect_dates(project_root: &Path, concurrency: usize) {
|
||||
let mut json_path = project_root.to_path_buf();
|
||||
json_path.push("testfiles/dict/playlist_samples.json");
|
||||
let json_path = path!(project_root / "testfiles" / "dict" / "playlist_samples.json");
|
||||
|
||||
// These are the sample playlists
|
||||
let cases = [
|
||||
|
|
@ -116,8 +116,7 @@ pub async fn collect_dates(project_root: &Path, concurrency: usize) {
|
|||
/// The ND (no digit) tokens (today, tomorrow) of some languages cannot be
|
||||
/// parsed automatically and require manual work.
|
||||
pub fn write_samples_to_dict(project_root: &Path) {
|
||||
let mut json_path = project_root.to_path_buf();
|
||||
json_path.push("testfiles/dict/playlist_samples.json");
|
||||
let json_path = path!(project_root / "testfiles" / "dict" / "playlist_samples.json");
|
||||
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
let collected_dates: CollectedDates =
|
||||
|
|
|
|||
|
|
@ -1,9 +1,17 @@
|
|||
use std::{collections::BTreeMap, fs::File, io::BufReader, path::Path, str::FromStr};
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
fs::File,
|
||||
io::BufReader,
|
||||
path::{Path, PathBuf},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use path_macro::path;
|
||||
use rustypipe::{model::AlbumType, param::Language};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const DICT_PATH: &str = "testfiles/dict/dictionary.json";
|
||||
static DICT_PATH: Lazy<PathBuf> = Lazy::new(|| path!("testfiles" / "dict" / "dictionary.json"));
|
||||
|
||||
type Dictionary = BTreeMap<Language, DictEntry>;
|
||||
|
||||
|
|
@ -62,15 +70,13 @@ pub struct Text {
|
|||
}
|
||||
|
||||
pub fn read_dict(project_root: &Path) -> Dictionary {
|
||||
let mut json_path = project_root.to_path_buf();
|
||||
json_path.push(DICT_PATH);
|
||||
let json_path = path!(project_root / *DICT_PATH);
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
serde_json::from_reader(BufReader::new(json_file)).unwrap()
|
||||
}
|
||||
|
||||
pub fn write_dict(project_root: &Path, dict: &Dictionary) {
|
||||
let mut json_path = project_root.to_path_buf();
|
||||
json_path.push(DICT_PATH);
|
||||
let json_path = path!(project_root / *DICT_PATH);
|
||||
let json_file = File::create(json_path).unwrap();
|
||||
serde_json::to_writer_pretty(json_file, dict).unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -509,8 +509,9 @@ fn combine_channel_data<T>(channel_data: Channel<()>, content: T) -> Channel<T>
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -532,8 +533,7 @@ mod tests {
|
|||
#[case::shorts("shorts", "UCh8gHdtzO2tXd593_bjErWg")]
|
||||
#[case::livestreams("livestreams", "UC2DjFE7Xf11URZqWBigcVOQ")]
|
||||
fn map_channel_videos(#[case] name: &str, #[case] id: &str) {
|
||||
let filename = format!("testfiles/channel/channel_{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "channel" / format!("channel_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let channel: response::Channel =
|
||||
|
|
@ -560,7 +560,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn map_channel_playlists() {
|
||||
let json_path = Path::new("testfiles/channel/channel_playlists.json");
|
||||
let json_path = path!("testfiles" / "channel" / "channel_playlists.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let channel: response::Channel =
|
||||
|
|
@ -579,7 +579,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn map_channel_info() {
|
||||
let json_path = Path::new("testfiles/channel/channel_info.json");
|
||||
let json_path = path!("testfiles" / "channel" / "channel_info.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let channel: response::Channel =
|
||||
|
|
|
|||
|
|
@ -60,10 +60,11 @@ impl RustyPipeQuery {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use crate::{client::response, model::ChannelRss};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
|
||||
#[rstest]
|
||||
|
|
@ -71,8 +72,7 @@ mod tests {
|
|||
#[case::no_likes("no_likes")]
|
||||
#[case::no_channel_id("no_channel_id")]
|
||||
fn map_channel_rss(#[case] name: &str) {
|
||||
let filename = format!("testfiles/channel_rss/{}.xml", name);
|
||||
let xml_path = Path::new(&filename);
|
||||
let xml_path = path!("testfiles" / "channel_rss" / format!("{}.xml", name));
|
||||
let xml_file = File::open(xml_path).unwrap();
|
||||
|
||||
let feed: response::ChannelRss =
|
||||
|
|
|
|||
|
|
@ -305,12 +305,9 @@ impl MapResponse<Vec<AlbumItem>> for response::MusicArtistAlbums {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{
|
||||
fs::File,
|
||||
io::BufReader,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::param::Language;
|
||||
|
|
@ -324,16 +321,13 @@ mod tests {
|
|||
#[case::no_artist("no_artist", "UCh8gHdtzO2tXd593_bjErWg")]
|
||||
#[case::only_more_singles("only_more_singles", "UC0aXrjVxG5pZr99v77wZdPQ")]
|
||||
fn map_music_artist(#[case] name: &str, #[case] id: &str) {
|
||||
let filename_base = format!("testfiles/music_artist/artist_{}", name);
|
||||
|
||||
let filename = filename_base.clone() + ".json";
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "music_artist" / format!("artist_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let mut album_page_paths = Vec::new();
|
||||
for i in 1..=2 {
|
||||
let filename = format!("{}_{}.json", filename_base, i);
|
||||
let json_path = PathBuf::from(filename);
|
||||
let json_path =
|
||||
path!("testfiles" / "music_artist" / format!("artist_{}_{}.json", name, i));
|
||||
if !json_path.exists() {
|
||||
break;
|
||||
}
|
||||
|
|
@ -373,7 +367,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn map_music_artist_no_cont() {
|
||||
let json_path = Path::new("testfiles/music_artist/artist_default.json");
|
||||
let json_path = path!("testfiles" / "music_artist" / "artist_default.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let artist: response::MusicArtist =
|
||||
|
|
|
|||
|
|
@ -365,8 +365,9 @@ impl MapResponse<MusicRelated> for response::MusicRelated {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
|
||||
use super::*;
|
||||
|
|
@ -376,8 +377,7 @@ mod tests {
|
|||
#[case::mv("mv", "ZeerrnuLi5E")]
|
||||
#[case::track("track", "7nigXQS1Xb0")]
|
||||
fn map_music_details(#[case] name: &str, #[case] id: &str) {
|
||||
let filename = format!("testfiles/music_details/details_{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "music_details" / format!("details_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let details: response::MusicDetails =
|
||||
|
|
@ -397,8 +397,7 @@ mod tests {
|
|||
#[case::mv("mv", "RDAMVMZeerrnuLi5E")]
|
||||
#[case::track("track", "RDAMVM7nigXQS1Xb0")]
|
||||
fn map_music_radio(#[case] name: &str, #[case] id: &str) {
|
||||
let filename = format!("testfiles/music_details/radio_{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "music_details" / format!("radio_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let radio: response::MusicDetails =
|
||||
|
|
@ -416,7 +415,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn map_lyrics() {
|
||||
let json_path = Path::new("testfiles/music_details/lyrics.json");
|
||||
let json_path = path!("testfiles" / "music_details" / "lyrics.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let lyrics: response::MusicLyrics =
|
||||
|
|
@ -433,7 +432,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn map_related() {
|
||||
let json_path = Path::new("testfiles/music_details/related.json");
|
||||
let json_path = path!("testfiles" / "music_details" / "related.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let lyrics: response::MusicRelated =
|
||||
|
|
|
|||
|
|
@ -77,8 +77,9 @@ impl<T: FromYtItem> MapResponse<Vec<T>> for response::MusicNew {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
|
||||
use super::*;
|
||||
|
|
@ -87,8 +88,7 @@ mod tests {
|
|||
#[rstest]
|
||||
#[case::default("default")]
|
||||
fn map_music_new_albums(#[case] name: &str) {
|
||||
let filename = format!("testfiles/music_new/albums_{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "music_new" / format!("albums_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let new_albums: response::MusicNew =
|
||||
|
|
@ -107,8 +107,7 @@ mod tests {
|
|||
#[rstest]
|
||||
#[case::default("default")]
|
||||
fn map_music_new_videos(#[case] name: &str) {
|
||||
let filename = format!("testfiles/music_new/videos_{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "music_new" / format!("videos_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let new_albums: response::MusicNew =
|
||||
|
|
|
|||
|
|
@ -257,8 +257,9 @@ impl MapResponse<MusicAlbum> for response::MusicPlaylist {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
|
||||
use super::*;
|
||||
|
|
@ -269,8 +270,7 @@ mod tests {
|
|||
#[case::long("long", "PL5dDx681T4bR7ZF1IuWzOv1omlRbE7PiJ")]
|
||||
#[case::nomusic("nomusic", "PL1J-6JOckZtE_P9Xx8D3b2O6w0idhuKBe")]
|
||||
fn map_music_playlist(#[case] name: &str, #[case] id: &str) {
|
||||
let filename = format!("testfiles/music_playlist/playlist_{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "music_playlist" / format!("playlist_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let playlist: response::MusicPlaylist =
|
||||
|
|
@ -294,8 +294,7 @@ mod tests {
|
|||
#[case::single("single", "MPREb_bHfHGoy7vuv")]
|
||||
#[case::description("description", "MPREb_PiyfuVl6aYd")]
|
||||
fn map_music_album(#[case] name: &str, #[case] id: &str) {
|
||||
let filename = format!("testfiles/music_playlist/album_{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "music_playlist" / format!("album_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let playlist: response::MusicPlaylist =
|
||||
|
|
|
|||
|
|
@ -354,7 +354,10 @@ impl MapResponse<Vec<String>> for response::MusicSearchSuggestion {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::{
|
||||
client::{response, MapResponse},
|
||||
|
|
@ -366,15 +369,12 @@ mod tests {
|
|||
serializer::MapResult,
|
||||
};
|
||||
|
||||
use rstest::rstest;
|
||||
|
||||
#[rstest]
|
||||
#[case::default("default")]
|
||||
#[case::typo("typo")]
|
||||
#[case::radio("radio")]
|
||||
fn map_music_search_main(#[case] name: &str) {
|
||||
let filename = format!("testfiles/music_search/main_{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "music_search" / format!("main_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let search: response::MusicSearch =
|
||||
|
|
@ -397,8 +397,7 @@ mod tests {
|
|||
#[case::videos("videos")]
|
||||
#[case::no_artist_link("no_artist_link")]
|
||||
fn map_music_search_tracks(#[case] name: &str) {
|
||||
let filename = format!("testfiles/music_search/tracks_{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "music_search" / format!("tracks_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let search: response::MusicSearch =
|
||||
|
|
@ -417,8 +416,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn map_music_search_albums() {
|
||||
let filename = "testfiles/music_search/albums.json";
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "music_search" / "albums.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let search: response::MusicSearch =
|
||||
|
|
@ -437,8 +435,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn map_music_search_artists() {
|
||||
let filename = "testfiles/music_search/artists.json";
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "music_search" / "artists.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let search: response::MusicSearch =
|
||||
|
|
@ -459,8 +456,7 @@ mod tests {
|
|||
#[case::ytm("ytm")]
|
||||
#[case::community("community")]
|
||||
fn map_music_search_playlists(#[case] name: &str) {
|
||||
let filename = format!("testfiles/music_search/playlists_{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "music_search" / format!("playlists_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let search: response::MusicSearch =
|
||||
|
|
@ -481,8 +477,7 @@ mod tests {
|
|||
#[case::default("default")]
|
||||
#[case::empty("empty")]
|
||||
fn map_music_search_suggestion(#[case] name: &str) {
|
||||
let filename = format!("testfiles/music_search/suggestion_{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "music_search" / format!("suggestion_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let suggestion: response::MusicSearchSuggestion =
|
||||
|
|
|
|||
|
|
@ -307,8 +307,9 @@ paginator!(PlaylistVideo);
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader, path::PathBuf};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
|
||||
use super::*;
|
||||
|
|
@ -316,12 +317,11 @@ mod tests {
|
|||
use crate::param::Language;
|
||||
|
||||
#[rstest]
|
||||
#[case("search", "search/cont")]
|
||||
#[case("startpage", "trends/startpage_cont")]
|
||||
#[case("recommendations", "video_details/recommendations")]
|
||||
fn map_continuation_items(#[case] name: &str, #[case] path: &str) {
|
||||
let filename = format!("testfiles/{}.json", path);
|
||||
let json_path = Path::new(&filename);
|
||||
#[case("search", path!("search" / "cont.json"))]
|
||||
#[case("startpage", path!("trends" / "startpage_cont.json"))]
|
||||
#[case("recommendations", path!("video_details" / "recommendations.json"))]
|
||||
fn map_continuation_items(#[case] name: &str, #[case] path: PathBuf) {
|
||||
let json_path = path!("testfiles" / path);
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let items: response::Continuation =
|
||||
|
|
@ -340,10 +340,9 @@ mod tests {
|
|||
}
|
||||
|
||||
#[rstest]
|
||||
#[case("channel_playlists", "channel/channel_playlists_cont")]
|
||||
fn map_continuation_playlists(#[case] name: &str, #[case] path: &str) {
|
||||
let filename = format!("testfiles/{}.json", path);
|
||||
let json_path = Path::new(&filename);
|
||||
#[case("channel_playlists", path!("channel" / "channel_playlists_cont.json"))]
|
||||
fn map_continuation_playlists(#[case] name: &str, #[case] path: PathBuf) {
|
||||
let json_path = path!("testfiles" / path);
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let items: response::Continuation =
|
||||
|
|
@ -362,12 +361,11 @@ mod tests {
|
|||
}
|
||||
|
||||
#[rstest]
|
||||
#[case("playlist_tracks", "music_playlist/playlist_cont")]
|
||||
#[case("search_tracks", "music_search/tracks_cont")]
|
||||
#[case("radio_tracks", "music_details/radio_cont")]
|
||||
fn map_continuation_tracks(#[case] name: &str, #[case] path: &str) {
|
||||
let filename = format!("testfiles/{}.json", path);
|
||||
let json_path = Path::new(&filename);
|
||||
#[case("playlist_tracks", path!("music_playlist" / "playlist_cont.json"))]
|
||||
#[case("search_tracks", path!("music_search" / "tracks_cont.json"))]
|
||||
#[case("radio_tracks", path!("music_details" / "radio_cont.json"))]
|
||||
fn map_continuation_tracks(#[case] name: &str, #[case] path: PathBuf) {
|
||||
let json_path = path!("testfiles" / path);
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let items: response::MusicContinuation =
|
||||
|
|
@ -386,10 +384,9 @@ mod tests {
|
|||
}
|
||||
|
||||
#[rstest]
|
||||
#[case("playlist_related", "music_playlist/playlist_related")]
|
||||
fn map_continuation_music_playlists(#[case] name: &str, #[case] path: &str) {
|
||||
let filename = format!("testfiles/{}.json", path);
|
||||
let json_path = Path::new(&filename);
|
||||
#[case("playlist_related", path!("music_playlist" / "playlist_related.json"))]
|
||||
fn map_continuation_music_playlists(#[case] name: &str, #[case] path: PathBuf) {
|
||||
let json_path = path!("testfiles" / path);
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let items: response::MusicContinuation =
|
||||
|
|
|
|||
|
|
@ -611,12 +611,13 @@ fn get_audio_codec(codecs: Vec<&str>) -> AudioCodec {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use crate::deobfuscate::DeobfData;
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
|
||||
use super::*;
|
||||
use rstest::rstest;
|
||||
use crate::deobfuscate::DeobfData;
|
||||
|
||||
static DEOBFUSCATOR: Lazy<Deobfuscator> = Lazy::new(|| {
|
||||
Deobfuscator::from(DeobfData {
|
||||
|
|
@ -634,8 +635,7 @@ mod tests {
|
|||
#[case::android("android")]
|
||||
#[case::ios("ios")]
|
||||
fn map_player_data(#[case] name: &str) {
|
||||
let filename = format!("testfiles/player/{}_video.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "player" / format!("{}_video.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let resp: response::Player = serde_json::from_reader(BufReader::new(json_file)).unwrap();
|
||||
|
|
|
|||
|
|
@ -227,8 +227,9 @@ fn map_playlist_items(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
|
||||
use super::*;
|
||||
|
|
@ -238,8 +239,7 @@ mod tests {
|
|||
#[case::long("long", "PL5dDx681T4bR7ZF1IuWzOv1omlRbE7PiJ")]
|
||||
#[case::nomusic("nomusic", "PL1J-6JOckZtE_P9Xx8D3b2O6w0idhuKBe")]
|
||||
fn map_playlist_data(#[case] name: &str, #[case] id: &str) {
|
||||
let filename = format!("testfiles/playlist/playlist_{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "playlist" / format!("playlist_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let playlist: response::Playlist =
|
||||
|
|
@ -258,7 +258,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn map_playlist_cont() {
|
||||
let json_path = Path::new("testfiles/playlist/playlist_cont.json");
|
||||
let json_path = path!("testfiles" / "playlist" / "playlist_cont.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let playlist: response::PlaylistCont =
|
||||
|
|
|
|||
|
|
@ -935,13 +935,15 @@ pub(crate) fn map_queue_item(item: QueueMusicItem, lang: Language) -> TrackItem
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{collections::BTreeMap, fs::File, io::BufReader, path::Path};
|
||||
use std::{collections::BTreeMap, fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn map_album_type_samples() {
|
||||
let json_path = Path::new("testfiles/dict/album_type_samples.json");
|
||||
let json_path = path!("testfiles" / "dict" / "album_type_samples.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
let atype_samples: BTreeMap<Language, BTreeMap<AlbumType, String>> =
|
||||
serde_json::from_reader(BufReader::new(json_file)).unwrap();
|
||||
|
|
|
|||
|
|
@ -124,7 +124,10 @@ impl MapResponse<SearchResult> for response::Search {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::{
|
||||
client::{response, MapResponse},
|
||||
|
|
@ -133,16 +136,13 @@ mod tests {
|
|||
serializer::MapResult,
|
||||
};
|
||||
|
||||
use rstest::rstest;
|
||||
|
||||
#[rstest]
|
||||
#[case::default("default")]
|
||||
#[case::playlists("playlists")]
|
||||
#[case::empty("empty")]
|
||||
#[case::ab3_channel_handles("20221121_AB3_channel_handles")]
|
||||
fn t_map_search(#[case] name: &str) {
|
||||
let filename = format!("testfiles/search/{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "search" / format!("{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let search: response::Search = serde_json::from_reader(BufReader::new(json_file)).unwrap();
|
||||
|
|
|
|||
|
|
@ -118,7 +118,9 @@ fn map_startpage_videos(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
|
||||
use crate::{
|
||||
client::{response, MapResponse},
|
||||
|
|
@ -129,8 +131,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn map_startpage() {
|
||||
let filename = "testfiles/trends/startpage.json";
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "trends" / "startpage.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let startpage: response::Startpage =
|
||||
|
|
@ -151,8 +152,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn map_trending() {
|
||||
let filename = "testfiles/trends/trending.json";
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "trends" / "trending.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let startpage: response::Trending =
|
||||
|
|
|
|||
|
|
@ -526,8 +526,9 @@ fn map_comment(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -546,8 +547,8 @@ mod tests {
|
|||
#[case::new_cont("20221011_new_continuation", "ZeerrnuLi5E")]
|
||||
#[case::no_recommends("20221011_rec_isr", "nFDBxBUfE74")]
|
||||
fn map_video_details(#[case] name: &str, #[case] id: &str) {
|
||||
let filename = format!("testfiles/video_details/video_details_{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path =
|
||||
path!("testfiles" / "video_details" / format!("video_details_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let details: response::VideoDetails =
|
||||
|
|
@ -567,8 +568,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn map_video_details_not_found() {
|
||||
let filename = "testfiles/video_details/video_details_not_found.json";
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "video_details" / "video_details_not_found.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let details: response::VideoDetails =
|
||||
|
|
@ -584,8 +584,7 @@ mod tests {
|
|||
#[case::top("top")]
|
||||
#[case::latest("latest")]
|
||||
fn map_comments(#[case] name: &str) {
|
||||
let filename = format!("testfiles/video_details/comments_{}.json", name);
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "video_details" / format!("comments_{}.json", name));
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
let comments: response::VideoComments =
|
||||
|
|
|
|||
|
|
@ -314,13 +314,12 @@ fn get_sts(player_js: &str) -> Result<String> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::Path;
|
||||
|
||||
use super::*;
|
||||
use path_macro::path;
|
||||
use test_log::test;
|
||||
|
||||
static TEST_JS: Lazy<String> = Lazy::new(|| {
|
||||
let js_path = Path::new("testfiles/deobf/dummy_player.js");
|
||||
let js_path = path!("testfiles" / "deobf" / "dummy_player.js");
|
||||
std::fs::read_to_string(js_path).unwrap()
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -318,22 +318,23 @@ impl VideoPlayer {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use super::*;
|
||||
use once_cell::sync::Lazy;
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
use velcro::hash_set;
|
||||
|
||||
static PLAYER_ML: Lazy<VideoPlayer> = Lazy::new(|| {
|
||||
let json_path = Path::new("testfiles/player_model/multilanguage.json");
|
||||
let json_path = path!("testfiles" / "player_model" / "multilanguage.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
serde_json::from_reader(BufReader::new(json_file)).unwrap()
|
||||
});
|
||||
|
||||
static PLAYER_HDR: Lazy<VideoPlayer> = Lazy::new(|| {
|
||||
let json_path = Path::new("testfiles/player_model/hdr.json");
|
||||
let json_path = path!("testfiles" / "player_model" / "hdr.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
|
||||
serde_json::from_reader(BufReader::new(json_file)).unwrap()
|
||||
|
|
|
|||
|
|
@ -469,14 +469,15 @@ impl<'de> DeserializeAs<'de, String> for AccessibilityText {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
|
||||
use super::*;
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
use serde::Deserialize;
|
||||
use serde_with::serde_as;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[rstest]
|
||||
#[case(
|
||||
r#"{
|
||||
|
|
@ -783,8 +784,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn t_attributed_description() {
|
||||
let filename = format!("testfiles/text/attributed_description.json");
|
||||
let json_path = Path::new(&filename);
|
||||
let json_path = path!("testfiles" / "text" / "attributed_description.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
let res: SAttributed = serde_json::from_reader(BufReader::new(json_file)).unwrap();
|
||||
insta::assert_debug_snapshot!(res);
|
||||
|
|
|
|||
|
|
@ -285,8 +285,9 @@ pub(crate) fn parse_textual_date_or_warn(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{collections::BTreeMap, fs::File, io::BufReader, path::Path};
|
||||
use std::{collections::BTreeMap, fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
use time::macros::{date, datetime};
|
||||
|
||||
|
|
@ -308,7 +309,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn t_testfile() {
|
||||
let json_path = Path::new("testfiles/dict/timeago_samples.json");
|
||||
let json_path = path!("testfiles" / "dict" / "timeago_samples.json");
|
||||
|
||||
let expect = [
|
||||
TimeAgo {
|
||||
|
|
@ -491,7 +492,7 @@ mod tests {
|
|||
cases: BTreeMap<String, u8>,
|
||||
}
|
||||
|
||||
let json_path = Path::new("testfiles/dict/timeago_table.json");
|
||||
let json_path = path!("testfiles" / "dict" / "timeago_table.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
let timeago_table: TimeagoTable =
|
||||
serde_json::from_reader(BufReader::new(json_file)).unwrap();
|
||||
|
|
@ -538,7 +539,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn t_parse_date_samples() {
|
||||
let json_path = Path::new("testfiles/dict/playlist_samples.json");
|
||||
let json_path = path!("testfiles" / "dict" / "playlist_samples.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
let date_samples: BTreeMap<Language, BTreeMap<String, String>> =
|
||||
serde_json::from_reader(BufReader::new(json_file)).unwrap();
|
||||
|
|
|
|||
|
|
@ -351,12 +351,13 @@ pub fn video_id_from_thumbnail_url(url: &str) -> Option<String> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use path_macro::path;
|
||||
use rstest::rstest;
|
||||
|
||||
use super::*;
|
||||
|
||||
use rstest::rstest;
|
||||
|
||||
#[rstest]
|
||||
#[case("1.000", 1000)]
|
||||
#[case("4 Hello World 2", 42)]
|
||||
|
|
@ -439,7 +440,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn t_parse_large_numstr_samples() {
|
||||
let json_path = Path::new("testfiles/dict/large_number_samples.json");
|
||||
let json_path = path!("testfiles" / "dict" / "large_number_samples.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
let number_samples: BTreeMap<Language, BTreeMap<u8, (String, u64)>> =
|
||||
serde_json::from_reader(BufReader::new(json_file)).unwrap();
|
||||
|
|
@ -453,7 +454,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn t_parse_large_numstr_samples2() {
|
||||
let json_path = Path::new("testfiles/dict/large_number_samples_all.json");
|
||||
let json_path = path!("testfiles" / "dict" / "large_number_samples_all.json");
|
||||
let json_file = File::open(json_path).unwrap();
|
||||
let number_samples: BTreeMap<Language, BTreeMap<String, u64>> =
|
||||
serde_json::from_reader(BufReader::new(json_file)).unwrap();
|
||||
|
|
|
|||
Reference in a new issue