Changeset - 66431a3df04a
[Not reviewed]
0 1 0
Lance Edgar (lance) - 3 months ago 2024-08-05 23:13:53
lance@edbob.org
test: fix tests for `AppHandler.get_version()`

for some reason python-configuration is unreliable on certain python
versions? not sure what that's about, but this seems to work..
1 file changed with 12 insertions and 8 deletions:
0 comments (0 inline, 0 general)
tests/test_app.py
Show inline comments
 
@@ -76,20 +76,24 @@ class TestAppHandler(TestCase):
 
    def test_get_version(self):
 
        from importlib.metadata import version
 

	
 
        try:
 
            from sqlalchemy.orm import Query
 
        except ImportError:
 
            pytest.skip("test is not relevant without sqlalchemy")
 

	
 
        # works with "non-native" objects
 
        from config import Configuration
 
        config = Configuration({})
 
        ver = self.app.get_version(obj=config)
 
        self.assertEqual(ver, version('python-configuration'))
 
        query = Query({})
 
        ver = self.app.get_version(obj=query)
 
        self.assertEqual(ver, version('SQLAlchemy'))
 

	
 
        # can override dist via config
 
        self.config.setdefault('rattail.app_dist', 'importlib_metadata')
 
        self.config.setdefault('rattail.app_dist', 'SQLAlchemy')
 
        ver = self.app.get_version()
 
        self.assertEqual(ver, version('importlib_metadata'))
 
        self.assertEqual(ver, version('SQLAlchemy'))
 

	
 
        # but the provided object takes precedence
 
        ver = self.app.get_version(obj=config)
 
        self.assertEqual(ver, version('python-configuration'))
 
        ver = self.app.get_version(obj=query)
 
        self.assertEqual(ver, version('SQLAlchemy'))
 

	
 
        # reset
 
        del self.config.defaults['rattail.app_dist']
0 comments (0 inline, 0 general)