Skip to content

Commit 6e97b68

Browse files
author
mwasilew
committed
fix: [general] clean up todos and format code
1 parent a619374 commit 6e97b68

File tree

7 files changed

+18
-17
lines changed

7 files changed

+18
-17
lines changed

image_formatter/image_properties_tag_replacer/image_properties_tag_replacer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def add_tag_properties_to_url(self, tag_token: Token) -> str:
7070
Returns:
7171
str: image tag properties formatted to CSS
7272
"""
73-
if (tag_token.string not in self.image_tags_properties):
73+
if tag_token.string not in self.image_tags_properties:
7474
log.info(f"{ImagePropertiesTagReplacer.name()}: {tag_token.string} is an unknown tag, removing formatting")
7575
return self.curr_token.string
7676
properties = '{: style="'

image_formatter/lexer/lexer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(
5151
self.max_int = max_int
5252
self.tag = tag
5353
self.special_signs = special_signs
54-
self.newline_characters = newline_characters # @TODO add hypothesis tests
54+
self.newline_characters = newline_characters
5555
self.additional_path_signs = additional_path_signs
5656

5757
@classmethod
@@ -305,7 +305,7 @@ def get_url_ending(self, string: str) -> str or None:
305305
return None
306306
string += self.current_char
307307
self.next_char()
308-
while self.is_character() or self.current_char in self.additional_path_signs: # @TODO add hypothesis tests
308+
while self.is_character() or self.current_char in self.additional_path_signs:
309309
string += self.current_char
310310
self.next_char()
311311
log.info(f"{Lexer.name()}: Url ending built successfully.")

tests/image_formatter_plugin/test_e2e_image_formatter_plugin.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from click.testing import CliRunner
3030
from mkdocs.__main__ import build_command
3131

32+
3233
# Adapted from https://github.com/timvink/mkdocs-table-reader-plugin/blame/master/tests/test_build.py
3334
def setup_clean_mkdocs_folder(mkdocs_yml_path, output_path):
3435
"""
@@ -72,6 +73,7 @@ def setup_clean_mkdocs_folder(mkdocs_yml_path, output_path):
7273

7374
return testproject_path
7475

76+
7577
def build_docs_setup(testproject_path):
7678
"""
7779
Runs the `mkdocs build` command
@@ -98,25 +100,28 @@ def build_docs_setup(testproject_path):
98100

99101

100102
def test_given_tags_in_config_then_changes_image_styling(tmp_path):
101-
tmp_proj = setup_clean_mkdocs_folder(
102-
"./resources/e2e_test_files/test_project/mkdocs.yml", tmp_path
103-
)
103+
tmp_proj = setup_clean_mkdocs_folder("./resources/e2e_test_files/test_project/mkdocs.yml", tmp_path)
104104

105105
build_docs_setup(tmp_proj)
106106

107-
page_path = tmp_proj / 'site/index.html'
107+
page_path = tmp_proj / "site/index.html"
108108
contents = page_path.read_text()
109109
assert re.search(r'<img alt="Persian Cat" src="img/Persialainen.jpg" style="height:100px;width:100px" />', contents)
110-
assert re.search(r'<img alt="Siamese Cat" src="img/Siam_lilacpoint.jpg" style="height:200px;width:200px" />', contents)
110+
assert re.search(
111+
r'<img alt="Siamese Cat" src="img/Siam_lilacpoint.jpg" style="height:200px;width:200px" />', contents
112+
)
111113
assert re.search(r'<img alt="Maine Coon" src="img/Maine_coon.jpg" style="height:100px;width:100px" />', contents)
112114

115+
113116
def test_given_unknown_tags_in_config_then_no_styling_applied(tmp_path):
114117
tmp_proj = setup_clean_mkdocs_folder("./resources/e2e_test_files/test_project_unknown_tags/mkdocs.yml", tmp_path)
115118

116119
build_docs_setup(tmp_proj)
117120

118-
page_path = tmp_proj / 'site/index.html'
121+
page_path = tmp_proj / "site/index.html"
119122
contents = page_path.read_text()
120123
assert re.search(r'<img alt="Persian Cat" src="img/Persialainen.jpg" />', contents)
121-
assert re.search(r'<img alt="Siamese Cat" src="img/Siam_lilacpoint.jpg" style="height:200px;width:200px" />', contents)
124+
assert re.search(
125+
r'<img alt="Siamese Cat" src="img/Siam_lilacpoint.jpg" style="height:200px;width:200px" />', contents
126+
)
122127
assert re.search(r'<img alt="Maine Coon" src="img/Maine_coon.jpg" />', contents)

tests/image_properties_tag_replacer/test_image_properties_tag_replacer_exceptions.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from image_formatter.lexer.position import Position
77
from tests.test_helpers import get_all_tags_replacer_results
88

9-
# @ TODO inline global var
109
image_tags_properties = {
1110
"small": {"height": "100px", "width": "100px"},
1211
"small-2": {"height": "110px", "width": "110px"},

tests/image_properties_tag_replacer/test_unit_image_properties_tag_replacer.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from image_formatter.lexer.position import Position
55
from tests.test_helpers import get_all_tags_replacer_results
66

7-
# @ TODO inline global var
87
image_tags_properties = {
98
"small": {"height": "100px", "width": "100px"},
109
"medium": {"height": "150px", "width": "150px"},
@@ -51,7 +50,7 @@ def test_given_only_image_links_then_only_image_links_returned():
5150
assert result == expected_tokens
5251

5352

54-
def test_given_tag_and_url_separated_by_char_then_only_false_returned():
53+
def test_given_tag_and_url_separated_by_char_then_tags_are_unchanged():
5554
mock_lexer = Mock()
5655
mock_lexer.get_token.side_effect = [
5756
Token(TokenType.T_IMAGE_SIZE_TAG, Position(1, 1), "small"),
@@ -72,7 +71,7 @@ def test_given_tag_and_url_separated_by_char_then_only_false_returned():
7271
assert result == expected_tokens
7372

7473

75-
def test_given_no_tags_or_urls_then_only_false_returned():
74+
def test_given_no_tags_or_urls_then_tags_are_unchanged():
7675
mock_lexer = Mock()
7776
mock_lexer.get_token.side_effect = [
7877
Token(TokenType.T_CHAR, Position(1, 1), "*"),
@@ -93,7 +92,7 @@ def test_given_no_tags_or_urls_then_only_false_returned():
9392
assert result == expected_tokens
9493

9594

96-
def test_given_url_and_tag_token_in_reverted_order_then_only_false_returned():
95+
def test_given_url_and_tag_token_in_reverted_order_then_tags_are_unchanged():
9796
mock_lexer = Mock()
9897
mock_lexer.get_token.side_effect = [
9998
Token(TokenType.T_IMAGE_URL, Position(1, 1), "(some/url.png)"),

tests/lexer/test_unit_lexer.py

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ def test_given_only_tags_and_white_chars_then_only_tag_and_white_char_tokens_are
141141
[Position(1, 1), Position(2, 1), Position(2, 2)],
142142
[TokenType.T_WHITE_CHAR, TokenType.T_WHITE_CHAR, TokenType.T_IMAGE_URL],
143143
),
144-
# (" \t(url1.png.url2/url3.jpg)", [Position(1, 4)]), @TODO
145144
],
146145
)
147146
def test_given_only_urls_and_white_chars_then_only_url_and_white_char_tokens_are_returned(text, positions, types):

tests/token_to_string_converter/test_unit_token_to_string_converter.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from image_formatter.image_properties_tag_replacer.image_properties_tag_replacer import ImagePropertiesTagReplacer
55
from image_formatter.token_to_string_converter.token_to_string_converter import TokenToStringConverter
66

7-
# @ TODO inline global var
87
image_tags_properties = {
98
"small": {"height": "100px", "width": "100px"},
109
"small2": {"height": "110px", "width": "110px"},

0 commit comments

Comments
 (0)