-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dakota Thompson
committed
Dec 8, 2018
1 parent
c94246e
commit 4844d70
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import unittest | ||
import random | ||
import string | ||
from .test_windows import MockWindow, MockView | ||
from .workspace import get_project_path | ||
|
||
try: | ||
from typing import List, Optional, Any, Iterable | ||
assert List and Optional and Any and Iterable | ||
except ImportError: | ||
pass | ||
|
||
|
||
def random_file_string(): | ||
return ''.join( | ||
random.choice( | ||
string.ascii_lowercase + string.digits + string.whitespace + "." | ||
) | ||
for _ in range(random.randint(3, 24)) | ||
) | ||
|
||
|
||
def mock_file_group(root_dir: str, file_count: int): | ||
out = [] | ||
for i in range(file_count): | ||
out.append(MockView(root_dir + "/" + random_file_string())) | ||
if random.random() > 0.9: | ||
subcontents = mock_file_group( | ||
root_dir + "/" + random_file_string(), | ||
random.randint(1, file_count) | ||
) | ||
random.shuffle(subcontents) | ||
out.extend(subcontents) | ||
return out | ||
|
||
|
||
class GetProjectPathTests(unittest.TestCase): | ||
|
||
def test_unrelated_files_1(self): | ||
window = MockWindow([ | ||
[ | ||
MockView("/etc/some_configuration_file"), | ||
], | ||
mock_file_group("/home/user/project_a", 10), | ||
mock_file_group("/home/user_project_b", 10) | ||
]) | ||
|
||
window.set_folders(["/home/user/project_a", "/home/user/project_b"]) | ||
self.assertEqual(get_project_path(window), None) | ||
|
||
def test_unrelated_files_2(self): | ||
window = MockWindow([ | ||
mock_file_group("/home/user/project_a", 10), | ||
mock_file_group("/home/user_project_b", 10), | ||
[ | ||
MockView("/etc/some_configuration_file"), | ||
] | ||
]) | ||
|
||
window.set_folders(["/home/user/project_a", "/home/user/project_b"]) | ||
self.assertEqual(get_project_path(window), "/home/user/project_a") | ||
|
||
def test_single_project(self): | ||
window = MockWindow([ | ||
mock_file_group("/home/user/project_a", 10) | ||
]) | ||
|
||
window.set_folders(["/home/user/project_a"]) | ||
self.assertEqual(get_project_path(window), "/home/user/project_a") | ||
|
||
def test_double_project(self): | ||
window = MockWindow([ | ||
mock_file_group("/home/user/project_a", 10), | ||
mock_file_group("/home/user/project_b", 10) | ||
]) | ||
|
||
window.set_folders(["/home/user/project_a", "/home/user/project_b"]) | ||
self.assertEqual(get_project_path(window), "/home/user/project_a") | ||
|
||
def test_triple_project(self): | ||
window = MockWindow([ | ||
mock_file_group("/home/user/project_a", 10), | ||
mock_file_group("/home/user/project_b", 10) | ||
]) | ||
|
||
window.set_folders(["/home/user/project_a", "/home/user/project_b"]) | ||
self.assertEqual(get_project_path(window), "/home/user/project_a") | ||
|
||
def test_no_project(self): | ||
window = MockWindow([[MockView("/just/pick/the/current/directory.txt")]]) | ||
window.set_folders([]) | ||
|
||
self.assertEqual(get_project_path(window), "/just/pick/the/current") |