-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR fixes a bug where `VERSION_PINS` is always set to an empty dictionary due to a misaligned indent. We also handle invalid prefixes and version datatypes more gracefully and make the logger more informative. --------- Co-authored-by: Charles Tapley Hoyt <cthoyt@gmail.com>
- Loading branch information
Showing
3 changed files
with
97 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Tests for PyOBO version pins.""" | ||
import os | ||
import unittest | ||
from unittest import mock | ||
|
||
from pyobo.api.utils import get_version, get_version_pins | ||
|
||
MOCK_PYOBO_VERSION_PINS = '{"ncbitaxon": "2024-07-03", "vo":"2024-04-09", "chebi":"235", "bfo":5}' | ||
FAULTY_MOCK_PYOBO_VERSION_PINS = "{'ncbitaxon': '2024-07-03'}" | ||
|
||
|
||
@mock.patch.dict(os.environ, {"PYOBO_VERSION_PINS": MOCK_PYOBO_VERSION_PINS}) | ||
class TestVersionPins(unittest.TestCase): | ||
"""Test using user-defined version pins.""" | ||
|
||
def setUp(self): | ||
"""Clear the cache before each test case.""" | ||
get_version_pins.cache_clear() | ||
|
||
def test_correct_version_pin_types(self): | ||
"""Test resource and version type.""" | ||
version_pins = get_version_pins() | ||
for resource_prefix, version in version_pins.items(): | ||
self.assertIsInstance(resource_prefix, str) | ||
self.assertIsInstance(version, str) | ||
|
||
def test_use_correct_version_pin(self): | ||
"""Tests correct resource version is used.""" | ||
version_pins = get_version_pins() | ||
for resource_prefix, version in version_pins.items(): | ||
self.assertEqual(get_version(resource_prefix), version) | ||
|
||
@mock.patch.dict(os.environ, {"PYOBO_VERSION_PINS": ""}) | ||
def test_empty_version_pins(self): | ||
"""Test empty version pins are processed correctly.""" | ||
version_pins = get_version_pins() | ||
self.assertFalse(version_pins) | ||
|
||
@mock.patch.dict(os.environ, {"PYOBO_VERSION_PINS": FAULTY_MOCK_PYOBO_VERSION_PINS}) | ||
def test_incorrectly_set_version_pins(self): | ||
"""Test erroneously set version pins are processed correctly.""" | ||
version_pins = get_version_pins() | ||
self.assertFalse(version_pins) |