def test_picklable(self):
        writer = datasets.PickleDatasetWriter(self.io)
        writer.write(1)
        writer.flush()

        dataset = datasets.PickleDataset(self.io)
        dataset = pickle.loads(pickle.dumps(dataset))
        assert len(dataset) == 1
        assert dataset[0] == 1
Beispiel #2
0
    def test_write_read(self):
        writer = datasets.PickleDatasetWriter(self.io)
        writer.write(1)
        writer.write('hello')
        writer.write(1.5)
        writer.flush()

        dataset = datasets.PickleDataset(self.io)
        assert len(dataset) == 3
        assert dataset[0] == 1
        assert dataset[2] == 1.5
        assert dataset[1] == 'hello'
    def test_after_fork(self):
        writer = datasets.PickleDatasetWriter(self.io)
        writer.write(1)
        writer.flush()

        reader = ReaderMock(self.io)
        # Assign to avoid destruction of the instance
        # before creation a child process
        dataset = datasets.PickleDataset(reader)

        assert reader.n_hook_called == 0
        p = multiprocessing.Process()
        p.start()
        p.join()
        assert reader.n_hook_called == 1
        assert reader.last_caller_pid == p.pid

        # Touch to suppress "unused variable' warning
        del dataset