Add tests for version parsing
This commit is contained in:
parent
f36c0b7ff7
commit
94b011799d
@ -1,9 +1,11 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
from unittest.mock import mock_open
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@ -103,5 +105,34 @@ class TestRemoteInfo(unittest.TestCase):
|
|||||||
subtest.run(release_gitter.GitRemoteInfo.get_releases_url)
|
subtest.run(release_gitter.GitRemoteInfo.get_releases_url)
|
||||||
|
|
||||||
|
|
||||||
|
class TestVersionInfo(unittest.TestCase):
|
||||||
|
def test_no_cargo_file(self):
|
||||||
|
with patch("pathlib.Path.exists", return_value=False):
|
||||||
|
version = release_gitter.read_version()
|
||||||
|
self.assertIsNone(version)
|
||||||
|
|
||||||
|
def test_cargo_file_has_version(self):
|
||||||
|
with (
|
||||||
|
patch("pathlib.Path.exists", return_value=True),
|
||||||
|
patch(
|
||||||
|
"pathlib.Path.open",
|
||||||
|
mock_open(read_data="\n".join(["[package]", 'version = "1.0.0"'])),
|
||||||
|
),
|
||||||
|
):
|
||||||
|
version = release_gitter.read_version()
|
||||||
|
self.assertEqual(version, "1.0.0")
|
||||||
|
|
||||||
|
def test_cargo_file_missing_version(self):
|
||||||
|
with (
|
||||||
|
patch("pathlib.Path.exists", return_value=True),
|
||||||
|
patch(
|
||||||
|
"pathlib.Path.open",
|
||||||
|
mock_open(read_data="\n".join(["[package]"])),
|
||||||
|
),
|
||||||
|
):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
release_gitter.read_version()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user