def test_write_sourcemap_source_mapping_encoded_same(self):
        root = mktemp()
        # emulating a codecs.open with encoding as shift_jis
        raw_stream = BytesIO()
        raw_stream.encoding = 'shift_jis'
        raw_stream.name = join(root, 'lang.js')
        output_stream = codecs.getwriter(raw_stream.encoding)(raw_stream)
        output_stream.write('yes\u306f\u3044//')
        mappings = [[(0, 0, 0, 0, 0)]]
        sources = [join(root, 'src', 'ja.js')]
        names = ['yes\u306f\u3044']

        sourcemap.write_sourcemap(
            mappings, sources, names, output_stream, output_stream,
            source_mapping_url='src.map')

        encoded = raw_stream.getvalue().splitlines()[-1]
        # the sourcemap is written as a sourceMappingURL, with the
        # source_mapping_url argument ignored.
        self.assertIn(b'application/json;base64;charset=shift_jis', encoded)
        # decode the base64 string; note the shift_jis encoding
        self.assertEqual({
            "version": 3,
            "sources": ['src/ja.js'],
            "names": ["yes\u306f\u3044"],
            "mappings": "AAAAA",
            "file": 'lang.js',
        }, json.loads(base64.b64decode(
            encoded.split(b',')[-1]).decode('shift_jis')))