-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to docs, convert formatter to a Class
- Loading branch information
1 parent
c49f672
commit 31ea885
Showing
4 changed files
with
120 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,41 @@ | ||
import vestaboard.formatter as formatter | ||
from vestaboard.formatter import Formatter | ||
|
||
validCharacters = [ | ||
[63, 64, 65, 66, 67, 68, 69, 63, 64, 65, 66, 67, 68, 69, 63, 64, 65, 66, 67, 68, 69, 63], | ||
[64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64], | ||
[65, 0, 0, 0, 8, 1, 16, 16, 25, 0, 2, 9, 18, 20, 8, 4, 1, 25, 0, 0, 0, 65], | ||
[66, 0, 0, 0, 0, 0, 0, 0, 13, 9, 14, 1, 20, 15, 37, 0, 0, 0, 0, 0, 0, 66], | ||
[67, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67], | ||
[68, 69, 63, 64, 65, 66, 67, 68, 69, 63, 64, 65, 66, 67, 68, 69, 63, 64, 65, 66, 67, 68] | ||
] | ||
|
||
validCharactersResult= { | ||
'characters': validCharacters | ||
} | ||
|
||
def test_standard_formatting(): | ||
assert formatter.standard('Love is all you need') == {'text': 'Love is all you need'}, 'Should return a dict with a "text" key and the passed in value.' | ||
assert Formatter._standard('Love is all you need') == {'text': 'Love is all you need'}, 'Should return a dict with a "text" key and the passed in value.' | ||
|
||
def test_raw_formatting(): | ||
assert Formatter._raw(validCharacters) == validCharactersResult, 'Should return a dict with a "characters" key and the passed in list of lists as the value.' | ||
|
||
def test_character_conversion_by_letter(): | ||
assert Formatter.convert('test') == [20, 5, 19, 20], 'Should convert by letter into a list.' | ||
|
||
def test_character_ignores_case(): | ||
Formatter.convert('tHiS Is A sCHEdulEd TESt') | ||
|
||
def test_character_conversion_by_word(): | ||
assert Formatter.convert('test message', byWord=True) == [[20, 5, 19, 20], [13, 5, 19, 19, 1, 7, 5]], 'Should return a list with nested lists - each nested list should contain the character codes.' | ||
|
||
def test_convert_line_with_centering(): | ||
assert len(Formatter.convertLine('test message')) == 22, 'Should return a list with 22 elements' | ||
assert Formatter.convertLine('test message') == [0, 0, 0, 0, 0, 20, 5, 19, 20, 0, 13, 5, 19, 19, 1, 7, 5, 0, 0, 0, 0, 0], 'Should add padding to reach 22 characters' | ||
|
||
def test_convert_line_left_justified(): | ||
assert len(Formatter.convertLine('Oh hi!', left=True)) == 22, 'Should return a list with 22 elements' | ||
assert Formatter.convertLine('Oh hi!', left=True) == [15, 8, 0, 8, 9, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'Should left justify up to 22 characters' | ||
|
||
def test_convert_line_right_justified(): | ||
assert len(Formatter.convertLine('Oh hi!', right=True)) == 22, 'Should return a list with 22 elements' | ||
assert Formatter.convertLine('Oh hi!', right=True) == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 8, 0, 8, 9, 37], 'Should left justify up to 22 characters' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,40 @@ | ||
def standard(text): | ||
return {'text': text} | ||
from vestaboard.characters import characters | ||
|
||
def raw(charList): | ||
return {'characters': charList} | ||
class Formatter: | ||
def _standard(text): | ||
return {'text': text} | ||
|
||
def _raw(charList): | ||
return {'characters': charList} | ||
|
||
def convert(inputString, byLetter=True, byWord=False): | ||
inputString = inputString.lower() | ||
converted = [] | ||
if byWord: | ||
wordList = inputString.split(' ') | ||
for word in wordList: | ||
convertedWord = [] | ||
for letter in word: | ||
convertedWord.append(characters[letter]) | ||
converted.append(convertedWord) | ||
elif byLetter: | ||
for letter in inputString: | ||
converted.append(characters[letter]) | ||
|
||
return converted | ||
|
||
def convertLine(inputString, center=True, left=False, right=False): | ||
inputString = inputString.lower() | ||
converted = [] | ||
if len(inputString) > 22: | ||
return Exception('Convert line method takes in a string less than or equal to 22 characters.') | ||
if left: | ||
inputString = inputString.ljust(22) | ||
elif right: | ||
inputString = inputString.rjust(22) | ||
elif center: | ||
inputString = inputString.center(22) | ||
for letter in inputString: | ||
converted.append(characters[letter]) | ||
|
||
return converted |