Repository: ipython/ipython

Issue:
Application._load_config_files log parameter default fails
The files `examples/tests/embed/embed[1-3].py` are failing with an error like this:

```
Traceback (most recent call last):
  File "embed1.py", line 10, in <module>
    bar(f)
  File "embed1.py", line 8, in bar
    IPython.embed(banner1='check f in globals, foo in locals')
  File "/home/takluyver/.local/lib/python3.3/site-packages/IPython/terminal/embed.py", line 287, in embed
    config = load_default_config()
  File "/home/takluyver/.local/lib/python3.3/site-packages/IPython/terminal/ipapp.py", line 379, in load_default_config
    for cf in Application._load_config_files("ipython_config", path=profile_dir):
  File "/home/takluyver/.local/lib/python3.3/site-packages/IPython/config/application.py", line 527, in _load_config_files
    log.debug("Loaded config file: %s", loader.full_filename)
AttributeError: 'NoneType' object has no attribute 'debug'
```

`_load_config_files` has a log parameter with a default of None. It should either be required, or it should do something sensible when it gets the default.



Discussion:

Resolving patch:
diff --git a/IPython/config/application.py b/IPython/config/application.py
--- a/IPython/config/application.py
+++ b/IPython/config/application.py
@@ -505,31 +505,28 @@ def _load_config_files(cls, basefilename, path=None, log=None):
 
         yield each config object in turn.
         """
-
         pyloader = PyFileConfigLoader(basefilename+'.py', path=path, log=log)
         jsonloader = JSONFileConfigLoader(basefilename+'.json', path=path, log=log)
-        config_found = False
         config = None
         for loader in [pyloader, jsonloader]:
             try:
                 config = loader.load_config()
-                config_found = True
             except ConfigFileNotFound:
                 pass
             except Exception:
                 # try to get the full filename, but it will be empty in the
                 # unlikely event that the error raised before filefind finished
-                filename = loader.full_filename or filename
+                filename = loader.full_filename or basefilename
                 # problem while running the file
-                log.error("Exception while loading config file %s",
-                                filename, exc_info=True)
+                if log:
+                    log.error("Exception while loading config file %s",
+                            filename, exc_info=True)
             else:
-                log.debug("Loaded config file: %s", loader.full_filename)
+                if log:
+                    log.debug("Loaded config file: %s", loader.full_filename)
             if config:
                  yield config
 
-        if not config_found:
-            raise ConfigFileNotFound('Neither .json, nor .py config file found.')
         raise StopIteration
 
 
diff --git a/IPython/utils/process.py b/IPython/utils/process.py
--- a/IPython/utils/process.py
+++ b/IPython/utils/process.py
@@ -27,7 +27,7 @@
     from ._process_posix import _find_cmd, system, getoutput, arg_split
 
 
-from ._process_common import getoutputerror, get_output_error_code
+from ._process_common import getoutputerror, get_output_error_code, process_handler
 from . import py3compat
 
 #-----------------------------------------------------------------------------


Test patch:
diff --git a/IPython/terminal/tests/test_embed.py b/IPython/terminal/tests/test_embed.py
new file mode 100644
--- /dev/null
+++ b/IPython/terminal/tests/test_embed.py
@@ -0,0 +1,54 @@
+"""Test embedding of IPython"""
+
+#-----------------------------------------------------------------------------
+#  Copyright (C) 2013 The IPython Development Team
+#
+#  Distributed under the terms of the BSD License.  The full license is in
+#  the file COPYING, distributed as part of this software.
+#-----------------------------------------------------------------------------
+
+#-----------------------------------------------------------------------------
+# Imports
+#-----------------------------------------------------------------------------
+
+import sys
+import nose.tools as nt
+from IPython.utils.process import process_handler
+from IPython.utils.tempdir import NamedFileInTemporaryDirectory
+
+#-----------------------------------------------------------------------------
+# Tests
+#-----------------------------------------------------------------------------
+
+_sample_embed = b"""
+from __future__ import print_function
+import IPython
+
+a = 3
+b = 14
+print(a, '.', b)
+
+IPython.embed()
+
+print('bye!')
+"""
+
+_exit = b"exit\r"
+
+def test_ipython_embed():
+    """test that `IPython.embed()` works"""
+    with NamedFileInTemporaryDirectory('file_with_embed.py') as f:
+        f.write(_sample_embed)
+        f.flush()
+        f.close() # otherwise msft won't be able to read the file
+
+        # run `python file_with_embed.py`
+        cmd = [sys.executable, f.name]
+
+        out, p = process_handler(cmd, lambda p: (p.communicate(_exit), p))
+        std = out[0].decode('UTF-8')
+        nt.assert_equal(p.returncode, 0)
+        nt.assert_in('3 . 14', std)
+        nt.assert_in('IPython', std)
+        nt.assert_in('bye!', std)
+