It happens whenever the combined string is 20 characters or fewer.
The optimization occurs in the peephole optimizer. See line 219 in the fold_binops_on_constants() function in Python/peephole.c: http://hg.python.org/cpython/file/cd87afe18ff8/Python/peephole.c#l149