| 1 |
# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 |
# |
| 3 |
# This source code is licensed under the MIT license found in the |
| 4 |
# LICENSE file in the root directory of this source tree. |
| 5 |
|
| 6 |
|
| 7 |
import unittest |
| 8 |
|
| 9 |
from ..buildopts import find_existing_win32_subst_for_path |
| 10 |
|
| 11 |
|
| 12 |
class Win32SubstTest(unittest.TestCase): |
| 13 |
def test_no_existing_subst(self) -> None: |
| 14 |
self.assertIsNone( |
| 15 |
find_existing_win32_subst_for_path( |
| 16 |
r"C:\users\alice\appdata\local\temp\fbcode_builder_getdeps", |
| 17 |
subst_mapping={}, |
| 18 |
) |
| 19 |
) |
| 20 |
self.assertIsNone( |
| 21 |
find_existing_win32_subst_for_path( |
| 22 |
r"C:\users\alice\appdata\local\temp\fbcode_builder_getdeps", |
| 23 |
subst_mapping={"X:\\": r"C:\users\alice\appdata\local\temp\other"}, |
| 24 |
) |
| 25 |
) |
| 26 |
|
| 27 |
def test_exact_match_returns_drive_path(self) -> None: |
| 28 |
self.assertEqual( |
| 29 |
find_existing_win32_subst_for_path( |
| 30 |
r"C:\temp\fbcode_builder_getdeps", |
| 31 |
subst_mapping={"X:\\": r"C:\temp\fbcode_builder_getdeps"}, |
| 32 |
), |
| 33 |
"X:\\", |
| 34 |
) |
| 35 |
self.assertEqual( |
| 36 |
find_existing_win32_subst_for_path( |
| 37 |
r"C:/temp/fbcode_builder_getdeps", |
| 38 |
subst_mapping={"X:\\": r"C:/temp/fbcode_builder_getdeps"}, |
| 39 |
), |
| 40 |
"X:\\", |
| 41 |
) |
| 42 |
|
| 43 |
def test_multiple_exact_matches_returns_arbitrary_drive_path(self) -> None: |
| 44 |
self.assertIn( |
| 45 |
find_existing_win32_subst_for_path( |
| 46 |
r"C:\temp\fbcode_builder_getdeps", |
| 47 |
subst_mapping={ |
| 48 |
"X:\\": r"C:\temp\fbcode_builder_getdeps", |
| 49 |
"Y:\\": r"C:\temp\fbcode_builder_getdeps", |
| 50 |
"Z:\\": r"C:\temp\fbcode_builder_getdeps", |
| 51 |
}, |
| 52 |
), |
| 53 |
("X:\\", "Y:\\", "Z:\\"), |
| 54 |
) |
| 55 |
|
| 56 |
def test_drive_letter_is_case_insensitive(self) -> None: |
| 57 |
self.assertEqual( |
| 58 |
find_existing_win32_subst_for_path( |
| 59 |
r"C:\temp\fbcode_builder_getdeps", |
| 60 |
subst_mapping={"X:\\": r"c:\temp\fbcode_builder_getdeps"}, |
| 61 |
), |
| 62 |
"X:\\", |
| 63 |
) |
| 64 |
|
| 65 |
def test_path_components_are_case_insensitive(self) -> None: |
| 66 |
self.assertEqual( |
| 67 |
find_existing_win32_subst_for_path( |
| 68 |
r"C:\TEMP\FBCODE_builder_getdeps", |
| 69 |
subst_mapping={"X:\\": r"C:\temp\fbcode_builder_getdeps"}, |
| 70 |
), |
| 71 |
"X:\\", |
| 72 |
) |
| 73 |
self.assertEqual( |
| 74 |
find_existing_win32_subst_for_path( |
| 75 |
r"C:\temp\fbcode_builder_getdeps", |
| 76 |
subst_mapping={"X:\\": r"C:\TEMP\FBCODE_builder_getdeps"}, |
| 77 |
), |
| 78 |
"X:\\", |
| 79 |
) |