Skip to content

Commit 8d05268

Browse files
authored
Merge pull request #45 from chavarera/main
local file support added
2 parents 1413a49 + 2095045 commit 8d05268

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

s_tool/utils.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ def get_session(driver: webdriver) -> str:
2222
return driver.session_id
2323

2424

25+
def is_local(path: str) -> str:
26+
"""Return valid URL path for file
27+
28+
Args:
29+
path (str): normal path or URL
30+
31+
Returns:
32+
str: Modified file path if local file
33+
Returns path as it is if URL
34+
"""
35+
import os
36+
37+
URL = path
38+
if os.path.exists(path) or path.startswith("file"):
39+
if not URL.startswith("file"):
40+
URL = f"file://{URL}"
41+
return URL
42+
43+
2544
def visit(driver: webdriver, url: str) -> None:
2645
"""Visit given url
2746
@@ -32,7 +51,7 @@ def visit(driver: webdriver, url: str) -> None:
3251
Returns:
3352
None
3453
"""
35-
driver.get(url)
54+
driver.get(is_local(url))
3655

3756

3857
def page_source(driver: webdriver) -> str:

tests/test_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Test related to utilities
3+
"""
4+
import os
5+
6+
from s_tool.utils import is_local
7+
8+
9+
def test_local_path():
10+
"""test local file path or URL"""
11+
URL_PATH = "http://www.google.com"
12+
URL_PATH1 = "www.google.com"
13+
LOCAL_PATH = "tests/index.html"
14+
15+
assert URL_PATH == is_local(URL_PATH)
16+
assert "file" in is_local(os.path.abspath(LOCAL_PATH))
17+
assert URL_PATH1 == is_local(URL_PATH1)

0 commit comments

Comments
 (0)