Skip to content

Commit

Permalink
Ignore common file extensions in ignored files warning (BugFix) (#1583)
Browse files Browse the repository at this point in the history
* Add ignore list for ignored files warning

* Add unit tests
  • Loading branch information
pedro-avalos authored Nov 8, 2024
1 parent 2cc3162 commit 498c548
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
20 changes: 20 additions & 0 deletions checkbox-ng/plainbox/impl/secure/providers/test_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from plainbox.impl.secure.providers.v1 import Provider1
from plainbox.impl.secure.providers.v1 import Provider1Definition
from plainbox.impl.secure.providers.v1 import Provider1PlugIn
from plainbox.impl.secure.providers.v1 import ProviderContentLoader
from plainbox.impl.secure.providers.v1 import UnitPlugIn
from plainbox.impl.secure.providers.v1 import VersionValidator
from plainbox.impl.secure.rfc822 import FileTextSource
Expand Down Expand Up @@ -911,3 +912,22 @@ def test_init_bindtextdomain__not_called(self, mock_gettext):
base_dir=self.BASE_DIR,
)
self.assertEqual(mock_gettext.bindtextdomain.call_args_list, [])


@mock.patch("plainbox.impl.secure.providers.v1.logger")
class ProviderContentLoaderTests(TestCase):
def test__warn_ignored_file_warned(self, logger_mock):
self_mock = mock.MagicMock()
self_mock.provider.units_dir = "/some/path"
ProviderContentLoader._warn_ignored_file(
self_mock, "/some/path/script.py"
)
self.assertTrue(logger_mock.warning.called)

def test__warn_ignored_file_ignored(self, logger_mock):
self_mock = mock.MagicMock()
self_mock.provider.units_dir = "/some/path"
ProviderContentLoader._warn_ignored_file(
self_mock, "/some/path/__pycache__/script.pyc"
)
self.assertFalse(logger_mock.warning.called)
43 changes: 20 additions & 23 deletions checkbox-ng/plainbox/impl/secure/providers/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,31 +661,28 @@ def load(self, plugin_kwargs):

def _warn_ignored_file(self, filename):
"""
Print an warning message for each file that is skipped at loading
Do not print warning for all skipped files, do it only for file that is located
inside a official provider folder (bin, data, units, ..).
"""
if (
(
self.provider.units_dir
and filename.startswith(self.provider.units_dir)
)
or (
self.provider.jobs_dir
and filename.startswith(self.provider.jobs_dir)
Print a warning message for each file that is skipped at loading.
Do not print warning for all skipped files. Ignore common text formats,
compiled bytcode python files, etc. Files to warn about should also be
located inside an official provider folder (bin, data, units, ...).
"""
if all(
not filename.endswith(ext)
for ext in (
".md",
".txt",
".pyc",
)
or (
self.provider.data_dir
and filename.startswith(self.provider.data_dir)
)
or (
self.provider.bin_dir
and filename.startswith(self.provider.bin_dir)
)
or (
self.provider.locale_dir
and filename.startswith(self.provider.locale_dir)
) and any(
filename.startswith(path)
for path in (
self.provider.units_dir,
self.provider.jobs_dir,
self.provider.data_dir,
self.provider.bin_dir,
self.provider.locale_dir,
)
if path
):
logger.warning("Skipped file: %s", filename)

Expand Down

0 comments on commit 498c548

Please sign in to comment.