Repository: joke2k/faker
Pull request #1649 (2022-05-04 02:27:37)

Fix fr-FR datetime provider and add tests for it
I have fixed the fr-FR date_time provider and added tests for it.


Patch:
diff --git a/faker/providers/date_time/fr_FR/__init__.py b/faker/providers/date_time/fr_FR/__init__.py
index ca031e97..b7d25de3 100644
--- a/faker/providers/date_time/fr_FR/__init__.py
+++ b/faker/providers/date_time/fr_FR/__init__.py
@@ -2,33 +2,34 @@ from .. import Provider as DateTimeProvider
 
 
 class Provider(DateTimeProvider):
+    DAY_NAMES = {
+        "0": "dimanche",
+        "1": "lundi",
+        "2": "mardi",
+        "3": "mercredi",
+        "4": "jeudi",
+        "5": "vendredi",
+        "6": "samedi",
+    }
+    MONTH_NAMES = {
+        "01": "Janvier",
+        "02": "Février",
+        "03": "Mars",
+        "04": "Avril",
+        "05": "Mai",
+        "06": "Juin",
+        "07": "Juillet",
+        "08": "Août",
+        "09": "Septembre",
+        "10": "Octobre",
+        "11": "Novembre",
+        "12": "Décembre",
+    }
+
     def day_of_week(self) -> str:
         day = self.date("%w")
-        DAY_NAMES = {
-            "0": "Dimanche",
-            "1": "Lundi",
-            "2": "Mardi",
-            "3": "Mercredi",
-            "4": "Jeudi",
-            "5": "Vendredi",
-            "6": "Samedi",
-        }
-        return DAY_NAMES[day]
+        return self.DAY_NAMES[day]
 
     def month_name(self) -> str:
         month = self.month()
-        MONTH_NAMES = {
-            "01": "Janvier",
-            "02": "Février",
-            "03": "Mars",
-            "04": "Avril",
-            "05": "Mai",
-            "06": "Juin",
-            "07": "Juillet",
-            "08": "Août",
-            "09": "Septembre",
-            "10": "Octobre",
-            "11": "Novembre",
-            "12": "Décembre",
-        }
-        return MONTH_NAMES[month]
+        return self.MONTH_NAMES[month]


Test patch:
diff --git a/tests/providers/test_date_time.py b/tests/providers/test_date_time.py
index 0d67b083..0ed74cbb 100644
--- a/tests/providers/test_date_time.py
+++ b/tests/providers/test_date_time.py
@@ -25,6 +25,7 @@ from faker.providers.date_time.de_AT import Provider as DeAtProvider
 from faker.providers.date_time.de_DE import Provider as DeDeProvider
 from faker.providers.date_time.el_GR import Provider as ElGrProvider
 from faker.providers.date_time.es_ES import Provider as EsEsProvider
+from faker.providers.date_time.fr_FR import Provider as FrFrProvider
 from faker.providers.date_time.hy_AM import Provider as HyAmProvider
 from faker.providers.date_time.it_IT import Provider as ItItProvider
 from faker.providers.date_time.nl_NL import Provider as NlProvider
@@ -1181,3 +1182,17 @@ class TestNoNo(unittest.TestCase):
     def test_month(self):
         month = self.fake.month_name()
         assert month in NoNoProvider.MONTH_NAMES.values()
+
+
+class TestFrFr(unittest.TestCase):
+    def setUp(self):
+        self.fake = Faker("fr-FR")
+        Faker.seed(0)
+
+    def test_day(self):
+        day = self.fake.day_of_week()
+        assert day in FrFrProvider.DAY_NAMES.values()
+
+    def test_month(self):
+        day = self.fake.month_name()
+        assert day in FrFrProvider.MONTH_NAMES.values()