def test_PermissionError_with_user_specified_path(self): with patch('builtins.open', mock_open(read_data=_MOCK_CFG)) as m: m.side_effect = PermissionError with self.assertRaises(rcfile.RcFileError) as cm: rcfile.read('/path/to/nondefault/rc') self.assertIn('read', str(cm.exception).lower()) self.assertIn('permission', str(cm.exception).lower())
def test_PermissionError_with_default_path(self): with patch('builtins.open', mock_open(read_data=_MOCK_CFG)) as m: m.side_effect = PermissionError with self.assertRaises(rcfile.RcFileError) as cm: cmds = rcfile.read() self.assertIn('read', str(cm.exception).lower()) self.assertIn('permission', str(cm.exception).lower())
def test_FileNotFoundError_with_default_path(self): with patch('builtins.open', mock_open(read_data=_MOCK_CFG)) as m: m.side_effect = FileNotFoundError cmds = rcfile.read() self.assertEqual(cmds, ())
def test_ignoring_comments_and_empty_lines(self): with patch('builtins.open', mock_open(read_data=_MOCK_CFG)): cmds = rcfile.read() self.assertEqual(tuple(cmds), ('foo bar baz', 'foo', 'faboobarbaz'))