diff --git a/test/support/fixtures/discogs/artist.ex b/test/support/fixtures/discogs/artist.ex index 2fe451ca..1979f04f 100644 --- a/test/support/fixtures/discogs/artist.ex +++ b/test/support/fixtures/discogs/artist.ex @@ -1,16 +1,17 @@ defmodule Discogs.Fixtures.Artist do @fixtures_folder Path.join([File.cwd!(), "test/support/fixtures/discogs"]) - def get_artist do - Path.join([@fixtures_folder, "artist - steven wilson.json"]) - |> File.read!() - |> JSON.decode!() - end + # Cache fixtures at compile time to avoid repeated file I/O + @get_artist Path.join([@fixtures_folder, "artist - steven wilson.json"]) + |> File.read!() + |> JSON.decode!() - def image_data do - Path.join([@fixtures_folder, "steven wilson.jpeg"]) - |> File.read!() - end + @image_data Path.join([@fixtures_folder, "steven wilson.jpeg"]) + |> File.read!() + + def get_artist, do: @get_artist + + def image_data, do: @image_data def image_width, do: 225 end diff --git a/test/support/fixtures/last_fm/artist.ex b/test/support/fixtures/last_fm/artist.ex index e15d0ea8..1fa27e0d 100644 --- a/test/support/fixtures/last_fm/artist.ex +++ b/test/support/fixtures/last_fm/artist.ex @@ -1,11 +1,12 @@ defmodule LastFm.Fixtures.Artist do @fixtures_folder Path.join([File.cwd!(), "test/support/fixtures/last_fm"]) - def get_info do - Path.join([@fixtures_folder, "artist.getinfo.json"]) - |> File.read!() - |> JSON.decode!() - end + # Cache fixtures at compile time to avoid repeated file I/O + @get_info Path.join([@fixtures_folder, "artist.getinfo.json"]) + |> File.read!() + |> JSON.decode!() + + def get_info, do: @get_info def get_similar_artists do %{"similarartists" => %{"artist" => []}} diff --git a/test/support/fixtures/music_brainz/artist.ex b/test/support/fixtures/music_brainz/artist.ex index 5b16f631..d60d7cc0 100644 --- a/test/support/fixtures/music_brainz/artist.ex +++ b/test/support/fixtures/music_brainz/artist.ex @@ -1,9 +1,10 @@ defmodule MusicBrainz.Fixtures.Artist do @fixtures_folder Path.join([File.cwd!(), "test/support/fixtures/music_brainz"]) - def get_artist do - Path.join([@fixtures_folder, "artist - steven wilson.json"]) - |> File.read!() - |> JSON.decode!() - end + # Cache fixtures at compile time to avoid repeated file I/O + @get_artist Path.join([@fixtures_folder, "artist - steven wilson.json"]) + |> File.read!() + |> JSON.decode!() + + def get_artist, do: @get_artist end diff --git a/test/support/fixtures/wikipedia/fixtures.ex b/test/support/fixtures/wikipedia/fixtures.ex index 2467e4e5..60c44d2b 100644 --- a/test/support/fixtures/wikipedia/fixtures.ex +++ b/test/support/fixtures/wikipedia/fixtures.ex @@ -1,32 +1,33 @@ defmodule Wikipedia.Fixtures do @fixtures_folder Path.join([File.cwd!(), "test/support/fixtures/wikipedia"]) - def wikidata_response do - Path.join([@fixtures_folder, "wikidata_response.json"]) - |> File.read!() - |> JSON.decode!() - end + # Cache fixtures at compile time to avoid repeated file I/O + @wikidata_response Path.join([@fixtures_folder, "wikidata_response.json"]) + |> File.read!() + |> JSON.decode!() - def wikidata_response_no_enwiki do - Path.join([@fixtures_folder, "wikidata_response_no_enwiki.json"]) - |> File.read!() - |> JSON.decode!() - end + @wikidata_response_no_enwiki Path.join([@fixtures_folder, "wikidata_response_no_enwiki.json"]) + |> File.read!() + |> JSON.decode!() - def article_summary do - Path.join([@fixtures_folder, "article_summary.json"]) - |> File.read!() - |> JSON.decode!() - end + @article_summary Path.join([@fixtures_folder, "article_summary.json"]) + |> File.read!() + |> JSON.decode!() - def article_extract do - Path.join([@fixtures_folder, "article_extract.json"]) - |> File.read!() - |> JSON.decode!() - end + @article_extract Path.join([@fixtures_folder, "article_extract.json"]) + |> File.read!() + |> JSON.decode!() + + def wikidata_response, do: @wikidata_response + + def wikidata_response_no_enwiki, do: @wikidata_response_no_enwiki + + def article_summary, do: @article_summary + + def article_extract, do: @article_extract def article_extract_html do - article_extract() + @article_extract |> get_in(["query", "pages"]) |> Map.values() |> List.first()