def set_values_and_compare(self, rhythmdb_without_cout_rating: Path,
itunes_library_path: Path,
expected_rhythmboxdb:Path,
output_file_name: str,
assert_something_was_changed: bool,
itunes_library_root: str="D:/Music/",
rhythmbox_library_root: str="/home/pha/Music/") -> IntegrationLog:
target_rhythmdb = self.target_folder.joinpath(output_file_name)
rhythmdb_without_cout_rating.copy(target_rhythmdb)
itunes_library = str(itunes_library_path)
songs = itunes_library_reader.read_songs(itunes_library)
log = rhythmbox_count_rating_integrator.set_values(itunes_songs=songs,
target_rhythmdb=target_rhythmdb,
itunes_library_root=itunes_library_root,
rhythmbox_library_root=rhythmbox_library_root)
print("Expect something has changed: {}".format(assert_something_was_changed))
if assert_something_was_changed:
self.assertTrue(log.something_was_changed(), "No song entries was changed! But they should be!")
else:
self.assertFalse(log.something_was_changed(), "A song entries was changed! But they shouldn't be!")
print("Compare content of {} (actual) with {} (expected)".format(target_rhythmdb, expected_rhythmboxdb))
with expected_rhythmboxdb.open(mode="r", encoding="UTF-8") as expected_rhythmboxdb_opened, target_rhythmdb.open(
"r") as target_rhythmdb_opened:
actual_playlist_xml = target_rhythmdb_opened.read()
expected_playlist_xml = expected_rhythmboxdb_opened.read()
# comparing xml is a pain. simple string comparision doesn't work due to different tag order and formatting (newline after each tag or not).
# so let's sort each character in both xml strings. this leads to rubbish. but if the sorted rubbish is equal, the origin is xml is very likely to be equal.
actual_playlist_xml_normalized = sort_and_clean(actual_playlist_xml)
expected_playlist_xml_normalized = sort_and_clean(expected_playlist_xml)
self.assertEqual(actual_playlist_xml_normalized, expected_playlist_xml_normalized,
"Normalized content of {} and {} are different!".format(expected_rhythmboxdb, target_rhythmdb))
return log
rhythmbox_count_rating_integrator_tests.py 文件源码
python
阅读 20
收藏 0
点赞 0
评论 0
评论列表
文章目录