This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
forked from diffplug/selfie
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed testing to reflect kotlin code and added a way to access the …
…private variables
- Loading branch information
1 parent
3ba9c3f
commit 4e73dd7
Showing
2 changed files
with
95 additions
and
174 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,175 +1,90 @@ | ||
from selfie_lib import SourceFile | ||
|
||
|
||
def test_todo(): | ||
source_file = SourceFile("UnderTest.py", ".toBe_TODO()") | ||
assert str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe_TODO()" | ||
assert str(source_file.parse_to_be_like(1).arg) == "" | ||
|
||
source_file = SourceFile("UnderTest.py", " .toBe_TODO() ") | ||
assert str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe_TODO()" | ||
assert str(source_file.parse_to_be_like(1).arg) == "" | ||
|
||
source_file = SourceFile("UnderTest.py", " .toBe_TODO( ) ") | ||
assert ( | ||
str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe_TODO( )" | ||
) | ||
assert str(source_file.parse_to_be_like(1).arg) == "" | ||
|
||
source_file = SourceFile("UnderTest.py", " .toBe_TODO( \n ) ") | ||
assert ( | ||
str(source_file.parse_to_be_like(1).function_call_plus_arg) | ||
== ".toBe_TODO( \n )" | ||
) | ||
assert str(source_file.parse_to_be_like(1).arg) == "" | ||
|
||
|
||
def test_numeric(): | ||
source_file = SourceFile("UnderTest.py", ".toBe(7)") | ||
assert str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe(7)" | ||
assert str(source_file.parse_to_be_like(1).arg) == "7" | ||
|
||
source_file = SourceFile("UnderTest.py", " .toBe(7)") | ||
assert str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe(7)" | ||
assert str(source_file.parse_to_be_like(1).arg) == "7" | ||
|
||
source_file = SourceFile("UnderTest.py", ".toBe(7) ") | ||
assert str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe(7)" | ||
assert str(source_file.parse_to_be_like(1).arg) == "7" | ||
def python_test(source_raw, function_call_plus_arg_raw, arg_raw=""): | ||
source = source_raw.replace("'", '"') | ||
function_call_plus_arg = function_call_plus_arg_raw.replace("'", '"') | ||
arg = arg_raw.replace("'", '"') | ||
parsed = SourceFile("UnderTest.py", source) | ||
to_be_literal = parsed.parse_to_be_like(1) | ||
assert to_be_literal._get_function_call_plus_arg() == function_call_plus_arg | ||
assert to_be_literal._get_arg() == arg | ||
|
||
source_file = SourceFile("UnderTest.py", " .toBe(7) ") | ||
assert str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe(7)" | ||
assert str(source_file.parse_to_be_like(1).arg) == "7" | ||
|
||
source_file = SourceFile("UnderTest.py", " .toBe( 7 ) ") | ||
assert str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe( 7 )" | ||
assert str(source_file.parse_to_be_like(1).arg) == "7" | ||
|
||
source_file = SourceFile("UnderTest.py", " .toBe(\n7) ") | ||
assert str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe(\n7)" | ||
assert str(source_file.parse_to_be_like(1).arg) == "7" | ||
def python_test_error(source_raw, error_msg): | ||
try: | ||
python_test(source_raw, "unusedArg") | ||
except AssertionError as e: | ||
assert str(e) == error_msg | ||
|
||
source_file = SourceFile("UnderTest.py", " .toBe(7\n) ") | ||
assert str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe(7\n)" | ||
assert str(source_file.parse_to_be_like(1).arg) == "7" | ||
|
||
def todo(): | ||
python_test(".toBe_TODO()", ".toBe_TODO()", "") | ||
python_test(" .toBe_TODO() ", ".toBe_TODO()", "") | ||
python_test(" .toBe_TODO( ) ", ".toBe_TODO( )", "") | ||
python_test(" .toBe_TODO( \n ) ", ".toBe_TODO( \n )", "") | ||
|
||
def test_single_line_string(): | ||
source_file = SourceFile("UnderTest.py", ".toBe('7')") | ||
assert str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe('7')" | ||
assert str(source_file.parse_to_be_like(1).arg) == "'7'" | ||
|
||
source_file = SourceFile("UnderTest.py", ".toBe('')") | ||
assert str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe('')" | ||
assert str(source_file.parse_to_be_like(1).arg) == "''" | ||
def numeric(): | ||
python_test(".toBe(7)", ".toBe(7)", "7") | ||
python_test(" .toBe(7)", ".toBe(7)", "7") | ||
python_test(".toBe(7) ", ".toBe(7)", "7") | ||
python_test(" .toBe(7) ", ".toBe(7)", "7") | ||
python_test(" .toBe( 7 ) ", ".toBe( 7 )", "7") | ||
python_test(" .toBe(\n7) ", ".toBe(\n7)", "7") | ||
python_test(" .toBe(7\n) ", ".toBe(7\n)", "7") | ||
|
||
source_file = SourceFile("UnderTest.py", ".toBe( '' )") | ||
assert str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe( '' )" | ||
assert str(source_file.parse_to_be_like(1).arg) == "''" | ||
|
||
source_file = SourceFile("UnderTest.py", ".toBe( \n '' \n )") | ||
assert ( | ||
str(source_file.parse_to_be_like(1).function_call_plus_arg) | ||
== ".toBe( \n '' \n )" | ||
) | ||
assert str(source_file.parse_to_be_like(1).arg) == "''" | ||
def single_line_string(): | ||
python_test(".toBe('7')", "'7'") | ||
python_test(".toBe('')", "''") | ||
python_test(".toBe( '' )", "''") | ||
python_test(".toBe( \n '' \n )", "''") | ||
python_test(".toBe( \n '78' \n )", "'78'") | ||
python_test(".toBe('\\'')", "'\\''") | ||
|
||
source_file = SourceFile("UnderTest.py", ".toBe( \n '78' \n )") | ||
assert ( | ||
str(source_file.parse_to_be_like(1).function_call_plus_arg) | ||
== ".toBe( \n '78' \n )" | ||
) | ||
assert str(source_file.parse_to_be_like(1).arg) == "'78'" | ||
|
||
source_file = SourceFile("UnderTest.py", ".toBe('\\'')") | ||
assert str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe('\\'')" | ||
assert str(source_file.parse_to_be_like(1).arg) == "'\\''" | ||
def multi_line_string(): | ||
python_test(".toBe('''7''')", "'''7'''") | ||
python_test(".toBe(''' 7 ''')", "''' 7 '''") | ||
python_test(".toBe('''\n7\n''')", "'''\n7\n'''") | ||
python_test(".toBe(''' ' '' ' ''')", "''' ' '' ' '''") | ||
|
||
|
||
def test_multi_line_string(): | ||
source_file = SourceFile("UnderTest.py", ".toBe('''7''')") | ||
assert ( | ||
str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe('''7''')" | ||
def error_unclosed(): | ||
python_test_error( | ||
".toBe(", "Appears to be an unclosed function call `.toBe()` on line 1" | ||
) | ||
assert str(source_file.parse_to_be_like(1).arg) == "'''7'''" | ||
|
||
source_file = SourceFile("UnderTest.py", ".toBe('''7''')") | ||
assert ( | ||
str(source_file.parse_to_be_like(1).function_call_plus_arg) == ".toBe('''7''')" | ||
python_test_error( | ||
".toBe( \n ", "Appears to be an unclosed function call `.toBe()` on line 1" | ||
) | ||
assert str(source_file.parse_to_be_like(1).arg) == "'''7'''" | ||
|
||
# source_file = SourceFile("UnderTest.py", ".toBe('''\n7\n''')") | ||
# assert ( | ||
# str(source_file.parse_to_be_like(1).function_call_plus_arg) | ||
# == ".toBe('''\n7\n''')" | ||
# ) | ||
# assert str(source_file.parse_to_be_like(1).arg) == "'''\n7\n'''" | ||
|
||
# source_file = SourceFile("UnderTest.py", ".toBe(''' ' '' ' ''')") | ||
# assert ( | ||
# str(source_file.parse_to_be_like(1).function_call_plus_arg) | ||
# == ".toBe(''' ' '' ' ''')" | ||
# ) | ||
# assert str(source_file.parse_to_be_like(1).arg) == "''' ' '' ' '''" | ||
|
||
|
||
def test_error_unclosed(): | ||
source_file = SourceFile("UnderTest.py", ".toBe(") | ||
assert_raises_error( | ||
source_file, "Appears to be an unclosed function call `.toBe(` on line 1" | ||
python_test_error( | ||
".toBe_TODO(", | ||
"Appears to be an unclosed function call `.toBe_TODO()` on line 1", | ||
) | ||
|
||
source_file = SourceFile("UnderTest.py", ".toBe( \n ") | ||
assert_raises_error( | ||
source_file, "Appears to be an unclosed function call `.toBe(` on line 1" | ||
python_test_error( | ||
".toBe_TODO( \n ", | ||
"Appears to be an unclosed function call `.toBe_TODO()` on line 1", | ||
) | ||
|
||
source_file = SourceFile("UnderTest.py", ".toBe_TODO(") | ||
assert_raises_error( | ||
source_file, "Appears to be an unclosed function call `.toBe_TODO(` on line 1" | ||
python_test_error( | ||
".toBe_TODO(')", 'Appears to be an unclosed string literal `"` on line 1' | ||
) | ||
|
||
source_file = SourceFile("UnderTest.py", ".toBe_TODO( \n ") | ||
assert_raises_error( | ||
source_file, "Appears to be an unclosed function call `.toBe_TODO(` on line 1" | ||
python_test_error( | ||
".toBe_TODO(''')", | ||
'Appears to be an unclosed multiline string literal `"""` on line 1', | ||
) | ||
|
||
# source_file = SourceFile("UnderTest.py", ".toBe_TODO(')") | ||
# assert_raises_error( | ||
# source_file, 'Appears to be an unclosed string literal `"` on line 1' | ||
# ) | ||
|
||
# source_file = SourceFile("UnderTest.py", ".toBe_TODO(''')") | ||
# assert_raises_error( | ||
# source_file, | ||
# 'Appears to be an unclosed multiline string literal `"""` on line 1', | ||
# ) | ||
|
||
|
||
def test_error_non_primitive(): | ||
source_file = SourceFile("UnderTest.py", ".toBe(1 + 1)") | ||
assert_raises_error( | ||
source_file, | ||
"Non-primitive literal in `.toBe(` starting at line 1: error for character `+` on line 1", | ||
def error_non_primitive(): | ||
python_test_error( | ||
".toBe(1 + 1)", | ||
"Non-primitive literal in `.toBe()` starting at line 1: error for character `+` on line 1", | ||
) | ||
|
||
source_file = SourceFile("UnderTest.py", ".toBe('1' + '1')") | ||
assert_raises_error( | ||
source_file, | ||
"Non-primitive literal in `.toBe(` starting at line 1: error for character `+` on line 1", | ||
python_test_error( | ||
".toBe('1' + '1')", | ||
"Non-primitive literal in `.toBe()` starting at line 1: error for character `+` on line 1", | ||
) | ||
|
||
source_file = SourceFile("UnderTest.py", ".toBe('''1''' + '''1''')") | ||
assert_raises_error( | ||
source_file, | ||
"Non-primitive literal in `.toBe(` starting at line 1: error for character `+` on line 1", | ||
python_test_error( | ||
".toBe('''1''' + '''1''')", | ||
"Non-primitive literal in `.toBe()` starting at line 1: error for character `+` on line 1", | ||
) | ||
|
||
|
||
def assert_raises_error(source_file, error_msg): | ||
try: | ||
source_file.parse_to_be_like(1) | ||
assert False, "Expected an AssertionError, but none was raised." | ||
except AssertionError as e: | ||
assert str(e) == error_msg |