fix: use fixed testfiles location

This commit is contained in:
ThetaDev 2023-03-25 23:18:49 +01:00
parent 3a2e4c8abe
commit 7bcff13eb8
20 changed files with 80 additions and 62 deletions

View file

@ -496,6 +496,7 @@ mod tests {
model::{paginator::Paginator, Channel, ChannelInfo, PlaylistItem, VideoItem},
param::Language,
serializer::MapResult,
util::tests::TESTFILES,
};
#[rstest]
@ -510,7 +511,7 @@ mod tests {
#[case::shorts("shorts", "UCh8gHdtzO2tXd593_bjErWg")]
#[case::livestreams("livestreams", "UC2DjFE7Xf11URZqWBigcVOQ")]
fn map_channel_videos(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "channel" / format!("channel_{name}.json"));
let json_path = path!(*TESTFILES / "channel" / format!("channel_{name}.json"));
let json_file = File::open(json_path).unwrap();
let channel: response::Channel =
@ -535,9 +536,9 @@ mod tests {
}
}
#[test]
#[rstest]
fn map_channel_playlists() {
let json_path = path!("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 =
@ -554,9 +555,9 @@ mod tests {
insta::assert_ron_snapshot!("map_channel_playlists", map_res.c);
}
#[test]
#[rstest]
fn map_channel_info() {
let json_path = path!("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 =

View file

@ -68,7 +68,7 @@ impl RustyPipeQuery {
mod tests {
use std::{fs::File, io::BufReader};
use crate::{client::response, model::ChannelRss};
use crate::{client::response, model::ChannelRss, util::tests::TESTFILES};
use path_macro::path;
use rstest::rstest;
@ -78,7 +78,7 @@ mod tests {
#[case::no_likes("no_likes")]
#[case::no_channel_id("no_channel_id")]
fn map_channel_rss(#[case] name: &str) {
let xml_path = path!("testfiles" / "channel_rss" / format!("{}.xml", name));
let xml_path = path!(*TESTFILES / "channel_rss" / format!("{}.xml", name));
let xml_file = File::open(xml_path).unwrap();
let feed: response::ChannelRss =

View file

@ -367,7 +367,7 @@ mod tests {
use path_macro::path;
use rstest::rstest;
use crate::param::Language;
use crate::{param::Language, util::tests::TESTFILES};
use super::*;
@ -378,12 +378,12 @@ 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 json_path = path!("testfiles" / "music_artist" / format!("artist_{name}.json"));
let json_path = path!(*TESTFILES / "music_artist" / format!("artist_{name}.json"));
let json_file = File::open(json_path).unwrap();
let mut album_page_paths = Vec::new();
for i in 1..=2 {
let json_path = path!("testfiles" / "music_artist" / format!("artist_{name}_{i}.json"));
let json_path = path!(*TESTFILES / "music_artist" / format!("artist_{name}_{i}.json"));
if !json_path.exists() {
break;
}
@ -423,7 +423,7 @@ mod tests {
#[test]
fn map_music_artist_no_cont() {
let json_path = path!("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 =
@ -442,7 +442,7 @@ mod tests {
#[test]
fn map_music_artist_secondary_channel() {
let json_path = path!("testfiles" / "music_artist" / "artist_secondary_channel.json");
let json_path = path!(*TESTFILES / "music_artist" / "artist_secondary_channel.json");
let json_file = File::open(json_path).unwrap();
let artist: response::MusicArtist =

View file

@ -395,13 +395,13 @@ mod tests {
use rstest::rstest;
use super::*;
use crate::{model, param::Language};
use crate::{model, param::Language, util::tests::TESTFILES};
#[rstest]
#[case::mv("mv", "ZeerrnuLi5E")]
#[case::track("track", "7nigXQS1Xb0")]
fn map_music_details(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "music_details" / format!("details_{name}.json"));
let json_path = path!(*TESTFILES / "music_details" / format!("details_{name}.json"));
let json_file = File::open(json_path).unwrap();
let details: response::MusicDetails =
@ -421,7 +421,7 @@ mod tests {
#[case::mv("mv", "RDAMVMZeerrnuLi5E")]
#[case::track("track", "RDAMVM7nigXQS1Xb0")]
fn map_music_radio(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "music_details" / format!("radio_{name}.json"));
let json_path = path!(*TESTFILES / "music_details" / format!("radio_{name}.json"));
let json_file = File::open(json_path).unwrap();
let radio: response::MusicDetails =
@ -439,7 +439,7 @@ mod tests {
#[test]
fn map_lyrics() {
let json_path = path!("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 =
@ -456,7 +456,7 @@ mod tests {
#[test]
fn map_related() {
let json_path = path!("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 =

View file

@ -202,11 +202,11 @@ mod tests {
use rstest::rstest;
use super::*;
use crate::{model, param::Language};
use crate::{model, param::Language, util::tests::TESTFILES};
#[test]
fn map_music_genres() {
let json_path = path!("testfiles" / "music_genres" / "genres.json");
let json_path = path!(*TESTFILES / "music_genres" / "genres.json");
let json_file = File::open(json_path).unwrap();
let playlist: response::MusicGenres =
@ -226,7 +226,7 @@ mod tests {
#[case::default("default", "ggMPOg1uX1lMbVZmbzl6NlJ3")]
#[case::mood("mood", "ggMPOg1uX1JOQWZFeDByc2Jm")]
fn map_music_genre(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "music_genres" / format!("genre_{name}.json"));
let json_path = path!(*TESTFILES / "music_genres" / format!("genre_{name}.json"));
let json_file = File::open(json_path).unwrap();
let playlist: response::MusicGenre =

View file

@ -85,12 +85,12 @@ mod tests {
use rstest::rstest;
use super::*;
use crate::{param::Language, serializer::MapResult};
use crate::{param::Language, serializer::MapResult, util::tests::TESTFILES};
#[rstest]
#[case::default("default")]
fn map_music_new_albums(#[case] name: &str) {
let json_path = path!("testfiles" / "music_new" / format!("albums_{name}.json"));
let json_path = path!(*TESTFILES / "music_new" / format!("albums_{name}.json"));
let json_file = File::open(json_path).unwrap();
let new_albums: response::MusicNew =
@ -109,7 +109,7 @@ mod tests {
#[rstest]
#[case::default("default")]
fn map_music_new_videos(#[case] name: &str) {
let json_path = path!("testfiles" / "music_new" / format!("videos_{name}.json"));
let json_path = path!(*TESTFILES / "music_new" / format!("videos_{name}.json"));
let json_file = File::open(json_path).unwrap();
let new_albums: response::MusicNew =

View file

@ -393,14 +393,14 @@ mod tests {
use rstest::rstest;
use super::*;
use crate::{model, param::Language};
use crate::{model, param::Language, util::tests::TESTFILES};
#[rstest]
#[case::short("short", "RDCLAK5uy_kFQXdnqMaQCVx2wpUM4ZfbsGCDibZtkJk")]
#[case::long("long", "PL5dDx681T4bR7ZF1IuWzOv1omlRbE7PiJ")]
#[case::nomusic("nomusic", "PL1J-6JOckZtE_P9Xx8D3b2O6w0idhuKBe")]
fn map_music_playlist(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "music_playlist" / format!("playlist_{name}.json"));
let json_path = path!(*TESTFILES / "music_playlist" / format!("playlist_{name}.json"));
let json_file = File::open(json_path).unwrap();
let playlist: response::MusicPlaylist =
@ -425,7 +425,7 @@ mod tests {
#[case::description("description", "MPREb_PiyfuVl6aYd")]
#[case::unavailable("unavailable", "MPREb_AzuWg8qAVVl")]
fn map_music_album(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "music_playlist" / format!("album_{name}.json"));
let json_path = path!(*TESTFILES / "music_playlist" / format!("album_{name}.json"));
let json_file = File::open(json_path).unwrap();
let playlist: response::MusicPlaylist =

View file

@ -387,6 +387,7 @@ mod tests {
},
param::Language,
serializer::MapResult,
util::tests::TESTFILES,
};
#[rstest]
@ -394,7 +395,7 @@ mod tests {
#[case::typo("typo")]
#[case::radio("radio")]
fn map_music_search_main(#[case] name: &str) {
let json_path = path!("testfiles" / "music_search" / format!("main_{name}.json"));
let json_path = path!(*TESTFILES / "music_search" / format!("main_{name}.json"));
let json_file = File::open(json_path).unwrap();
let search: response::MusicSearch =
@ -417,7 +418,7 @@ mod tests {
#[case::videos("videos")]
#[case::no_artist_link("no_artist_link")]
fn map_music_search_tracks(#[case] name: &str) {
let json_path = path!("testfiles" / "music_search" / format!("tracks_{name}.json"));
let json_path = path!(*TESTFILES / "music_search" / format!("tracks_{name}.json"));
let json_file = File::open(json_path).unwrap();
let search: response::MusicSearch =
@ -436,7 +437,7 @@ mod tests {
#[test]
fn map_music_search_albums() {
let json_path = path!("testfiles" / "music_search" / "albums.json");
let json_path = path!(*TESTFILES / "music_search" / "albums.json");
let json_file = File::open(json_path).unwrap();
let search: response::MusicSearch =
@ -455,7 +456,7 @@ mod tests {
#[test]
fn map_music_search_artists() {
let json_path = path!("testfiles" / "music_search" / "artists.json");
let json_path = path!(*TESTFILES / "music_search" / "artists.json");
let json_file = File::open(json_path).unwrap();
let search: response::MusicSearch =
@ -476,7 +477,7 @@ mod tests {
#[case::ytm("ytm")]
#[case::community("community")]
fn map_music_search_playlists(#[case] name: &str) {
let json_path = path!("testfiles" / "music_search" / format!("playlists_{name}.json"));
let json_path = path!(*TESTFILES / "music_search" / format!("playlists_{name}.json"));
let json_file = File::open(json_path).unwrap();
let search: response::MusicSearch =
@ -497,7 +498,7 @@ mod tests {
#[case::default("default")]
#[case::empty("empty")]
fn map_music_search_suggestion(#[case] name: &str) {
let json_path = path!("testfiles" / "music_search" / format!("suggestion_{name}.json"));
let json_path = path!(*TESTFILES / "music_search" / format!("suggestion_{name}.json"));
let json_file = File::open(json_path).unwrap();
let suggestion: response::MusicSearchSuggestion =

View file

@ -344,15 +344,18 @@ mod tests {
use rstest::rstest;
use super::*;
use crate::model::{MusicPlaylistItem, PlaylistItem, TrackItem};
use crate::param::Language;
use crate::{
model::{MusicPlaylistItem, PlaylistItem, TrackItem},
param::Language,
util::tests::TESTFILES,
};
#[rstest]
#[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_path = path!(*TESTFILES / path);
let json_file = File::open(json_path).unwrap();
let items: response::Continuation =
@ -373,7 +376,7 @@ mod tests {
#[rstest]
#[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_path = path!(*TESTFILES / path);
let json_file = File::open(json_path).unwrap();
let items: response::Continuation =
@ -396,7 +399,7 @@ mod tests {
#[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_path = path!(*TESTFILES / path);
let json_file = File::open(json_path).unwrap();
let items: response::MusicContinuation =
@ -417,7 +420,7 @@ mod tests {
#[rstest]
#[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_path = path!(*TESTFILES / path);
let json_file = File::open(json_path).unwrap();
let items: response::MusicContinuation =

View file

@ -622,7 +622,7 @@ mod tests {
use rstest::rstest;
use super::*;
use crate::deobfuscate::DeobfData;
use crate::{deobfuscate::DeobfData, util::tests::TESTFILES};
static DEOBF_DATA: Lazy<DeobfData> = Lazy::new(|| {
DeobfData {
@ -640,7 +640,7 @@ mod tests {
#[case::android("android")]
#[case::ios("ios")]
fn map_player_data(#[case] name: &str) {
let json_path = path!("testfiles" / "player" / format!("{name}_video.json"));
let json_path = path!(*TESTFILES / "player" / format!("{name}_video.json"));
let json_file = File::open(json_path).unwrap();
let resp: response::Player = serde_json::from_reader(BufReader::new(json_file)).unwrap();

View file

@ -236,7 +236,7 @@ mod tests {
use path_macro::path;
use rstest::rstest;
use crate::param::Language;
use crate::{param::Language, util::tests::TESTFILES};
use super::*;
@ -245,7 +245,7 @@ mod tests {
#[case::long("long", "PL5dDx681T4bR7ZF1IuWzOv1omlRbE7PiJ")]
#[case::nomusic("nomusic", "PL1J-6JOckZtE_P9Xx8D3b2O6w0idhuKBe")]
fn map_playlist_data(#[case] name: &str, #[case] id: &str) {
let json_path = path!("testfiles" / "playlist" / format!("playlist_{name}.json"));
let json_path = path!(*TESTFILES / "playlist" / format!("playlist_{name}.json"));
let json_file = File::open(json_path).unwrap();
let playlist: response::Playlist =
@ -264,7 +264,7 @@ mod tests {
#[test]
fn map_playlist_cont() {
let json_path = path!("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 =

View file

@ -1064,10 +1064,11 @@ mod tests {
use path_macro::path;
use super::*;
use crate::util::tests::TESTFILES;
#[test]
fn map_album_type_samples() {
let json_path = path!("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();

View file

@ -138,6 +138,7 @@ mod tests {
model::SearchResult,
param::Language,
serializer::MapResult,
util::tests::TESTFILES,
};
#[rstest]
@ -146,7 +147,7 @@ mod tests {
#[case::empty("empty")]
#[case::ab3_channel_handles("20221121_AB3_channel_handles")]
fn t_map_search(#[case] name: &str) {
let json_path = path!("testfiles" / "search" / format!("{name}.json"));
let json_path = path!(*TESTFILES / "search" / format!("{name}.json"));
let json_file = File::open(json_path).unwrap();
let search: response::Search = serde_json::from_reader(BufReader::new(json_file)).unwrap();

View file

@ -129,11 +129,12 @@ mod tests {
model::{paginator::Paginator, VideoItem},
param::Language,
serializer::MapResult,
util::tests::TESTFILES,
};
#[test]
fn map_startpage() {
let json_path = path!("testfiles" / "trends" / "startpage.json");
let json_path = path!(*TESTFILES / "trends" / "startpage.json");
let json_file = File::open(json_path).unwrap();
let startpage: response::Startpage =
@ -154,7 +155,7 @@ mod tests {
#[test]
fn map_trending() {
let json_path = path!("testfiles" / "trends" / "trending.json");
let json_path = path!(*TESTFILES / "trends" / "trending.json");
let json_file = File::open(json_path).unwrap();
let startpage: response::Trending =

View file

@ -543,6 +543,7 @@ mod tests {
use crate::{
client::{response, MapResponse},
param::Language,
util::tests::TESTFILES,
};
#[rstest]
@ -556,7 +557,7 @@ 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 json_path = path!("testfiles" / "video_details" / format!("video_details_{name}.json"));
let json_path = path!(*TESTFILES / "video_details" / format!("video_details_{name}.json"));
let json_file = File::open(json_path).unwrap();
let details: response::VideoDetails =
@ -576,7 +577,7 @@ mod tests {
#[test]
fn map_video_details_not_found() {
let json_path = path!("testfiles" / "video_details" / "video_details_not_found.json");
let json_path = path!(*TESTFILES / "video_details" / "video_details_not_found.json");
let json_file = File::open(json_path).unwrap();
let details: response::VideoDetails =
@ -592,7 +593,7 @@ mod tests {
#[case::top("top")]
#[case::latest("latest")]
fn map_comments(#[case] name: &str) {
let json_path = path!("testfiles" / "video_details" / format!("comments_{name}.json"));
let json_path = path!(*TESTFILES / "video_details" / format!("comments_{name}.json"));
let json_file = File::open(json_path).unwrap();
let comments: response::VideoComments =

View file

@ -288,11 +288,12 @@ fn get_sts(player_js: &str) -> Result<String> {
#[cfg(test)]
mod tests {
use super::*;
use crate::util::tests::TESTFILES;
use path_macro::path;
use rstest::{fixture, rstest};
static TEST_JS: Lazy<String> = Lazy::new(|| {
let js_path = path!("testfiles" / "deobf" / "dummy_player.js");
let js_path = path!(*TESTFILES / "deobf" / "dummy_player.js");
std::fs::read_to_string(js_path).unwrap()
});

View file

@ -330,20 +330,22 @@ impl VideoPlayer {
mod tests {
use std::{fs::File, io::BufReader};
use super::*;
use once_cell::sync::Lazy;
use path_macro::path;
use rstest::rstest;
use super::*;
use crate::util::tests::TESTFILES;
static PLAYER_ML: Lazy<VideoPlayer> = Lazy::new(|| {
let json_path = path!("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!("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()

View file

@ -485,6 +485,7 @@ mod tests {
use serde_with::serde_as;
use super::*;
use crate::util::tests::TESTFILES;
#[rstest]
#[case(
@ -793,7 +794,7 @@ mod tests {
#[test]
fn t_attributed_description() {
let json_path = path!("testfiles" / "text" / "attributed_description.json");
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);

View file

@ -302,6 +302,7 @@ mod tests {
use time::macros::{date, datetime};
use super::*;
use crate::util::tests::TESTFILES;
#[rstest]
#[case(Language::De, "vor 1 Sekunde", Some(TimeAgo { n: 1, unit: TimeUnit::Second }))]
@ -319,7 +320,7 @@ mod tests {
#[test]
fn t_testfile() {
let json_path = path!("testfiles" / "dict" / "timeago_samples.json");
let json_path = path!(*TESTFILES / "dict" / "timeago_samples.json");
let expect = [
TimeAgo {
@ -500,7 +501,7 @@ mod tests {
cases: BTreeMap<String, u8>,
}
let json_path = path!("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();
@ -545,7 +546,7 @@ mod tests {
#[test]
fn t_parse_date_samples() {
let json_path = path!("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();

View file

@ -363,14 +363,18 @@ pub fn b64_decode<T: AsRef<[u8]>>(input: T) -> Result<Vec<u8>, base64::DecodeErr
}
#[cfg(test)]
mod tests {
use std::{fs::File, io::BufReader};
pub(crate) mod tests {
use std::{fs::File, io::BufReader, path::PathBuf};
use path_macro::path;
use rstest::rstest;
use super::*;
/// Get the path of the `testfiles` directory
pub static TESTFILES: Lazy<PathBuf> =
Lazy::new(|| path!(env!("CARGO_MANIFEST_DIR") / "testfiles"));
#[rstest]
#[case("1.000", 1000)]
#[case("4 Hello World 2", 42)]
@ -450,7 +454,7 @@ mod tests {
#[test]
fn t_parse_large_numstr_samples() {
let json_path = path!("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();
@ -464,7 +468,7 @@ mod tests {
#[test]
fn t_parse_large_numstr_samples2() {
let json_path = path!("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();