Skip to content

Commit

Permalink
add strings tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sirfoga committed Oct 12, 2018
1 parent 1fe882a commit e7ad266
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hal/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__description__ = 'Your swiss knife to perform fast and easy pythonic stuff'
__url__ = 'https://sirfoga.github.io/pyhal/'
__version__ = '10.2.3'
__build__ = 'ac24617a0b69cdcbdc07a81ee3d04179fa6bfb5d'
__build__ = '53d431df7021456d891db9b714bff8290a2a99f7'
__author__ = 'Stefano Fogarollo'
__author_email__ = 'sirfoga@protonmail.com'
__license__ = 'MIT'
Expand Down
2 changes: 1 addition & 1 deletion hal/strings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class String:
def __init__(self, string):
self.string = str(string)

def just_alphanum(self):
def remove_escapes(self):
"""Removes everything except number and letters from string
:return: All numbers and letters in string
Expand Down
72 changes: 72 additions & 0 deletions tests/test_strings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# !/usr/bin/python
# coding: utf_8


"""Tests string implementation"""

from hal.strings.models import String
from hal.tests.utils import BatteryTests


class TestString:
"""Tests linked list"""

def test_remove_escapes(self):
"""Asserts removal of anything except letters and numbers"""

tests = {
"a": "a",
"a\\a1": "a1",
"a\\?A2": "aA2"
}
tests = {
String(key).remove_escapes(): val
for key, val in tests.items()
}

BatteryTests(tests).assert_all()

def test_remove_non_ansi(self):
"""Asserts removal of non ANSI chars"""

tests = {
"a": "a",
"a\x1b[30m": "a",
"a\x1b[31m": "a"
}
tests = {
String(key).remove_non_ansi(): val
for key, val in tests.items()
}

BatteryTests(tests).assert_all()

def test_is_well_formatted(self):
"""Asserts is well formatted"""

tests = {
"a": True,
"a\n": False,
"a\\t": False
}
tests = {
String(key).is_well_formatted(): val
for key, val in tests.items()
}

BatteryTests(tests).assert_all()

def test_strip_bad_html(self):
"""Asserts bad HTML stripper"""

tests = {
"a": True,
"a\n": "a",
"a\\t": "a"
}
tests = {
String(key).strip_bad_html(): val
for key, val in tests.items()
}

BatteryTests(tests).assert_all()

0 comments on commit e7ad266

Please sign in to comment.