Repository: chainer/chainer

Issue:
`TestCaffeExport` is failing in AppVeyor
I found Caffe export tests failed.  It seems a problem with `int` vs `long` in Python 2.

* Conditions
  - Chainer version: master
  - OS/Platform: Windows
* Code to reproduce
* Error messages, stack traces, or logs
https://ci.appveyor.com/project/pfnet/chainer/build/10765/job/9m4yuq02f3426yv8
```
_____________________ TestCaffeExport.test_LinearFunction _____________________
self = <chainer_tests.exporters_tests.test_caffe.TestCaffeExport testMethod=test_LinearFunction>
    def test_LinearFunction(self):
        W = numpy.random.uniform(-1, 1, (1, numpy.prod(self.x.shape[1:])))
    
        class Link(chainer.Chain):
            def __call__(self, x):
                return F.linear(x, W)
    
>       assert_export_import_match(Link(), self.x)
tests\chainer_tests\exporters_tests\test_caffe.py:61: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests\chainer_tests\exporters_tests\test_caffe.py:97: in assert_export_import_match
    l2 = export_and_import(l1, (x,), True)
tests\chainer_tests\exporters_tests\test_caffe.py:111: in export_and_import
    caffe.export(l, args, tempdir, export_params, graph_name)
chainer\exporters\caffe.py:459: in export
    retriever(graph_name, args, output)
chainer\exporters\caffe.py:357: in __call__
    self.dump_function_object(i, f, net)
chainer\exporters\caffe.py:327: in dump_function_object
    prototxt.write(self._gen_layer_prototxt(params))
chainer\exporters\caffe.py:115: in _gen_layer_prototxt
    self._gen_layer_prototxt(val, name=key, depth=depth + 1)
chainer\exporters\caffe.py:115: in _gen_layer_prototxt
    self._gen_layer_prototxt(val, name=key, depth=depth + 1)
chainer\exporters\caffe.py:115: in _gen_layer_prototxt
    self._gen_layer_prototxt(val, name=key, depth=depth + 1)
chainer\exporters\caffe.py:131: in _gen_layer_prototxt
    s += self._gen_layer_prototxt(t, name=name, depth=depth + 1)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <chainer.exporters.caffe._RetrieveAsCaffeModel object at 0x000000002519C3C8>
layer_params = 1L, name = 'dim', depth = 4, indent = 2
    def _gen_layer_prototxt(self, layer_params, name='layer', depth=0,
                            indent=2):
        if isinstance(layer_params, (dict, collections.OrderedDict)):
            s = name + ' {\n'
            indent_s = ' ' * ((depth + 1) * indent)
            for key, val in layer_params.items():
                s += indent_s + \
                    self._gen_layer_prototxt(val, name=key, depth=depth + 1)
            s += ' ' * (depth * indent)
            s += '}\n'
            return s
        elif isinstance(layer_params, (int, float)):
            return '{}: {}\n'.format(name, layer_params)
        elif isinstance(layer_params, bool):
            return '{}: {}\n'.format(name, 'true' if layer_params else 'false')
        elif isinstance(layer_params, str):
            return '{}: "{}"\n'.format(name, layer_params)
        elif isinstance(layer_params, list):
            s = ''
            indent_s = ' ' * depth * indent
            for i, t in enumerate(layer_params):
                if i != 0:
                    s += indent_s
                s += self._gen_layer_prototxt(t, name=name, depth=depth + 1)
            return s
        else:
>           raise ValueError('Unsupported type: ' + str(type(layer_params)))
E           ValueError: Unsupported type: <type 'long'>
chainer\exporters\caffe.py:134: ValueError
```



Discussion:

Resolving patch:
diff --git a/chainer/exporters/caffe.py b/chainer/exporters/caffe.py
--- a/chainer/exporters/caffe.py
+++ b/chainer/exporters/caffe.py
@@ -116,10 +116,10 @@ def _gen_layer_prototxt(self, layer_params, name='layer', depth=0,
             s += ' ' * (depth * indent)
             s += '}\n'
             return s
-        elif isinstance(layer_params, (int, float)):
-            return '{}: {}\n'.format(name, layer_params)
         elif isinstance(layer_params, bool):
             return '{}: {}\n'.format(name, 'true' if layer_params else 'false')
+        elif isinstance(layer_params, six.integer_types + (float,)):
+            return '{}: {}\n'.format(name, layer_params)
         elif isinstance(layer_params, str):
             return '{}: "{}"\n'.format(name, layer_params)
         elif isinstance(layer_params, list):


Test patch: