Skip to content

Commit

Permalink
TEMP
Browse files Browse the repository at this point in the history
  • Loading branch information
tofu-rocketry committed Oct 9, 2023
1 parent afe46aa commit 6967cd2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions ssm/message_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ 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)
file_name_list = [file for file in os.listdir(self.directory_path) if os.path.isfile(os.path.join(self.directory_path, file))]
#print(file_name_list)

if sort_by_mtime:
# Working space to hold the unsorted messages
Expand All @@ -110,9 +111,10 @@ def _get_messages(self, sort_by_mtime=False):
for (file_name, _mtime) in sorted(unsorted_messages,
key=lambda tup: tup[1]):
# Store the sorted file paths in a class element.
if os.path.isfile(file_name):
if os.path.isfile(os.path.join(self.directory_path, file_name)):
sorted_messages.append(file_name)
else:
print(file_name)
continue

# Return the sorted list.
Expand Down
10 changes: 9 additions & 1 deletion test/test_message_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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 +137,14 @@ 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):
print(self.message_directory.count())
print(self.tmp_dir)
extra_dir = tempfile.mkdtemp(prefix='extra_directory_', dir=self.tmp_dir)
print(extra_dir)
print(self.message_directory.count())


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

0 comments on commit 6967cd2

Please sign in to comment.