Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task 1 (Ievgen Shumelchyk) #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,8 @@ venv.bak/
.mypy_cache/
.idea/*
*.solution`

# log data
pylint_init.txt
pylint_test.txt
test.txt
10 changes: 2 additions & 8 deletions highlighter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,15 @@ def markup_text(text):
This is supplementary method that helps you to wrap marked text in tags.
@:param text - string text to be marked
@:return marked text, e.g., <mark>highlighted text</mark>."""
result = text

# TODO: add an implementation

result = "<mark>" + text + "</mark>"
return result

def highlight_text(text, expr):
"""Markup searched string in given text.
@:param text - string text to be processed (e.g., 'The sun in the sky')
@:param expr - string pattern to be searched in the text (e.g., 'th')
@:return marked text, e.g., "<mark>Th</mark>e sun in <mark>th</mark>e sky"."""
result = text

# TODO: add an implementation

result = text.replace(expr, markup_text(expr))
return result

return app
9 changes: 5 additions & 4 deletions tests/test_highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class HighlightTest(unittest.TestCase):
def setUp(self):
"""This method is called each time the test routine run"""
self.app = create_app().test_client()
# TODO: add the missing test data in this routine
self.highlighted_text = b'Sample <mark>text</mark> to be highlighted'
self.highlight_text = b'Python'
self.text_data = b'Sample Python application'
self.highlighted_text = b'Sample <mark>Python</mark> application'

def tearDown(self):
"""This method is called after the test routine is finished
Expand All @@ -24,6 +25,6 @@ def tearDown(self):

def test_markup_text(self):
"""Test markup process"""
response = self.app.post('/', data={'search': self.search_text,
'text': self.text})
response = self.app.post('/', data={'search': self.highlight_text,
'text': self.text_data})
self.assertIn(self.highlighted_text, response.data)