Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File check. Issue235 #250

Merged
merged 6 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ssm/message_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ def _get_messages(self, sort_by_mtime=False):
"""
try:
# Get a list of files under self.directory_path
# in an arbitrary order.
file_name_list = os.listdir(self.directory_path)
# in an arbitrary order (ignoring directories).
file_name_list = [file for file in os.listdir(self.directory_path)
if os.path.isfile(os.path.join(self.directory_path, file))]

if sort_by_mtime:
# Working space to hold the unsorted messages
Expand Down
16 changes: 15 additions & 1 deletion test/test_message_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""This module contains test cases for the MessageDirectory class."""
from __future__ import print_function

import os
import shutil
import tempfile
import time
Expand All @@ -27,7 +28,7 @@ class TestMessageDirectory(unittest.TestCase):

def setUp(self):
"""Create a MessageDirectory class on top of a temporary directory."""
self.tmp_dir = tempfile.mkdtemp(prefix='message_directory')
self.tmp_dir = tempfile.mkdtemp(prefix='message_directory_')
self.message_directory = MessageDirectory(self.tmp_dir)

def test_add_and_get(self):
Expand Down Expand Up @@ -137,6 +138,19 @@ def test_remove(self):
# Check the count method returns the expected value.
self.assertEqual(self.message_directory.count(), 0)

def test_dir_in_dir(self):
"""Check that directories inside the queue are being ignored."""
self.longMessage = True # Include normal unittest output before custom message.

# Add a single test file (closing it to ensure this works on Unix)
handle, _path = tempfile.mkstemp(dir=self.tmp_dir)
os.close(handle)
# Add a directory (to ignore)
tempfile.mkdtemp(prefix='extra_directory_', dir=self.tmp_dir)

self.assertEqual(self.message_directory.count(), 1, "Expected just one file, "
"but greater result implies that directory is being counted.")

def tearDown(self):
"""Remove test directory and all contents."""
try:
Expand Down