From 1a6938039e9eb3151a2cec239cfd9a0d90abd33a Mon Sep 17 00:00:00 2001 From: Guionardo Furlan Date: Fri, 24 Jun 2022 17:48:31 -0300 Subject: [PATCH 1/2] Fixed pipeline --- .github/workflows/python-publish.yml | 2 +- gs/cache/memory_cache.py | 1 + tests/cache/test_cache.py | 3 +++ tests/dotenv/test_dotenv.py | 19 ++++++++++++------- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 206a1d6..be9786d 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -8,7 +8,7 @@ name: Upload Python Package -on: +on: release: types: [published] diff --git a/gs/cache/memory_cache.py b/gs/cache/memory_cache.py index 6c7c214..5024c03 100644 --- a/gs/cache/memory_cache.py +++ b/gs/cache/memory_cache.py @@ -19,6 +19,7 @@ def get(self, key: str) -> Union[str, None]: if valid_until > datetime.datetime.now(): return value del self.cache[key] + return None def set(self, key: str, value: str, ttl: datetime.timedelta = datetime.timedelta(seconds=0)) -> None: diff --git a/tests/cache/test_cache.py b/tests/cache/test_cache.py index 2a8d1b2..3a44581 100644 --- a/tests/cache/test_cache.py +++ b/tests/cache/test_cache.py @@ -10,14 +10,17 @@ class TestCache(unittest.TestCase): """Test Caches""" def test_unknown_cache(self): + """Asserts uknown cache type raises exception""" with self.assertRaises(Exception): get_cache('unknown') def test_memory_cache(self): + """Test memory cache""" cache = get_cache('memory') self._test_cache(cache, MemoryCache) def test_file_cache(self): + """Test file cache""" with tempfile.TemporaryDirectory() as tmpdir: cache = get_cache(f'path://{tmpdir}') self._test_cache(cache, FileCache) diff --git a/tests/dotenv/test_dotenv.py b/tests/dotenv/test_dotenv.py index b27996a..0053b99 100644 --- a/tests/dotenv/test_dotenv.py +++ b/tests/dotenv/test_dotenv.py @@ -1,3 +1,5 @@ +"""Test dotenv module""" +import os import unittest import tempfile @@ -5,24 +7,27 @@ class TestDotEnv(unittest.TestCase): + """Test dotenv""" def test_just_extra_source(self): + """Validates extra_source argument""" - with self.assertLogs('gs.dotenv', level='INFO') as cm: + with self.assertLogs('gs.dotenv', level='INFO') as logs: self.assertTrue( load_env(extra_source={'TEST_DOTENV': 'test'}, verbose=True)) self.assertEqual( - cm.output, ['INFO:gs.dotenv:load_env(extra_source={\'TEST_DOTENV\': \'test\'})']) + logs.output, ['INFO:gs.dotenv:load_env(extra_source={\'TEST_DOTENV\': \'test\'})']) def test_envfile(self): + """Validates envfile argument""" with tempfile.NamedTemporaryFile('w', prefix='.env', delete=True) as tmp: tmp.write('TEST_DOTENV=test\n# comment\nTEST_DOTENV2=test2=test3\n') tmp.flush() - with self.assertLogs('gs.dotenv', level='INFO') as cm: - self.assertTrue( - load_env(file_name=tmp.name, verbose=True)) - self.assertEqual( - cm.output, [f"INFO:gs.dotenv:load_env(file_name={tmp.name}) - {{'TEST_DOTENV': 'test', 'TEST_DOTENV2': 'test2=test3'}}"]) + + self.assertTrue(load_env(file_name=tmp.name)) + self.assertEqual('test', os.environ['TEST_DOTENV']) + self.assertEqual('test2=test3', os.environ['TEST_DOTENV2']) def test_unexistent_file(self): + """Validates nonexistent file""" self.assertFalse(load_env(file_name='/tmp/nonexistent.env')) From 84a06c17a9926e8d2e4b9a3d2b0aa6e8f00be974 Mon Sep 17 00:00:00 2001 From: Guionardo Furlan Date: Fri, 24 Jun 2022 17:48:55 -0300 Subject: [PATCH 2/2] Updated version --- gs/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gs/__init__.py b/gs/__init__.py index b4a6326..85d5eae 100644 --- a/gs/__init__.py +++ b/gs/__init__.py @@ -1,5 +1,5 @@ """Package data""" -__version__ = '0.1.3' +__version__ = '0.1.4' __tool_name__ = 'py-gstools' __description__ = 'Tool classes and functions for Guiosoft projects' __author__ = 'Guionardo Furlan'