Revision ad1c1e41 htest/Test/Ganeti/OpCodes.hs

b/htest/Test/Ganeti/OpCodes.hs
451 451
  sample_opcodes <- sample' (vectorOf num_opcodes
452 452
                             (arbitrary::Gen OpCodes.MetaOpCode))
453 453
  let opcodes = head sample_opcodes
454
      with_sum = map (\o -> (OpCodes.opSummary $
455
                             OpCodes.metaOpCode o, o)) opcodes
454 456
      serialized = J.encode opcodes
455 457
  -- check for non-ASCII fields, usually due to 'arbitrary :: String'
456 458
  mapM_ (\op -> when (any (not . isAscii) (J.encode op)) .
......
465 467
               \decoded = [opcodes.OpCode.LoadOpCode(o) for o in op_data]\n\
466 468
               \for op in decoded:\n\
467 469
               \  op.Validate(True)\n\
468
               \encoded = [op.__getstate__() for op in decoded]\n\
470
               \encoded = [(op.Summary(), op.__getstate__())\n\
471
               \           for op in decoded]\n\
469 472
               \print serializer.Dump(encoded)" serialized
470 473
     >>= checkPythonResult
471
  let deserialised = J.decode py_stdout::J.Result [OpCodes.MetaOpCode]
474
  let deserialised =
475
        J.decode py_stdout::J.Result [(String, OpCodes.MetaOpCode)]
472 476
  decoded <- case deserialised of
473 477
               J.Ok ops -> return ops
474 478
               J.Error msg ->
......
477 481
                 -- for proper types
478 482
                 >> fail "Unable to decode opcodes"
479 483
  HUnit.assertEqual "Mismatch in number of returned opcodes"
480
    (length opcodes) (length decoded)
484
    (length decoded) (length with_sum)
481 485
  mapM_ (uncurry (HUnit.assertEqual "Different result after encoding/decoding")
482
        ) $ zip opcodes decoded
486
        ) $ zip decoded with_sum
483 487

  
484 488
-- | Custom HUnit test case that forks a Python process and checks
485 489
-- correspondence between Haskell OpCodes fields and their Python

Also available in: Unified diff