def setUp(self):
        ipydir = self.ipython_dir.name
        sample_kernel_dir = pjoin(ipydir, 'kernels', 'sample')
        try:
            os.makedirs(sample_kernel_dir)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        with open(pjoin(sample_kernel_dir, 'kernel.json'), 'w') as f:
            json.dump(sample_kernel_json, f)

        with io.open(pjoin(sample_kernel_dir, 'resource.txt'), 'w',
                     encoding='utf-8') as f:
            f.write(some_resource)

        self.ks_api = KernelSpecAPI(self.base_url())