Skip to content

Commit c5404b4

Browse files
committed
Tests: Stop creating temp files for immutable tests
1 parent c29a463 commit c5404b4

14 files changed

+76
-99
lines changed

tests/taglib/test_aiff.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use lofty::{Accessor, AudioFile, FileType, ParseOptions, Probe};
1+
use crate::util::get_file;
2+
use crate::{assert_delta, temp_file};
23

3-
use lofty::id3::v2::Id3v2Tag;
4-
use lofty::iff::aiff::AiffFile;
54
use std::io::Seek;
65

7-
use crate::util::get_file;
8-
use crate::{assert_delta, temp_file};
6+
use lofty::id3::v2::Id3v2Tag;
7+
use lofty::iff::aiff::AiffFile;
8+
use lofty::{Accessor, AudioFile, FileType, ParseOptions, Probe};
99

1010
#[test]
1111
#[ignore]

tests/taglib/test_ape.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::temp_file;
2+
use crate::util::get_file;
23

3-
use std::fs::File;
44
use std::io::Seek;
55
use std::time::Duration;
66

@@ -9,9 +9,8 @@ use lofty::id3::v1::Id3v1Tag;
99
use lofty::{Accessor, AudioFile, FileType, ItemValue, ParseOptions, Probe, TagExt};
1010

1111
fn test_399(path: &str) {
12-
let mut file = File::open(path).unwrap();
13-
let file = ApeFile::read_from(&mut file, ParseOptions::new()).unwrap();
14-
let properties = file.properties();
12+
let f = get_file::<ApeFile>(path);
13+
let properties = f.properties();
1514

1615
assert_eq!(properties.duration(), Duration::from_millis(3550));
1716
assert_eq!(properties.bitrate(), 192);
@@ -44,9 +43,8 @@ fn test_properties_399_id3v2() {
4443
#[test]
4544
#[ignore]
4645
fn test_properties_396() {
47-
let mut file = File::open("tests/taglib/data/mac-396.ape").unwrap();
48-
let file = ApeFile::read_from(&mut file, ParseOptions::new()).unwrap();
49-
let properties = file.properties();
46+
let f = get_file::<ApeFile>("tests/taglib/data/mac-396.ape");
47+
let properties = f.properties();
5048

5149
assert_eq!(properties.duration(), Duration::from_millis(3685));
5250
assert_eq!(properties.bitrate(), 0);
@@ -61,9 +59,8 @@ fn test_properties_396() {
6159
#[test]
6260
#[ignore]
6361
fn test_properties_390() {
64-
let mut file = File::open("tests/taglib/data/mac-390-hdr.ape").unwrap();
65-
let file = ApeFile::read_from(&mut file, ParseOptions::new()).unwrap();
66-
let properties = file.properties();
62+
let f = get_file::<ApeFile>("tests/taglib/data/mac-390-hdr.ape");
63+
let properties = f.properties();
6764

6865
assert_eq!(properties.duration(), Duration::from_millis(15630));
6966
assert_eq!(properties.bitrate(), 0);

tests/taglib/test_flac.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::temp_file;
2+
use crate::util::get_file;
23

34
use std::io::{Read, Seek, SeekFrom};
45

@@ -11,8 +12,7 @@ use lofty::{
1112

1213
#[test]
1314
fn test_signature() {
14-
let mut file = temp_file!("tests/taglib/data/no-tags.flac");
15-
let f = FlacFile::read_from(&mut file, ParseOptions::new()).unwrap();
15+
let f = get_file::<FlacFile>("tests/taglib/data/no-tags.flac");
1616
assert_eq!(
1717
format!("{:x}", f.properties().signature()),
1818
"a1b141f766e9849ac3db1030a20a3c77"
@@ -390,8 +390,7 @@ fn test_invalid() {
390390

391391
#[test]
392392
fn test_audio_properties() {
393-
let mut file = temp_file!("tests/taglib/data/sinewave.flac");
394-
let f = FlacFile::read_from(&mut file, ParseOptions::new()).unwrap();
393+
let f = get_file::<FlacFile>("tests/taglib/data/sinewave.flac");
395394

396395
let properties = f.properties();
397396
assert_eq!(properties.duration().as_secs(), 3);
@@ -410,8 +409,7 @@ fn test_audio_properties() {
410409

411410
#[test]
412411
fn test_zero_sized_padding_1() {
413-
let mut file = temp_file!("tests/taglib/data/zero-sized-padding.flac");
414-
let _ = FlacFile::read_from(&mut file, ParseOptions::new()).unwrap();
412+
let _f = get_file::<FlacFile>("tests/taglib/data/zero-sized-padding.flac");
415413
}
416414

417415
#[test]

tests/taglib/test_id3v2.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
use crate::temp_file;
2+
3+
use std::borrow::Cow;
4+
use std::io::Seek;
5+
26
use lofty::id3::v2::{
37
AttachedPictureFrame, CommentFrame, ExtendedTextFrame, ExtendedUrlFrame, Frame, FrameFlags,
48
FrameId, FrameValue, GeneralEncapsulatedObject, Id3v2Tag, Id3v2Version, Popularimeter,
@@ -10,8 +14,6 @@ use lofty::{
1014
Accessor, AudioFile, MimeType, ParseOptions, ParsingMode, Picture, PictureType, TagExt,
1115
TextEncoding,
1216
};
13-
use std::borrow::Cow;
14-
use std::io::Seek;
1517

1618
#[test]
1719
fn test_unsynch_decode() {

tests/taglib/test_mp4.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use crate::temp_file;
2+
use crate::util::get_file;
3+
24
use std::borrow::Cow;
35
use std::io::{Read, Seek};
46

@@ -7,8 +9,7 @@ use lofty::{Accessor, AudioFile, MimeType, ParseOptions, Picture, PictureType, T
79

810
#[test]
911
fn test_properties_aac() {
10-
let mut file = temp_file!("tests/taglib/data/has-tags.m4a");
11-
let f = Mp4File::read_from(&mut file, ParseOptions::new()).unwrap();
12+
let f = get_file::<Mp4File>("tests/taglib/data/has-tags.m4a");
1213
assert_eq!(f.properties().duration().as_secs(), 3);
1314
assert_eq!(f.properties().duration().as_millis(), 3708);
1415
assert_eq!(f.properties().audio_bitrate(), 3);
@@ -47,8 +48,7 @@ fn test_properties_aac_without_bitrate() {
4748

4849
#[test]
4950
fn test_properties_alac() {
50-
let mut file = temp_file!("tests/taglib/data/empty_alac.m4a");
51-
let f = Mp4File::read_from(&mut file, ParseOptions::new()).unwrap();
51+
let f = get_file::<Mp4File>("tests/taglib/data/empty_alac.m4a");
5252
assert_eq!(f.properties().duration().as_secs(), 3);
5353
assert_eq!(f.properties().duration().as_millis(), 3705);
5454
assert_eq!(f.properties().audio_bitrate(), 3);
@@ -86,8 +86,7 @@ fn test_properties_alac_without_bitrate() {
8686

8787
#[test]
8888
fn test_properties_m4v() {
89-
let mut file = temp_file!("tests/taglib/data/blank_video.m4v");
90-
let f = Mp4File::read_from(&mut file, ParseOptions::new()).unwrap();
89+
let f = get_file::<Mp4File>("tests/taglib/data/blank_video.m4v");
9190
assert_eq!(f.properties().duration().as_secs(), 0);
9291
assert_eq!(f.properties().duration().as_millis(), 975);
9392
assert_eq!(f.properties().audio_bitrate(), 96);
@@ -107,8 +106,7 @@ fn test_check_valid() {
107106
#[test]
108107
fn test_has_tag() {
109108
{
110-
let mut file = temp_file!("tests/taglib/data/has-tags.m4a");
111-
let f = Mp4File::read_from(&mut file, ParseOptions::new()).unwrap();
109+
let f = get_file::<Mp4File>("tests/taglib/data/has-tags.m4a");
112110
assert!(f.ilst().is_some());
113111
}
114112

@@ -241,15 +239,13 @@ fn test_64bit_atom() {}
241239

242240
#[test]
243241
fn test_gnre() {
244-
let mut file = temp_file!("tests/taglib/data/gnre.m4a");
245-
let f = Mp4File::read_from(&mut file, ParseOptions::new()).unwrap();
242+
let f = get_file::<Mp4File>("tests/taglib/data/gnre.m4a");
246243
assert_eq!(f.ilst().unwrap().genre().as_deref(), Some("Ska"));
247244
}
248245

249246
#[test]
250247
fn test_covr_read() {
251-
let mut file = temp_file!("tests/taglib/data/has-tags.m4a");
252-
let f = Mp4File::read_from(&mut file, ParseOptions::new()).unwrap();
248+
let f = get_file::<Mp4File>("tests/taglib/data/has-tags.m4a");
253249
let tag = f.ilst().unwrap();
254250
assert!(tag.contains(&AtomIdent::Fourcc(*b"covr")));
255251
let mut covrs = tag.get(&AtomIdent::Fourcc(*b"covr")).unwrap().data();
@@ -314,8 +310,7 @@ fn test_covr_write() {
314310

315311
#[test]
316312
fn test_covr_read2() {
317-
let mut file = temp_file!("tests/taglib/data/covr-junk.m4a");
318-
let f = Mp4File::read_from(&mut file, ParseOptions::new()).unwrap();
313+
let f = get_file::<Mp4File>("tests/taglib/data/covr-junk.m4a");
319314
let tag = f.ilst().unwrap();
320315
assert!(tag.contains(&AtomIdent::Fourcc(*b"covr")));
321316
let mut covrs = tag.get(&AtomIdent::Fourcc(*b"covr")).unwrap().data();
@@ -353,8 +348,7 @@ fn test_properties_movement() {
353348

354349
#[test]
355350
fn test_fuzzed_file() {
356-
let mut file = temp_file!("tests/taglib/data/infloop.m4a");
357-
let _ = Mp4File::read_from(&mut file, ParseOptions::new()).unwrap();
351+
let _f = get_file::<Mp4File>("tests/taglib/data/infloop.m4a");
358352
}
359353

360354
#[test]
@@ -386,8 +380,7 @@ fn test_repeated_save() {
386380

387381
#[test]
388382
fn test_with_zero_length_atom() {
389-
let mut file = temp_file!("tests/taglib/data/zero-length-mdat.m4a");
390-
let f = Mp4File::read_from(&mut file, ParseOptions::new()).unwrap();
383+
let f = get_file::<Mp4File>("tests/taglib/data/zero-length-mdat.m4a");
391384
assert_eq!(f.properties().duration().as_millis(), 1115);
392385
assert_eq!(f.properties().sample_rate(), 22050);
393386
}
@@ -450,8 +443,7 @@ fn test_remove_metadata() {
450443

451444
#[test]
452445
fn test_non_full_meta_atom() {
453-
let mut file = temp_file!("tests/taglib/data/non-full-meta.m4a");
454-
let f = Mp4File::read_from(&mut file, ParseOptions::new()).unwrap();
446+
let f = get_file::<Mp4File>("tests/taglib/data/non-full-meta.m4a");
455447
assert!(f.ilst().is_some());
456448

457449
let tag = f.ilst().unwrap();

tests/taglib/test_mpeg.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::temp_file;
2+
use crate::util::get_file;
23

34
use std::fs::File;
45
use std::io::Seek;
@@ -12,8 +13,7 @@ use lofty::{Accessor, AudioFile, ParseOptions};
1213
#[test]
1314
#[ignore]
1415
fn test_audio_properties_xing_header_cbr() {
15-
let mut file = File::open("tests/taglib/data/lame_cbr.mp3").unwrap();
16-
let f = MpegFile::read_from(&mut file, ParseOptions::new()).unwrap();
16+
let f = get_file::<MpegFile>("tests/taglib/data/lame_cbr.mp3");
1717

1818
assert_eq!(f.properties().duration().as_secs(), 1887); // TODO: Off by 9
1919
assert_eq!(f.properties().duration().as_millis(), 1887164);
@@ -27,8 +27,7 @@ fn test_audio_properties_xing_header_cbr() {
2727
#[test]
2828
#[ignore]
2929
fn test_audio_properties_xing_header_vbr() {
30-
let mut file = File::open("tests/taglib/data/lame_vbr.mp3").unwrap();
31-
let f = MpegFile::read_from(&mut file, ParseOptions::new()).unwrap();
30+
let f = get_file::<MpegFile>("tests/taglib/data/lame_vbr.mp3");
3231

3332
assert_eq!(f.properties().duration().as_secs(), 1887); // TODO: Off by 9
3433
assert_eq!(f.properties().duration().as_millis(), 1887164);
@@ -42,8 +41,7 @@ fn test_audio_properties_xing_header_vbr() {
4241
#[test]
4342
#[ignore]
4443
fn test_audio_properties_vbri_header() {
45-
let mut file = File::open("tests/taglib/data/rare_frames.mp3").unwrap();
46-
let f = MpegFile::read_from(&mut file, ParseOptions::new()).unwrap();
44+
let f = get_file::<MpegFile>("tests/taglib/data/rare_frames.mp3");
4745

4846
assert_eq!(f.properties().duration().as_secs(), 222); // TODO: Off by 1
4947
assert_eq!(f.properties().duration().as_millis(), 222198);
@@ -57,8 +55,7 @@ fn test_audio_properties_vbri_header() {
5755
#[test]
5856
#[ignore]
5957
fn test_audio_properties_no_vbr_headers() {
60-
let mut file = File::open("tests/taglib/data/bladeenc.mp3").unwrap();
61-
let f = MpegFile::read_from(&mut file, ParseOptions::new()).unwrap();
58+
let f = get_file::<MpegFile>("tests/taglib/data/bladeenc.mp3");
6259

6360
assert_eq!(f.properties().duration().as_secs(), 3); // Off by 1
6461
assert_eq!(f.properties().duration().as_millis(), 3553);
@@ -72,8 +69,7 @@ fn test_audio_properties_no_vbr_headers() {
7269

7370
#[test]
7471
fn test_skip_invalid_frames_1() {
75-
let mut file = File::open("tests/taglib/data/invalid-frames1.mp3").unwrap();
76-
let f = MpegFile::read_from(&mut file, ParseOptions::new()).unwrap();
72+
let f = get_file::<MpegFile>("tests/taglib/data/invalid-frames1.mp3");
7773

7874
assert_eq!(f.properties().duration().as_secs(), 0);
7975
assert_eq!(f.properties().duration().as_millis(), 392);
@@ -85,8 +81,7 @@ fn test_skip_invalid_frames_1() {
8581
#[test]
8682
#[ignore]
8783
fn test_skip_invalid_frames_2() {
88-
let mut file = File::open("tests/taglib/data/invalid-frames2.mp3").unwrap();
89-
let f = MpegFile::read_from(&mut file, ParseOptions::new()).unwrap();
84+
let f = get_file::<MpegFile>("tests/taglib/data/invalid-frames2.mp3");
9085

9186
assert_eq!(f.properties().duration().as_secs(), 0);
9287
assert_eq!(f.properties().duration().as_millis(), 314); // TODO: Off by 79
@@ -98,8 +93,7 @@ fn test_skip_invalid_frames_2() {
9893
#[test]
9994
#[ignore]
10095
fn test_skip_invalid_frames_3() {
101-
let mut file = File::open("tests/taglib/data/invalid-frames3.mp3").unwrap();
102-
let f = MpegFile::read_from(&mut file, ParseOptions::new()).unwrap();
96+
let f = get_file::<MpegFile>("tests/taglib/data/invalid-frames3.mp3");
10397

10498
assert_eq!(f.properties().duration().as_secs(), 0);
10599
assert_eq!(f.properties().duration().as_millis(), 183); // TODO: Off by 26
@@ -111,8 +105,7 @@ fn test_skip_invalid_frames_3() {
111105
#[test]
112106
#[ignore]
113107
fn test_version_2_duration_with_xing_header() {
114-
let mut file = File::open("tests/taglib/data/mpeg2.mp3").unwrap();
115-
let f = MpegFile::read_from(&mut file, ParseOptions::new()).unwrap();
108+
let f = get_file::<MpegFile>("tests/taglib/data/mpeg2.mp3");
116109
assert_eq!(f.properties().duration().as_secs(), 5387); // TODO: Off by 15
117110
assert_eq!(f.properties().duration().as_millis(), 5387285);
118111
}
@@ -176,8 +169,7 @@ fn test_save_id3v23() {
176169

177170
#[test]
178171
fn test_duplicate_id3v2() {
179-
let mut file = File::open("tests/taglib/data/duplicate_id3v2.mp3").unwrap();
180-
let f = MpegFile::read_from(&mut file, ParseOptions::new()).unwrap();
172+
let f = get_file::<MpegFile>("tests/taglib/data/duplicate_id3v2.mp3");
181173
assert_eq!(f.properties().sample_rate(), 44100);
182174
}
183175

tests/taglib/test_ogaflac.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use crate::temp_file;
2+
3+
use std::io::{Seek, SeekFrom};
4+
25
use lofty::flac::FlacFile;
36
use lofty::ogg::VorbisComments;
47
use lofty::{Accessor, AudioFile, ParseOptions};
5-
use std::io::{Seek, SeekFrom};
68

79
#[test]
810
#[ignore] // TODO: We don't support FLAC in OGA

tests/taglib/test_ogg.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use crate::temp_file;
2-
use lofty::ogg::VorbisFile;
3-
use lofty::{Accessor, AudioFile, ParseOptions};
2+
use crate::util::get_file;
43

54
use std::io::{Read, Seek, SeekFrom};
65

76
use byteorder::{LittleEndian, ReadBytesExt};
7+
use lofty::ogg::VorbisFile;
8+
use lofty::{Accessor, AudioFile, ParseOptions};
89

910
#[test]
1011
fn test_simple() {
@@ -74,8 +75,7 @@ fn test_dict_interface2() {
7475

7576
#[test]
7677
fn test_audio_properties() {
77-
let mut file = temp_file!("tests/taglib/data/empty.ogg");
78-
let f = VorbisFile::read_from(&mut file, ParseOptions::new()).unwrap();
78+
let f = get_file::<VorbisFile>("tests/taglib/data/empty.ogg");
7979
assert_eq!(f.properties().duration().as_secs(), 3);
8080
assert_eq!(f.properties().duration().as_millis(), 3685);
8181
assert_eq!(f.properties().audio_bitrate(), 1);

tests/taglib/test_opus.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
use crate::temp_file;
2+
use crate::util::get_file;
3+
4+
use std::io::Seek;
5+
26
use lofty::ogg::OpusFile;
37
use lofty::{Accessor, AudioFile, ParseOptions};
4-
use std::io::Seek;
58

69
#[test]
710
fn test_audio_properties() {
8-
let mut file = temp_file!("tests/taglib/data/correctness_gain_silent_output.opus");
9-
let f = OpusFile::read_from(&mut file, ParseOptions::new()).unwrap();
11+
let f = get_file::<OpusFile>("tests/taglib/data/correctness_gain_silent_output.opus");
1012
assert_eq!(f.properties().duration().as_secs(), 7);
1113
assert_eq!(f.properties().duration().as_millis(), 7737);
1214
assert_eq!(f.properties().audio_bitrate(), 36);
@@ -17,8 +19,7 @@ fn test_audio_properties() {
1719

1820
#[test]
1921
fn test_read_comments() {
20-
let mut file = temp_file!("tests/taglib/data/correctness_gain_silent_output.opus");
21-
let f = OpusFile::read_from(&mut file, ParseOptions::new()).unwrap();
22+
let f = get_file::<OpusFile>("tests/taglib/data/correctness_gain_silent_output.opus");
2223
assert_eq!(
2324
f.vorbis_comments().get("ENCODER"),
2425
Some("Xiph.Org Opus testvectormaker")

tests/taglib/test_speex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::temp_file;
2+
use crate::util::get_file;
23

34
use std::io::Seek;
45

@@ -8,8 +9,7 @@ use lofty::{Accessor, AudioFile, ParseOptions};
89
#[test]
910
#[ignore]
1011
fn test_audio_properties() {
11-
let mut file = temp_file!("tests/taglib/data/empty.spx");
12-
let f = SpeexFile::read_from(&mut file, ParseOptions::new()).unwrap();
12+
let f = get_file::<SpeexFile>("tests/taglib/data/empty.spx");
1313

1414
assert_eq!(f.properties().duration().as_secs(), 3);
1515
// TODO: We report 3684, we're off by one

0 commit comments

Comments
 (0)