Skip to content
Open
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
27 changes: 25 additions & 2 deletions _package/tests/unit_tests/filesystem_pyt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from pathlib import Path
import platform
import shutil
import sys
import tempfile
import unittest
from unittest import mock
import uuid

# 2. Third party modules
Expand Down Expand Up @@ -261,7 +263,28 @@ def test_is_somewhere_below_system_temp(self):
"""Tests filesystem.is_somewhere_below_system_temp()."""
temp_dir = tempfile.mkdtemp()
file_path = _make_bob_file(temp_dir)
self.assertTrue(True, is_somewhere_below_system_temp(file_path))
self.assertTrue(True, is_somewhere_below_system_temp(Path(file_path)))
self.assertTrue(is_somewhere_below_system_temp(file_path))
self.assertTrue(is_somewhere_below_system_temp(Path(file_path)))
Path(file_path).unlink()
shutil.rmtree(temp_dir)

@mock.patch('xms.core.filesystem.filesystem.tempfile')
def test_is_somewhere_below_system_temp_8dot3_names(self, patched_tempfile):
"""
Tests filesystem.is_somewhere_below_system_temp with a shortened file name on Windows.

is_somewhere_below_system_temp uses a function internally that returns 8.3 file paths on Windows, which makes
people with usernames like LongNameThatExtendsPastThe8Dot3Limit get paths like `c:/users/LONGNA~1/AppData...`.
Failure to compensate for that results in callers that pass expanded paths being told their path isn't in the
system temp directory, even though it is.
"""
if sys.platform != 'win32':
return # Only Windows uses 8.3 filenames, and this test needs Windows.

patched_tempfile.gettempdir.return_value = 'c:\\PROGRA~1'

file_path = 'C:/Program Files/somewhere'
self.assertTrue(is_somewhere_below_system_temp(file_path))

file_path = 'C:/PROGRA~1/somewhere'
self.assertTrue(is_somewhere_below_system_temp(file_path))
12 changes: 6 additions & 6 deletions _package/xms/core/filesystem/filesystem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Filesystem utility methods."""

__copyright__ = "(C) Copyright Aquaveo 2019"
__license__ = "All rights reserved"

# 1. Standard python modules
import os
from pathlib import Path
Expand All @@ -13,10 +17,6 @@
# 4. Local modules


__copyright__ = "(C) Copyright Aquaveo 2019"
__license__ = "All rights reserved"


def clear_folder(folder: str | Path) -> None:
"""Deletes everything in folder.

Expand Down Expand Up @@ -159,8 +159,8 @@ def is_somewhere_below_system_temp(filename: str | Path) -> bool:
Returns:
See description.
"""
temp_dir = Path(tempfile.gettempdir())
filepath = Path(filename)
temp_dir = Path(tempfile.gettempdir()).resolve()
filepath = Path(filename).resolve()
return temp_dir in filepath.parents


Expand Down
8 changes: 4 additions & 4 deletions _package/xms/core/time/time_conversion.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Time conversion methods."""

__copyright__ = "(C) Copyright Aquaveo 2022"
__license__ = "All rights reserved"

# 1. Standard python modules
from datetime import datetime
from typing import Optional
Expand All @@ -10,10 +14,6 @@
# 4. Local modules
from .. import _xmscore

__copyright__ = "(C) Copyright Aquaveo 2022"
__license__ = "All rights reserved"


time_cpp = _xmscore.time


Expand Down
Loading