mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
py2 compat issues 🤷
This commit is contained in:
+4
-6
@@ -1,4 +1,3 @@
|
||||
import errno
|
||||
import json
|
||||
import logging
|
||||
import platform
|
||||
@@ -15,6 +14,7 @@ from dvc.lock import Lock, LockError
|
||||
from dvc.repo import Repo
|
||||
from dvc.scm import SCM
|
||||
from dvc.utils import env2bool, is_binary, makedirs
|
||||
from dvc.utils.compat import str, FileNotFoundError
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -53,7 +53,7 @@ def is_enabled():
|
||||
def send(path):
|
||||
url = "https://analytics.dvc.org"
|
||||
|
||||
with open(path) as fobj:
|
||||
with open(str(path)) as fobj:
|
||||
report = json.load(fobj)
|
||||
|
||||
requests.post(url, json=report, timeout=5)
|
||||
@@ -113,12 +113,10 @@ def find_or_create_user_id():
|
||||
with Lock(lockfile):
|
||||
try:
|
||||
user_id = json.loads(fname.read_text())["user_id"]
|
||||
except (IOError, json.JSONDecodeError, AttributeError) as exc:
|
||||
if exc.errno != errno.ENOENT:
|
||||
raise
|
||||
except (FileNotFoundError, ValueError, AttributeError):
|
||||
user_id = str(uuid.uuid4())
|
||||
makedirs(fname.parent, exist_ok=True)
|
||||
fname.write_text(json.dumps({"user_id": user_id}))
|
||||
fname.write_text(str(json.dumps({"user_id": user_id})))
|
||||
|
||||
return user_id
|
||||
|
||||
|
||||
+2
-7
@@ -342,13 +342,8 @@ class Config(object): # pylint: disable=too-many-instance-attributes
|
||||
return ret
|
||||
|
||||
def _load_configs(self):
|
||||
system_config_file = os.path.join(
|
||||
self.get_system_config_dir(), self.CONFIG
|
||||
)
|
||||
|
||||
global_config_file = os.path.join(
|
||||
self.get_global_config_dir(), self.CONFIG
|
||||
)
|
||||
system_config_file = str(self.get_system_config_dir() / self.CONFIG)
|
||||
global_config_file = str(self.get_global_config_dir() / self.CONFIG)
|
||||
|
||||
self._system_config = configobj.ConfigObj(system_config_file)
|
||||
self._global_config = configobj.ConfigObj(global_config_file)
|
||||
|
||||
@@ -2,13 +2,14 @@ import mock
|
||||
import json
|
||||
|
||||
from dvc.main import main
|
||||
from dvc.utils.compat import str
|
||||
|
||||
|
||||
@mock.patch("dvc.analytics.send")
|
||||
def test_daemon_analytics(mock_send, tmp_path):
|
||||
report = {"name": "dummy report"}
|
||||
fname = tmp_path / "report"
|
||||
fname.write_text(json.dumps(report))
|
||||
fname.write_text(str(json.dumps(report)))
|
||||
|
||||
assert 0 == main(["daemon", "analytics", str(fname)])
|
||||
assert mock_send.called
|
||||
|
||||
@@ -3,6 +3,7 @@ import pytest
|
||||
import mock
|
||||
|
||||
from dvc import analytics
|
||||
from dvc.utils.compat import builtin_str, str
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -21,7 +22,7 @@ def test_collect(tmp_global_config):
|
||||
assert not report["cmd_class"]
|
||||
assert type(report["is_binary"]) is bool
|
||||
assert type(report["system_info"]) is dict
|
||||
assert type(report["dvc_version"]) is str
|
||||
assert type(report["dvc_version"]) is builtin_str
|
||||
assert type(report["user_id"]) is str
|
||||
|
||||
|
||||
@@ -31,7 +32,7 @@ def test_send(mock_post, tmp_path):
|
||||
report = {"name": "dummy report"}
|
||||
fname = tmp_path / "report"
|
||||
|
||||
fname.write_text(json.dumps(report))
|
||||
fname.write_text(str(json.dumps(report)))
|
||||
analytics.send(fname)
|
||||
mock_post.assert_called_with(url, json=report, timeout=5)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user