|
1 | 1 | import pytest |
2 | | -from doc_generator.utils.file_utils import get_file_name, github_file_url, github_folder_url |
| 2 | +from doc_generator.utils.file_utils import ( |
| 3 | + get_file_name, |
| 4 | + github_file_url, |
| 5 | + github_folder_url, |
| 6 | +) |
| 7 | + |
3 | 8 |
|
4 | 9 | def test_get_file_name_with_delimiter(): |
5 | 10 | assert get_file_name("example.txt") == "example.md" |
6 | 11 |
|
| 12 | + |
7 | 13 | def test_get_file_name_without_delimiter(): |
8 | 14 | assert get_file_name("example") == "example.md" |
9 | 15 |
|
| 16 | + |
10 | 17 | def test_get_file_name_custom_delimiter(): |
11 | 18 | assert get_file_name("example-text", delimiter="-") == "example.md" |
12 | 19 |
|
| 20 | + |
13 | 21 | def test_get_file_name_no_delimiter_custom_extension(): |
14 | 22 | assert get_file_name("example", extension=".txt") == "example.txt" |
15 | 23 |
|
| 24 | + |
16 | 25 | def test_get_file_name_with_delimiter_custom_extension(): |
17 | 26 | assert get_file_name("example.txt", extension=".txt") == "example.txt" |
18 | 27 |
|
| 28 | + |
19 | 29 | def test_get_file_name_with_multiple_delimiters(): |
20 | 30 | assert get_file_name("my.example.txt") == "my.example.md" |
21 | 31 |
|
| 32 | + |
22 | 33 | def test_get_file_name_with_no_delimiter_and_no_extension(): |
23 | 34 | assert get_file_name("example", extension="") == "example" |
24 | 35 |
|
| 36 | + |
25 | 37 | def test_get_file_name_with_delimiter_and_no_extension(): |
26 | 38 | assert get_file_name("example.txt", extension="") == "example" |
27 | 39 |
|
| 40 | + |
28 | 41 | def test_get_file_name_empty_input(): |
29 | 42 | assert get_file_name("") == ".md" |
30 | 43 |
|
| 44 | + |
31 | 45 | def test_get_file_name_delimiter_not_in_input(): |
32 | 46 | assert get_file_name("example", delimiter="/") == "example.md" |
33 | 47 |
|
| 48 | + |
34 | 49 | def test_get_file_name_delimiter_at_end(): |
35 | 50 | assert get_file_name("example.", delimiter=".") == "example.md" |
36 | 51 |
|
| 52 | + |
37 | 53 | def test_get_file_name_delimiter_at_start(): |
38 | 54 | assert get_file_name(".example", delimiter=".") == ".md" |
39 | 55 |
|
| 56 | + |
40 | 57 | def test_get_file_name_delimiter_multiple_occurrences(): |
41 | 58 | assert get_file_name("my.file.name.txt") == "my.file.name.md" |
42 | 59 |
|
| 60 | + |
43 | 61 | def test_github_file_url_link_hosted_true(): |
44 | 62 | github_root = "https://github.com/user/repo" |
45 | 63 | input_root = "/home/user/project" |
46 | 64 | file_path = "/home/user/project/docs/file.md" |
47 | 65 | link_hosted = True |
48 | 66 | expected_url = f"{github_root}/{file_path[len(input_root)-1:]}" |
49 | | - assert github_file_url(github_root, input_root, file_path, link_hosted) == expected_url |
| 67 | + assert ( |
| 68 | + github_file_url(github_root, input_root, file_path, link_hosted) |
| 69 | + == expected_url |
| 70 | + ) |
| 71 | + |
50 | 72 |
|
51 | 73 | def test_github_file_url_link_hosted_false(): |
52 | 74 | github_root = "https://github.com/user/repo" |
53 | 75 | input_root = "/home/user/project" |
54 | 76 | file_path = "/home/user/project/docs/file.md" |
55 | 77 | link_hosted = False |
56 | 78 | expected_url = f"{github_root}/blob/master/{file_path[len(input_root)-1:]}" |
57 | | - assert github_file_url(github_root, input_root, file_path, link_hosted) == expected_url |
| 79 | + assert ( |
| 80 | + github_file_url(github_root, input_root, file_path, link_hosted) |
| 81 | + == expected_url |
| 82 | + ) |
| 83 | + |
58 | 84 |
|
59 | 85 | def test_github_file_url_empty_input_root(): |
60 | 86 | github_root = "https://github.com/user/repo" |
61 | 87 | input_root = "" |
62 | 88 | file_path = "/docs/file.md" |
63 | 89 | link_hosted = False |
64 | 90 | expected_url = f"{github_root}/blob/master/{file_path[-1:]}" |
65 | | - assert github_file_url(github_root, input_root, file_path, link_hosted) == expected_url |
| 91 | + assert ( |
| 92 | + github_file_url(github_root, input_root, file_path, link_hosted) |
| 93 | + == expected_url |
| 94 | + ) |
| 95 | + |
66 | 96 |
|
67 | 97 | def test_github_file_url_empty_file_path(): |
68 | 98 | github_root = "https://github.com/user/repo" |
69 | 99 | input_root = "/home/user/project" |
70 | 100 | file_path = "" |
71 | 101 | link_hosted = False |
72 | 102 | expected_url = f"{github_root}/blob/master/{file_path[len(input_root)-1:]}" |
73 | | - assert github_file_url(github_root, input_root, file_path, link_hosted) == expected_url |
| 103 | + assert ( |
| 104 | + github_file_url(github_root, input_root, file_path, link_hosted) |
| 105 | + == expected_url |
| 106 | + ) |
| 107 | + |
74 | 108 |
|
75 | 109 | def test_github_folder_url_link_hosted_true(): |
76 | 110 | github_root = "https://github.com/user/repo" |
77 | 111 | input_root = "/home/user/project" |
78 | 112 | folder_path = "/home/user/project/docs/" |
79 | 113 | link_hosted = True |
80 | 114 | expected_url = f"{github_root}/{folder_path[len(input_root)-1:]}" |
81 | | - assert github_folder_url(github_root, input_root, folder_path, link_hosted) == expected_url |
| 115 | + assert ( |
| 116 | + github_folder_url(github_root, input_root, folder_path, link_hosted) |
| 117 | + == expected_url |
| 118 | + ) |
| 119 | + |
82 | 120 |
|
83 | 121 | def test_github_folder_url_link_hosted_false(): |
84 | 122 | github_root = "https://github.com/user/repo" |
85 | 123 | input_root = "/home/user/project" |
86 | 124 | folder_path = "/home/user/project/docs/" |
87 | 125 | link_hosted = False |
88 | | - expected_url = f"{github_root}/tree/master/{folder_path[len(input_root)-1:]}" |
89 | | - assert github_folder_url(github_root, input_root, folder_path, link_hosted) == expected_url |
| 126 | + expected_url = ( |
| 127 | + f"{github_root}/tree/master/{folder_path[len(input_root)-1:]}" |
| 128 | + ) |
| 129 | + assert ( |
| 130 | + github_folder_url(github_root, input_root, folder_path, link_hosted) |
| 131 | + == expected_url |
| 132 | + ) |
| 133 | + |
90 | 134 |
|
91 | 135 | def test_github_folder_url_empty_input_root(): |
92 | 136 | github_root = "https://github.com/user/repo" |
93 | 137 | input_root = "" |
94 | 138 | folder_path = "/docs/" |
95 | 139 | link_hosted = False |
96 | 140 | expected_url = f"{github_root}/tree/master/{folder_path[-1:]}" |
97 | | - assert github_folder_url(github_root, input_root, folder_path, link_hosted) == expected_url |
| 141 | + assert ( |
| 142 | + github_folder_url(github_root, input_root, folder_path, link_hosted) |
| 143 | + == expected_url |
| 144 | + ) |
| 145 | + |
98 | 146 |
|
99 | 147 | def test_github_folder_url_empty_folder_path(): |
100 | 148 | github_root = "https://github.com/user/repo" |
101 | 149 | input_root = "/home/user/project" |
102 | 150 | folder_path = "" |
103 | 151 | link_hosted = False |
104 | | - expected_url = f"{github_root}/tree/master/{folder_path[len(input_root)-1:]}" |
105 | | - assert github_folder_url(github_root, input_root, folder_path, link_hosted) == expected_url |
| 152 | + expected_url = ( |
| 153 | + f"{github_root}/tree/master/{folder_path[len(input_root)-1:]}" |
| 154 | + ) |
| 155 | + assert ( |
| 156 | + github_folder_url(github_root, input_root, folder_path, link_hosted) |
| 157 | + == expected_url |
| 158 | + ) |
0 commit comments