def test_readinto_partial_sliding17(self, name, BQM):

        bqm = BQM(np.tril(np.arange(25).reshape((5, 5))), 'BINARY')
        bqm.offset = -6

        fv = FileView(bqm)

        buff = fv.readall()

        for pos in range(fv.quadratic_end):
            self.assertEqual(pos, fv.seek(pos))
            subbuff = bytearray(17)
            num_read = fv.readinto(subbuff)
            self.assertGreater(num_read, 0)
            self.assertEqual(subbuff[:num_read], buff[pos:pos + num_read])
    def test_readinto_partial_front_to_back(self, name, BQM):

        bqm = BQM(np.triu(np.arange(9).reshape((3, 3))), 'BINARY')
        bqm.offset = 14

        fv = FileView(bqm)

        buff = fv.readall()

        for nb in range(fv.quadratic_end):
            self.assertEqual(fv.seek(0), 0)
            subbuff = bytearray(nb)
            num_read = fv.readinto(subbuff)
            self.assertEqual(num_read, nb)
            self.assertEqual(subbuff[:num_read], buff[:num_read])
    def test_readinto_partial_back_to_front(self, name, BQM):

        bqm = BQM(np.triu(np.arange(25).reshape((5, 5))), 'BINARY')
        bqm.offset = 14

        fv = FileView(bqm)

        buff = fv.readall()

        for pos in range(1, fv.quadratic_end):
            fv.seek(-pos, io.SEEK_END)

            subbuff = bytearray(pos)  # length pos

            self.assertEqual(fv.readinto(subbuff), len(subbuff))
            self.assertEqual(buff[-pos:], subbuff)
    def test_readinto(self, name, BQM):

        bqm = BQM(np.triu(np.arange(25).reshape((5, 5))), 'BINARY')
        bqm.offset = 14

        fv = FileView(bqm)

        num_bytes = fv.quadratic_end

        # make a buffer that's a bit bigger
        buff = bytearray(num_bytes + 10)

        self.assertEqual(fv.readinto(buff), num_bytes)

        # reset and make sure that a total read it the same
        fv.seek(0)
        self.assertEqual(fv.read(), buff[:num_bytes])
    def test_readinto_partial_sliding17(self, BQM):
        if issubclass(BQM, dimod.AdjDictBQM):
            # not (yet) implemented for non cybqms
            return

        bqm = BQM(np.tril(np.arange(25).reshape((5, 5))), 'BINARY')
        bqm.offset = -6

        fv = FileView(bqm)

        buff = fv.readall()

        for pos in range(fv.quadratic_end):
            self.assertEqual(pos, fv.seek(pos))
            subbuff = bytearray(17)
            num_read = fv.readinto(subbuff)
            self.assertGreater(num_read, 0)
            self.assertEqual(subbuff[:num_read], buff[pos:pos+num_read])
    def test_readinto_partial_front_to_back(self, BQM):
        if issubclass(BQM, dimod.AdjDictBQM):
            # not (yet) implemented for non cybqms
            return

        bqm = BQM(np.triu(np.arange(9).reshape((3, 3))), 'BINARY')
        bqm.offset = 14

        fv = FileView(bqm)

        buff = fv.readall()

        for nb in range(fv.quadratic_end):
            self.assertEqual(fv.seek(0), 0)
            subbuff = bytearray(nb)
            num_read = fv.readinto(subbuff)
            self.assertEqual(num_read, nb)
            self.assertEqual(subbuff[:num_read], buff[:num_read])
    def test_readinto_partial_back_to_front(self, BQM):
        if issubclass(BQM, dimod.AdjDictBQM):
            # not (yet) implemented for non cybqms
            return

        bqm = BQM(np.triu(np.arange(25).reshape((5, 5))), 'BINARY')
        bqm.offset = 14

        fv = FileView(bqm)

        buff = fv.readall()

        for pos in range(1, fv.quadratic_end):
            fv.seek(-pos, io.SEEK_END)

            subbuff = bytearray(pos)  # length pos

            self.assertEqual(fv.readinto(subbuff), len(subbuff))
            self.assertEqual(buff[-pos:], subbuff)
    def test_readinto(self, BQM):
        if issubclass(BQM, dimod.AdjDictBQM):
            # not (yet) implemented for non cybqms
            return

        bqm = BQM(np.triu(np.arange(25).reshape((5, 5))), 'BINARY')
        bqm.offset = 14

        fv = FileView(bqm)

        num_bytes = fv.quadratic_end

        # make a buffer that's a bit bigger
        buff = bytearray(num_bytes + 10)

        self.assertEqual(fv.readinto(buff), num_bytes)

        # reset and make sure that a total read it the same
        fv.seek(0)
        self.assertEqual(fv.read(), buff[:num_bytes])