def _check_pypi_version(self): """ When the version is out of date or we have trouble retrieving it print a error to stderr and pause. """ try: check_version() except VersionException as err: print(str(err), file=sys.stderr) time.sleep(TWO_SECONDS)
def test_check_version_new_version_raises(self, mock_get_pypi_version, mock_get_internal_version): """ When their is a new version at pypi the VersionException should be raised. It should contain instructions on how to upgrade DukeDSClient. """ mock_get_pypi_version.return_value = [0, 2, 2] mock_get_internal_version.return_value = [0, 1, 2] with self.assertRaises(VersionException) as exception_info: check_version() self.assertIn("pip install --upgrade DukeDSClient", str(exception_info.exception))
def test_check_version_works(self): """ pypi shouldn't be a greater version than the development version """ check_version()
def test_check_version_pypi_bad_url(self, mock_requests): mock_requests.exceptions = requests.exceptions mock_requests.get.side_effect = requests.exceptions.ConnectionError with self.assertRaises(VersionException) as exception_info: check_version() self.assertIn("Failed to connect", str(exception_info.exception))
def test_check_version_pypi_timeout(self, mock_requests): mock_requests.exceptions = requests.exceptions mock_requests.get.side_effect = requests.exceptions.Timeout with self.assertRaises(VersionException) as exception_info: check_version() self.assertIn("Timeout", str(exception_info.exception))