Created
June 26, 2014 18:33
-
-
Save lita/1af81ec5c9e7cce3cf86 to your computer and use it in GitHub Desktop.
Mocked somewhat fixed
This file contains hidden or 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
class MockStringIO(object): | |
def __init__(self, config_string): | |
self.string_io = io.StringIO() | |
self.string_io.write(config_string) | |
def readlines(self): | |
lines = self.string_io.readlines() | |
self.string_io.seek(0) | |
return lines | |
def __exit__(self, type, value, traceback): | |
return | |
def __enter__(self): | |
return self | |
def get_stringio_config(config_string): | |
return MockStringIO(config_string) | |
""" | |
def get_stringio_config(config_string): | |
s = io.StringIO() | |
s.write(config_string) | |
s.seek(0) | |
return s | |
""" | |
class TurtleConfigTestCase(unittest.TestCase): | |
def tearDown(self): | |
turtle.bye() | |
@patch('builtins.open') | |
def test_config_dict(self, mock_open): | |
mock_open.return_value = get_stringio_config(test_config) | |
results = turtle.config_dict('turtle.cfg') | |
print('skjdfdslk') | |
print(results) | |
""" | |
self.assertTrue(results['width'] == 0.75) | |
self.assertTrue(results['canvwidth'] == 500) | |
self.assertTrue(results['shape'] == 'circle') | |
self.assertTrue(results['pencolor'] == 'red') | |
self.assertTrue(results['visible'] == None) | |
self.assertTrue(results['using_IDLE'] == '') | |
""" | |
@patch('builtins.open') | |
@patch('turtle.isfile') | |
def test_read_config(self, mock_isfile, mock_open): | |
mock_open.return_value = get_stringio_config(test_config) | |
mock_isfile.return_value = True | |
turtle.readconfig(turtle._CFG) | |
self.assertTrue(turtle._CFG['pencolor'] == 'red') | |
self.assertTrue(turtle._CFG['width'] == 0.75) | |
self.assertTrue(turtle._CFG['canvwidth'] == 500) | |
self.assertTrue(turtle._CFG['shape'] == 'circle') | |
self.assertTrue(turtle._CFG['pencolor'] == 'red') | |
self.assertTrue(turtle._CFG['visible'] == None) | |
self.assertTrue(turtle._CFG['using_IDLE'] == '') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment