Skip to content

Commit

Permalink
replace natsorted with sorted for file caches
Browse files Browse the repository at this point in the history
with sorted the files will be sort by the timestamp, not the file names
  • Loading branch information
ryanpdx committed Apr 1, 2024
1 parent 2726c1d commit a7490e8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion olaf/common/oresat_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def new_oresat_file(keyword: str, card: str = "", date: float = -1.0, ext: str = "") -> str:
"""
Convience function for making valid oresat file_names
Convenience function for making valid oresat file names.
Parameters
----------
Expand Down
5 changes: 2 additions & 3 deletions olaf/common/oresat_file_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pathlib import Path
from threading import Lock

from . import natsorted
from .oresat_file import OreSatFile


Expand Down Expand Up @@ -37,7 +36,7 @@ def __init__(self, dir_path: str):
self._data.append(oresat_file)
except Exception: # pylint: disable=W0718
remove(self._dir + f) # invalid file name
self._data = natsorted(self._data)
self._data = sorted(self._data)

def __len__(self) -> int:
with self._lock:
Expand Down Expand Up @@ -78,7 +77,7 @@ def add(self, file_path: str, consume: bool = False):

if not overwrite:
self._data.append(oresat_file)
self._data = natsorted(self._data)
self._data = sorted(self._data)

def remove(self, file_name: str):
"""Remove a file from cache
Expand Down
4 changes: 2 additions & 2 deletions tests/internals/resources/test_fread.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import unittest
from os.path import basename

from olaf import natsorted, new_oresat_file
from olaf import new_oresat_file
from olaf._internals.resources.fread import FreadResource

from . import MockApp
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_read(self):
self.assertEqual(self.app.sdo_read(index, subindex_file_data).decode(), file_data2)
self.assertEqual(self.app.sdo_read(index, subindex_len), 2)
file_names = json.loads(self.app.sdo_read(index, subindex_files_json))
self.assertListEqual(file_names, natsorted([file_name, file_name2]))
self.assertListEqual(file_names, [file_name, file_name2])

# delete the first file
self.app.sdo_write(index, subindex_file_name, basename(file_name))
Expand Down
4 changes: 2 additions & 2 deletions tests/internals/resources/test_fwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from os import remove
from os.path import basename

from olaf import natsorted, new_oresat_file
from olaf import new_oresat_file
from olaf._internals.resources.fwrite import FwriteResource

from . import MockApp
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_write(self):
self.assertEqual(len(self.app.node.fwrite_cache), 2)
self.assertEqual(self.app.sdo_read(index, subindex_len), 2)
file_names = json.loads(self.app.sdo_read(index, subindex_files_json))
self.assertListEqual(file_names, natsorted([file_name, file_name2]))
self.assertListEqual(file_names, [file_name, file_name2])

# remove test file
remove(file_path2)

0 comments on commit a7490e8

Please sign in to comment.