def test_reload_weight_file_when_false(self): temp_image_weights_file = tempfile.NamedTemporaryFile() test_weights = {'the_final_countdown': 5, 'the_man_who_sold_the_world': 10} temp_image_weights_file.write(six.b(json.dumps(test_weights))) temp_image_weights_file.flush() CONF.set_override('image_weights_filename', temp_image_weights_file.name, 'strategy') sb._load_image_weights_file(reload_file=False) self.assertEqual(sb._load_image_weights_file.image_weights, self.WEIGHTED_IMAGES) self.assertTrue(sb._load_image_weights_file.loaded)
def test_reload_weight_file_when_false(self): temp_image_weights_file = tempfile.NamedTemporaryFile() test_weights = {'the_final_countdown': 5, 'the_man_who_sold_the_world': 10} temp_image_weights_file.write(json.dumps(test_weights)) temp_image_weights_file.flush() CONF.set_override('image_weights_filename', temp_image_weights_file.name, 'strategy') sb._load_image_weights_file(reload_file=False) self.assertEqual(sb._load_image_weights_file.image_weights, self.WEIGHTED_IMAGES) self.assertTrue(sb._load_image_weights_file.loaded)
def test_load_image_weights(self): sb._load_image_weights_file.image_weights = {} sb._load_image_weights_file.loaded = False temp_image_weights_file = tempfile.NamedTemporaryFile() temp_image_weights_file.write(six.b(json.dumps(self.WEIGHTED_IMAGES))) temp_image_weights_file.flush() CONF.set_override('image_weights_filename', temp_image_weights_file.name, 'strategy') sb._load_image_weights_file() self.assertEqual(sb._load_image_weights_file.image_weights, self.WEIGHTED_IMAGES) self.assertTrue(sb._load_image_weights_file.loaded)
def test_load_image_weights(self): sb._load_image_weights_file.image_weights = {} sb._load_image_weights_file.loaded = False temp_image_weights_file = tempfile.NamedTemporaryFile() temp_image_weights_file.write(json.dumps(self.WEIGHTED_IMAGES)) temp_image_weights_file.flush() CONF.set_override('image_weights_filename', temp_image_weights_file.name, 'strategy') sb._load_image_weights_file() self.assertEqual(sb._load_image_weights_file.image_weights, self.WEIGHTED_IMAGES) self.assertTrue(sb._load_image_weights_file.loaded)
def test_exception_fails_image_weight_loading(self, exception_log_mock): sb._load_image_weights_file.loaded = False sb._load_image_weights_file.image_weights = {} CONF.set_override( 'image_weights_filename', os.path.join('from_fox_two_phantoms_were_born', 'those_who_dont_exist'), 'strategy') sb._load_image_weights_file() self.assertTrue( exception_log_mock.called, "The exception log method was not called, even though the file " "doesn't exist.") self.assertFalse( sb._load_image_weights_file.loaded, "_load_image_weights_file.loaded is True, even though it " "did not load a file.") self.assertEqual( {}, sb._load_image_weights_file.image_weights, "_load_image_weights_file.image_weights is not equal to {} " "even though no file was loaded.")
def test_exception_fails_image_weight_loading(self, exception_log_mock): sb._load_image_weights_file.loaded = False sb._load_image_weights_file.image_weights = {} CONF.set_override( 'image_weights_filename', os.path.join('from_fox_two_phantoms_were_born', 'those_who_dont_exist'), 'strategy') sb._load_image_weights_file() self.assertTrue( exception_log_mock.called, "The exception log method was not called, even though the file " "doesn't exist.") self.assertFalse( sb._load_image_weights_file.loaded, "_load_image_weights_file.loaded is True, even though it " "did not load a file.") self.assertEqual( {}, sb._load_image_weights_file.image_weights, "_load_image_weights_file.image_weights is not equal to {} " "even though no file was loaded.")