def test_error_if_loading_state_with_wrongly_typed_data(self):
     s = ReviewState()
     state = {
         'version': 1,
         'diff-checksums': "type dict expected, not str",
         'uncommitted': True
     }
     with self.assertRaisesRegexp(ExecutionError, "malformed state file"):
         s.load(json.dumps(state))
    def test_reset_state(self):
        s = ReviewState()
        s.set_checksum("12345", "abc123")
        s.set_uncommitted(True)

        s.reset()

        self.assertIsNone(s.get_checksum("12345"))
        self.assertFalse(s.get_uncommitted())
 def test_initial_state(self):
     s = ReviewState()
     state = {
         'version': 2,
         'diff-checksums': {},
         'uncommitted': False,
         'unpushed': False,
         'parent': None
     }
     self.assertDictEqual(state, s._state)
     self.assertEqual(json.dumps(state), str(s))
    def test_load_state(self):
        s = ReviewState()

        state = {
            'version': 1,
            'diff-checksums': {
                "12345": "abc123",
                "12346": "abc456"
            },
            'uncommitted': True
        }
        s.load(json.dumps(state))

        self.assertEqual("abc123", s.get_checksum("12345"))
        self.assertEqual("abc456", s.get_checksum("12346"))
        self.assertTrue(s.get_uncommitted())
 def test_error_if_loading_state_with_missing_data(self):
     s = ReviewState()
     state = {'version': 1}
     with self.assertRaisesRegexp(ExecutionError, "malformed state file"):
         s.load(json.dumps(state))
 def test_error_if_loading_wrong_state_version(self):
     s = ReviewState()
     state = {'version': 100, 'somekey': 'somevalue'}
     with self.assertRaisesRegexp(ExecutionError,
                                  "unsupported state file version"):
         s.load(json.dumps(state))
 def test_set_and_get_uncommitted(self):
     s = ReviewState()
     self.assertFalse(s.get_uncommitted())
     s.set_uncommitted(True)
     self.assertTrue(s.get_uncommitted())
 def test_set_and_get_checksum(self):
     s = ReviewState()
     self.assertIsNone(s.get_checksum("12345"))
     s.set_checksum("12345", "abc123")
     self.assertEqual("abc123", s.get_checksum("12345"))