Skip to content

Instantly share code, notes, and snippets.

@blackjack
Created February 24, 2016 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackjack/413061143f1974284d3e to your computer and use it in GitHub Desktop.
Save blackjack/413061143f1974284d3e to your computer and use it in GitHub Desktop.
@mock.patch('__builtin__.open', create=True)
def test_cmd_config_basic_items(self, mock_open):
test = """
# comment
stringkey1 = stringvalue1
stringkey2 = "stringvalue2"
intkey = 1234
floatkey = 56.78
bool1 = yes
bool2 = No
bool3 = y
"""
mock_content = mock.MagicMock()
mock_content.__iter__.return_value = test.split('\n')
mock_open.return_value = mock_content
cfg = config.parse('cmd.conf')
mock_open.assert_called_once_with('cmd.conf')
self.assertFalse('comment' in cfg)
self.assertEqual(cfg['stringkey1'], 'stringvalue1')
self.assertEqual(cfg['stringkey2'], 'stringvalue2')
self.assertEqual(cfg['intkey'], 1234)
self.assertEqual(cfg['floatkey'], 56.78)
self.assertEqual(cfg['bool1'], True)
self.assertEqual(cfg['bool2'], False)
self.assertEqual(cfg['bool3'], True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment