MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TestTensorSerializationErrors

Function TestTensorSerializationErrors

tensorflow/go/tensor_test.go:206–228  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

204}
205
206func TestTensorSerializationErrors(t *testing.T) {
207 // String tensors cannot be serialized
208 t1, err := NewTensor("abcd")
209 if err != nil {
210 t.Fatal(err)
211 }
212 buf := new(bytes.Buffer)
213 if n, err := t1.WriteContentsTo(buf); n != 0 || err == nil || buf.Len() != 0 {
214 t.Errorf("Got (%v, %v, %v) want (0, <non-nil>, 0)", n, err, buf.Len())
215 }
216 // Should fail to read a truncated value.
217 if t1, err = NewTensor(int8(8)); err != nil {
218 t.Fatal(err)
219 }
220 n, err := t1.WriteContentsTo(buf)
221 if err != nil {
222 t.Fatal(err)
223 }
224 r := bytes.NewReader(buf.Bytes()[:n-1])
225 if _, err = ReadTensor(t1.DataType(), t1.Shape(), r); err == nil {
226 t.Error("ReadTensor should have failed if the tensor content was truncated")
227 }
228}
229
230func TestReadTensorReadAll(t *testing.T) {
231 // Get the bytes of a tensor.

Callers

nothing calls this directly

Calls 6

WriteContentsToMethod · 0.95
DataTypeMethod · 0.95
ShapeMethod · 0.95
NewTensorFunction · 0.85
ReadTensorFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected