Repository: lk-geimfari/mimesis (language: python)

Issue:
Tests that write to files fail in windows
Tests that write to files (to csv, to json, and to pickle) fail in windows due to access rights issue.

Will create PR with fix.


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index e4810fefc..1cb02d988 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,3 +1,8 @@
+Version next
+--------------
+
+- Fix file permissions in Windows.
+
 Version 15.1.0
 --------------
 


Test patch:
diff --git a/tests/test_schema.py b/tests/test_schema.py
index 74527d605..68ee154c7 100644
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -2,9 +2,9 @@
 import json
 import pickle
 import re
-import tempfile
 import unicodedata
 from collections.abc import Iterator
+from typing import TYPE_CHECKING
 
 import pytest
 
@@ -24,6 +24,9 @@
 from mimesis.types import MissingSeed
 from tests.test_providers.patterns import DATA_PROVIDER_STR_REGEX
 
+if TYPE_CHECKING:
+    from pathlib import Path
+
 
 def test_str(default_field):
     assert re.match(DATA_PROVIDER_STR_REGEX, str(default_field))
@@ -309,35 +312,36 @@ def test_schema_iterator(schema):
         next(schema)
 
 
-def test_schema_to_csv(schema):
-    with tempfile.NamedTemporaryFile("r+") as temp_file:
-        schema.to_csv(temp_file.name)
-        dict_reader = csv.DictReader(temp_file)
+def test_schema_to_csv(tmp_path: "Path", schema: Schema):
+    file = tmp_path / "test.csv"
+    schema.to_csv(str(file))
+
+    dict_reader = csv.DictReader(file.read_text("UTF-8").splitlines())
 
-        assert len(list(dict_reader)) == schema.iterations
-        assert isinstance(dict_reader, csv.DictReader)
+    assert len(list(dict_reader)) == schema.iterations
+    assert isinstance(dict_reader, csv.DictReader)
 
-        for row in dict_reader:
-            assert "id" in row and "timestamp" in row
+    for row in dict_reader:
+        assert "id" in row and "timestamp" in row
 
 
-def test_schema_to_json(schema):
-    with tempfile.NamedTemporaryFile("r+") as temp_file:
-        schema.to_json(temp_file.name, sort_keys=True, ensure_ascii=False)
+def test_schema_to_json(tmp_path: "Path", schema: Schema):
+    file = tmp_path / "test.json"
+    schema.to_json(str(file), sort_keys=True, ensure_ascii=False)
 
-        data = json.load(temp_file)
-        assert len(list(data)) == schema.iterations
-        assert "id" in data[0] and "id" in data[-1]
+    data = json.loads(file.read_text("UTF-8"))
+    assert len(list(data)) == schema.iterations
+    assert "id" in data[0] and "id" in data[-1]
 
 
-def test_schema_to_pickle(schema):
-    with tempfile.NamedTemporaryFile("rb") as temp_file:
-        schema.to_pickle(temp_file.name)
+def test_schema_to_pickle(tmp_path: "Path", schema: Schema):
+    file = tmp_path / "test.pkl"
+    schema.to_pickle(str(file))
 
-        data = pickle.load(temp_file)
-        assert "id" in data[0] and "id" in data[-1]
-        assert isinstance(data, list)
-        assert len(data) == schema.iterations
+    data = pickle.loads(file.read_bytes())
+    assert "id" in data[0] and "id" in data[-1]
+    assert isinstance(data, list)
+    assert len(data) == schema.iterations
 
 
 @pytest.mark.parametrize(