Merge pull request #1604 from efiop/master

updater: don't use io.open when working with json
This commit is contained in:
Ruslan Kuprieiev
2019-02-12 01:49:49 +02:00
committed by GitHub
2 changed files with 40 additions and 1 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
from __future__ import unicode_literals
from dvc.utils.compat import str, open
from dvc.utils.compat import str
import sys
import os
+39
View File
@@ -0,0 +1,39 @@
import os
import json
import mock
from dvc import VERSION
from tests.basic_env import TestDvc
class MockResponse(object):
def __init__(self, json_data, status_code):
self.json_data = json_data
self.status_code = status_code
def json(self):
return self.json_data
def mocked_requests_get(*args, **kwargs):
class MockResponse:
def __init__(self, json_data, status_code):
self.json_data = json_data
self.status_code = status_code
def json(self):
return self.json_data
return MockResponse({"version": VERSION}, 200)
class TestUpdater(TestDvc):
@mock.patch("requests.get", side_effect=mocked_requests_get)
def test_fetch(self, mock_get):
self.assertFalse(os.path.exists(self.dvc.updater.updater_file))
self.dvc.updater.fetch(detach=False)
mock_get.assert_called_once()
self.assertTrue(os.path.isfile(self.dvc.updater.updater_file))
with open(self.dvc.updater.updater_file, "r") as fobj:
info = json.load(fobj)
self.assertEqual(info["version"], VERSION)