Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.. note::
The generated string will be terminated
at the specified length regardless
of if all the input strings have been fully replicated.
A unit > 1 length may
not be able to be replicated to extend to the full length.
In this situation, the
string will be shorter than the specified length.
Example: unit of 10 characters and a specified length of
25 will contain 2 units for
a total length of 20 characters.
"""
# Reduce the size if possible to extend closer to full length:
if not literal_unit:
unit = utils.reduce_to_unit(unit)
repeats = (length - len(start + end)) // len(unit)
return (start + unit * repeats + end)[0:length]
def test_splitter_2(self):
"""Test splitter function."""
self.assertEqual(
area4.splitter("---", "Hello", "world"), "Hello\n---world\n---"
)
def test_splitter_3(self):
"""Test splitter function."""
self.assertEqual(
area4.splitter(3, "Hello", "world"),
"Hello\n............\nworld\n............\n",
)
def test_splitter_5(self):
"""Test splitter function."""
self.assertEqual(
area4.splitter("xyz", "Hello", "world"), "Hello\nxyzworld\nxyz"
)
def test_splitter_1(self):
"""Test splitter function."""
self.assertEqual(area4.splitter("---", "Hello"), "Hello")
def test_splitter_4(self):
"""Test splitter function."""
self.assertEqual(
area4.splitter(45, "Hello", "world", "fine"),
"Hello\neeeeeeeeeeee\nworld\neeeeeeeeeeee\nfine\neeeeeeeeeeee\n",
)
def test_html_horizontal(self):
"""Test html_horizontal divider."""
self.assertEqual(area4.util.html_horizontal(), "<hr>")
self.assertEqual(area4.util.html_horizontal(closing_tag=False), "<hr>")
def test_html_horizontal(self):
"""Test html_horizontal divider."""
self.assertEqual(area4.util.html_horizontal(), "<hr>")
self.assertEqual(area4.util.html_horizontal(closing_tag=False), "<hr>")
def test_utilities(self):
"""Test util module."""
module = area4.util
self.assertEqual(module.get_divider_character(1), "-")
self.assertEqual(module.get_divider_character(2), "_")
self.assertEqual(module.get_divider_character(3), ".")
self.assertEqual(module.get_divider_character(7), "=")
self.assertEqual(module.get_divider_character(9), "*")
self.assertEqual(module.get_divider_character(13), "~")
self.assertNotEqual(module.get_divider_character(21), "¯\\_(ツ)_/¯")
self.assertEqual(module.get_divider_character(23), "2")
self.assertEqual(module.get_divider_character(24), "3")
self.assertEqual(module.get_divider_character(25), "4")
self.assertEqual(module.get_divider_character(26), "5")
self.assertEqual(module.get_divider_character(27), "6")
self.assertEqual(module.get_divider_character(28), "7")
self.assertEqual(module.get_divider_character(29), "8")
self.assertEqual(module.get_divider_character(30), "9")
self.assertEqual(module.get_divider_character(215), ";")
def test_dividers(self):
"""Test dividers."""
try:
for i in range(len(self.raw_dividers)):
# Try to match the raw divider with the result
# of the function:
if i != 35 and i != 0 and i != 32:
self.assertEqual(
self.raw_dividers[i].replace("\n", ""),
area4.divider(i),
f"Divider number {i} was not the same in the file and in the code. Please ask a maintainer for help.",
)
elif (i == 35 or i == 32) and i != 0:
self.assertNotEqual(self.raw_dividers[i], area4.divider(i))
finally:
pass