Skip to content

Commit f71db63

Browse files
Pavel.PrudkyPavel.Prudky
Pavel.Prudky
authored and
Pavel.Prudky
committed
Merge branch 'minor_polishing' of https://github.com/datahappy1/notes_app into main
� Conflicts: � notes_app/file.py
2 parents 25dd1c4 + 729849f commit f71db63

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

‎notes_app/file.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
SECTION_FILE_NAME_MINIMAL_CHAR_COUNT = 2
66

77

8+
def get_validated_file_path(file_path):
9+
try:
10+
with open(file=file_path, mode="r"):
11+
pass
12+
except (PermissionError, FileNotFoundError, IsADirectoryError):
13+
return
14+
return file_path
15+
16+
817
class SectionIdentifier:
918
def __init__(
1019
self, defaults, section_file_separator: str = None, section_name: str = None,
@@ -60,7 +69,7 @@ def get_validated_file_path(file_path):
6069
return
6170
return file_path
6271

63-
def _get_validated_raw_data(self, raw_data) -> str:
72+
def _get_validated_raw_data(self, raw_data) -> AnyStr:
6473
matches = re.findall(
6574
self.defaults.DEFAULT_SECTION_FILE_SEPARATOR_REGEX, raw_data
6675
)

‎notes_app/view/notes_view.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
AVAILABLE_SNACK_BAR_COLORS,
3535
)
3636
from notes_app.file import (
37+
get_validated_file_path,
3738
File,
3839
SectionIdentifier,
3940
SECTION_FILE_NEW_SECTION_PLACEHOLDER,
@@ -380,7 +381,7 @@ def execute_open_file(self, file_path):
380381
self.show_error_bar(error_message="Invalid file")
381382
return
382383

383-
validated_file_path = File.get_validated_file_path(file_path)
384+
validated_file_path = get_validated_file_path(file_path=file_path)
384385
if not validated_file_path:
385386
self.show_error_bar(error_message=f"Cannot open the file {file_path}")
386387
return

‎tests/test_unit_file.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
import pytest
44

5-
from notes_app.file import File, SectionIdentifier
5+
from notes_app.file import SectionIdentifier, get_validated_file_path
66

77
from notes_app.defaults import Defaults
88

99
defaults = Defaults()
1010

1111

12+
def test_get_validated_file_path():
13+
file_path = defaults.DEFAULT_NOTES_FILE_NAME
14+
assert get_validated_file_path(file_path=file_path) == file_path
15+
16+
file_path = f"sample_not_existing_{uuid.uuid4().hex}.txt"
17+
assert get_validated_file_path(file_path=file_path) is None
18+
19+
1220
class TestSectionIdentifier:
1321
def test_section_identifier(self):
1422
with pytest.raises(ValueError):
@@ -34,13 +42,6 @@ def test_section_identifier(self):
3442

3543

3644
class TestFile:
37-
def test_get_validated_file_path(self):
38-
file_path = defaults.DEFAULT_NOTES_FILE_NAME
39-
assert File.get_validated_file_path(file_path=file_path) == file_path
40-
41-
file_path = f"sample_not_existing_{uuid.uuid4().hex}.txt"
42-
assert File.get_validated_file_path(file_path=file_path) is None
43-
4445
def test_get_raw_data_content(self, get_file):
4546
raw_data = get_file.get_raw_data_content()
4647
assert (

0 commit comments

Comments
 (0)