Files
dvc/tests/unit/test_updater.py
T
Mr. Outis b4d0d37ac8 dvc: refactor package versioning logic
- Use `version.py` to compute a dynamic version stored in `__version__`.
  Version information was scattered across the source code
  (`VERSION_BASE`, `VERSION`, `__version__`, and `version.py`).

- Read `__version__` from `setup.py` and **pin** it using custom
  `build_py` command class.
  This way, we can maintain consistancy between the build version
  and the runtime one.
  Also, this gives us the ability to run `setup.py` without depending on
  on `dvc` itself.

Close #1824
2019-04-06 18:06:11 -06:00

40 lines
1.1 KiB
Python

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__)