def test_build_JobResult_checks_for_missing_io_log(self): """ verify that _build_JobResult() checks if ``io_log`` is present """ with self.assertRaises(CorruptedSessionError) as boom: obj_repr = copy.copy(self.good_repr) del obj_repr['io_log'] SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual( str(boom.exception), "Missing value for key 'io_log'")
def test_build_JobResult_checks_type_of_return_code(self): """ verify that _build_JobResult() checks if ``return_code`` is an integer """ with self.assertRaises(CorruptedSessionError) as boom: obj_repr = copy.copy(self.good_repr) obj_repr['return_code'] = "text" SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual( str(boom.exception), "Value of key 'return_code' is of incorrect type str")
def test_build_JobResult_checks_type_of_comments(self): """ verify that _build_JobResult() checks if ``comments`` is a string """ with self.assertRaises(CorruptedSessionError) as boom: obj_repr = copy.copy(self.good_repr) obj_repr['comments'] = False SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual( str(boom.exception), "Value of key 'comments' is of incorrect type bool")
def test_build_JobResult_checks_type_of_outcome(self): """ verify that _build_JobResult() checks if ``outcome`` is a string """ with self.assertRaises(CorruptedSessionError) as boom: obj_repr = copy.copy(self.good_repr) obj_repr['outcome'] = 42 SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual( str(boom.exception), "Value of key 'outcome' is of incorrect type int")
def test_build_JobResult_checks_for_none_io_log_filename(self): """ verify that _build_JobResult() checks if the value of ``io_log_filename`` is not None """ with self.assertRaises(CorruptedSessionError) as boom: obj_repr = copy.copy(self.good_repr) obj_repr['io_log_filename'] = None SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual( str(boom.exception), "Value of key 'io_log_filename' cannot be None")
def test_build_JobResult_checks_type_of_execution_duration(self): """ verify that _build_JobResult() checks if ``execution_duration`` is a float """ with self.assertRaises(CorruptedSessionError) as boom: obj_repr = copy.copy(self.good_repr) obj_repr['execution_duration'] = "text" SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual( str(boom.exception), "Value of key 'execution_duration' is of incorrect type str")
def test_build_JobResult_checks_value_of_outcome(self): """ verify that _build_JobResult() checks if the value of ``outcome`` is in the set of known-good values. """ with self.assertRaises(CorruptedSessionError) as boom: obj_repr = copy.copy(self.good_repr) obj_repr['outcome'] = 'maybe' SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual( str(boom.exception), ( "Value for key 'outcome' not in allowed set [None, 'pass', " "'fail', 'skip', 'not-supported', 'not-implemented', " "'undecided']"))
def test_build_JobResult_does_not_check_for_missing_io_log_filename(self): """ verify that _build_JobResult() does not check if ``io_log_filename`` is present as that signifies that MemoryJobResult should be recreated instead """ with self.assertRaises(CorruptedSessionError) as boom: obj_repr = copy.copy(self.good_repr) del obj_repr['io_log_filename'] SessionResumeHelper._build_JobResult(obj_repr) # NOTE: the error message explicitly talks about 'io_log', not # about 'io_log_filename' because we're hitting the other path # of the restore function self.assertEqual( str(boom.exception), "Missing value for key 'io_log'")
def test_build_JobResult_restores_comments(self): """ verify that _build_JobResult() restores the value of ``comments`` """ obj_repr = copy.copy(self.good_repr) obj_repr['comments'] = 'this is a comment' obj = SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual(obj.comments, 'this is a comment')
def test_build_JobResult_restores_outcome(self): """ verify that _build_JobResult() restores the value of ``outcome`` """ obj_repr = copy.copy(self.good_repr) obj_repr['outcome'] = 'fail' obj = SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual(obj.outcome, 'fail')
def test_build_JobResult_restores_return_code(self): """ verify that _build_JobResult() restores the value of ``return_code`` """ obj_repr = copy.copy(self.good_repr) obj_repr['return_code'] = 42 obj = SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual(obj.return_code, 42)
def test_build_JobResult_restores_io_log_filename(self): """ verify that _build_JobResult() restores the value of ``io_log_filename`` DiskJobResult representations """ obj_repr = copy.copy(self.good_repr) obj_repr['io_log_filename'] = "some-file.txt" obj = SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual(obj.io_log_filename, "some-file.txt")
def test_build_JobResult_allows_for_none_comments(self): """ verify that _build_JobResult() allows for the value of ``comments`` to be None """ obj_repr = copy.copy(self.good_repr) obj_repr['comments'] = None obj = SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual(obj.comments, None)
def test_build_JobResult_allows_none_outcome(self): """ verify that _build_JobResult() allows for the value of ``outcome`` to be None """ obj_repr = copy.copy(self.good_repr) obj_repr['outcome'] = None obj = SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual(obj.outcome, None)
def test_build_JobResult_allows_for_none_return_code(self): """ verify that _build_JobResult() allows for the value of ``return_code`` to be None """ obj_repr = copy.copy(self.good_repr) obj_repr['return_code'] = None obj = SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual(obj.return_code, None)
def test_build_JobResult_restores_execution_duration(self): """ verify that _build_JobResult() restores the value of ``execution_duration`` """ obj_repr = copy.copy(self.good_repr) obj_repr['execution_duration'] = 5.1 obj = SessionResumeHelper._build_JobResult(obj_repr) self.assertAlmostEqual(obj.execution_duration, 5.1)
def test_build_JobResult_allows_for_none_execution_duration(self): """ verify that _build_JobResult() allows for the value of ``execution_duration`` to be None """ obj_repr = copy.copy(self.good_repr) obj_repr['execution_duration'] = None obj = SessionResumeHelper._build_JobResult(obj_repr) self.assertEqual(obj.execution_duration, None)
def test_build_JobResult_restores_io_log(self): """ verify that _build_JobResult() checks if ``io_log`` is restored for MemoryJobResult representations """ obj_repr = copy.copy(self.good_repr) obj_repr['io_log'] = [[0.0, 'stdout', '']] obj = SessionResumeHelper._build_JobResult(obj_repr) # NOTE: MemoryJobResult.io_log is a property that converts # whatever was stored to IOLogRecord and returns a _tuple_ # so the original list is not visible self.assertEqual(obj.io_log, tuple([ IOLogRecord(0.0, 'stdout', b'') ]))
def test_build_JobResult_restores_DiskJobResult_representations(self): obj = SessionResumeHelper._build_JobResult(self.good_repr) self.assertIsInstance(obj, DiskJobResult)