Repository: OCHA-DAP/hdx-python-country

Issue:
set_use_live_default not working as expected
I have called `Country.set_use_live_default(False)` but when calling any method to retrieve data, it's still using the live data. It seems to be setting `cls._use_live` correctly but the method param default is not picking this value up.

I will submit a PR for a fix.

Hints from issue comments:
@mcarans: @andy-isoc Please confirm if 3.8.5 which has your fix resolves this issue@andy-isoc: @mcarans Many thanks for prompt review/merge/release. Yes, this does indeed fix the issue for us.

Solution patch:
diff --git a/src/hdx/location/country.py b/src/hdx/location/country.py
index dbdb239..b4e7500 100755
--- a/src/hdx/location/country.py
+++ b/src/hdx/location/country.py
@@ -212,7 +212,7 @@ def sort_list(colname):
     @classmethod
     def countriesdata(
         cls,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         country_name_overrides: Dict = None,
         country_name_mappings: Dict = None,
     ) -> List[Dict[str, Dict]]:
@@ -227,6 +227,8 @@ def countriesdata(
         Returns:
             List[Dict[str,Dict]]: Countries dictionaries
         """
+        if use_live is None:
+            use_live = cls._use_live
         if cls._countriesdata is None:
             countries = None
             if country_name_overrides is not None:
@@ -326,7 +328,7 @@ def set_country_name_mappings(cls, country_name_mappings: Dict) -> None:
     def get_country_info_from_iso3(
         cls,
         iso3: str,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
     ) -> Optional[Dict[str, str]]:
         """Get country information from ISO3 code
@@ -352,7 +354,7 @@ def get_country_info_from_iso3(
     def get_country_name_from_iso3(
         cls,
         iso3: str,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
         formal: bool = False,
     ) -> Optional[str]:
@@ -389,7 +391,7 @@ def get_country_name_from_iso3(
     def get_currency_from_iso3(
         cls,
         iso3: str,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
     ) -> Optional[int]:
         """Get currency code from ISO3 code
@@ -415,7 +417,7 @@ def get_currency_from_iso3(
     def get_iso2_from_iso3(
         cls,
         iso3: str,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
     ) -> Optional[str]:
         """Get ISO2 from ISO3 code
@@ -441,7 +443,7 @@ def get_iso2_from_iso3(
     def get_iso3_from_iso2(
         cls,
         iso2: str,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
     ) -> Optional[str]:
         """Get ISO3 from ISO2 code
@@ -467,7 +469,7 @@ def get_iso3_from_iso2(
     def get_country_info_from_iso2(
         cls,
         iso2: str,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
     ) -> Optional[Dict[str, str]]:
         """Get country name from ISO2 code
@@ -493,7 +495,7 @@ def get_country_info_from_iso2(
     def get_country_name_from_iso2(
         cls,
         iso2: str,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
         formal: bool = False,
     ) -> Optional[str]:
@@ -521,7 +523,7 @@ def get_country_name_from_iso2(
     def get_currency_from_iso2(
         cls,
         iso2: str,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
     ) -> Optional[str]:
         """Get currency from ISO2 code
@@ -547,7 +549,7 @@ def get_currency_from_iso2(
     def get_m49_from_iso3(
         cls,
         iso3: str,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
     ) -> Optional[int]:
         """Get M49 from ISO3 code
@@ -573,7 +575,7 @@ def get_m49_from_iso3(
     def get_iso3_from_m49(
         cls,
         m49: int,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
     ) -> Optional[str]:
         """Get ISO3 from M49 code
@@ -599,7 +601,7 @@ def get_iso3_from_m49(
     def get_country_info_from_m49(
         cls,
         m49: int,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
     ) -> Optional[Dict[str, str]]:
         """Get country name from M49 code
@@ -623,7 +625,7 @@ def get_country_info_from_m49(
     def get_country_name_from_m49(
         cls,
         m49: int,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
         formal: bool = False,
     ) -> Optional[str]:
@@ -651,7 +653,7 @@ def get_country_name_from_m49(
     def get_currency_from_m49(
         cls,
         m49: int,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
     ) -> Optional[str]:
         """Get currency from M49 code
@@ -754,7 +756,7 @@ def simplify_countryname(cls, country: str) -> (str, List[str]):
     def get_iso3_country_code(
         cls,
         country: str,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
     ) -> Optional[str]:
         """Get ISO3 code for cls. Only exact matches or None are returned.
@@ -814,7 +816,7 @@ def get_iso3_country_code(
     def get_iso3_country_code_fuzzy(
         cls,
         country: str,
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
         min_chars: int = 5,
     ) -> Tuple[Optional[str], bool]:
@@ -904,7 +906,7 @@ def remove_matching_from_list(wordlist, word_or_part):
     def get_countries_in_region(
         cls,
         region: Union[int, str],
-        use_live: bool = _use_live,
+        use_live: bool = None,
         exception: Optional[ExceptionUpperBound] = None,
     ) -> List[str]:
         """Get countries (ISO3 codes) in region


Test patch:
diff --git a/tests/hdx/location/test_country.py b/tests/hdx/location/test_country.py
index ad4215a..803d30f 100755
--- a/tests/hdx/location/test_country.py
+++ b/tests/hdx/location/test_country.py
@@ -696,8 +696,17 @@ def test_use_live_default(self):
         assert Country._use_live is True
         Country.set_use_live_default(False)
         assert Country._use_live is False
+        # We should now be able to load from local data without setting use_live=False
+        Country._countriesdata = None
+        Country.set_ocha_path(
+            script_dir_plus_file("Countries_UZB_Deleted.csv", TestCountry)
+        )
+        assert Country.get_iso3_country_code("UZBEKISTAN") is None
         Country.set_use_live_default(None)
         assert Country._use_live is True
+        Country._countriesdata = None
+        assert Country.get_iso3_country_code("UZBEKISTAN") == "UZB"
+        Country._countriesdata = None
 
     def test_ocha_feed_file_working(self):
         countries = hxl.data(