Skip to content

Commit

Permalink
Revert to setting default file path at time of load
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-isoc committed Nov 15, 2024
1 parent 890d313 commit 246e44d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
18 changes: 9 additions & 9 deletions src/hdx/location/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ class Country:
_countriesdata = None
_ochaurl_default = "https://docs.google.com/spreadsheets/d/1NjSI2LaS3SqbgYc0HdD8oIb7lofGtiHgoKKATCpwVdY/export?format=csv&gid=1088874596"
_ochaurl = _ochaurl_default
_ochapath_default = script_dir_plus_file(
"Countries & Territories Taxonomy MVP - C&T Taxonomy with HXL Tags.csv",
CountryError,
)
_ochapath = _ochapath_default
_ochapath = None
_country_name_overrides = {}
_country_name_mappings = {}

Expand Down Expand Up @@ -243,8 +239,14 @@ def countriesdata(
"Download from OCHA feed failed! Falling back to stored file."
)
if countries is None:
file_path = script_dir_plus_file(
"Countries & Territories Taxonomy MVP - C&T Taxonomy with HXL Tags.csv",
CountryError,
)
if cls._ochapath:
file_path = cls._ochapath
countries = hxl.data(
cls._ochapath,
file_path,
InputOptions(allow_local=True, encoding="utf-8"),
)
cls.set_countriesdata(countries)
Expand Down Expand Up @@ -292,10 +294,8 @@ def set_ocha_path(cls, path: Optional[str] = None) -> None:
Returns:
None
"""
if not os.path.exists(path):
if path and not os.path.exists(path):
path = None
if path is None:
path = cls._ochapath_default
cls._ochapath = path

@classmethod
Expand Down
11 changes: 6 additions & 5 deletions tests/hdx/location/test_country.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,16 +718,17 @@ def test_ocha_feed_file_working(self):
assert Country.get_iso3_from_iso2("AF") == "AFG"

def test_ocha_feed_local_file_working(self):
assert (
Country.get_iso3_country_code("UZBEKISTAN", use_live=False)
== "UZB"
)

Country._countriesdata = None
Country.set_ocha_path(
script_dir_plus_file("Countries_UZB_Deleted.csv", TestCountry)
)
assert (
Country.get_iso3_country_code("UZBEKISTAN", use_live=False) is None
)

Country._countriesdata = None
Country.set_ocha_path()
assert (
Country.get_iso3_country_code("UZBEKISTAN", use_live=False)
== "UZB"
)

0 comments on commit 246e44d

Please sign in to comment.