def test_encode_line_lena(self): self.maxDiff = None line_numbers = [1, 10, 100] for line in line_numbers: file = open(get_asset_filename("MartinM1_encode_line_lena%d.p" % line)) expected = pickle.load(file) actual = list(self.lena.encode_line(line)) self.assertEqual(expected, actual)
def test_gen_samples(self): gen_values = self.s.gen_samples() # gen_samples uses random to avoid quantization noise # by using additive noise, so there's always a chance # of running the code two consecutive times on the same machine # and having different results. # https://en.wikipedia.org/wiki/Quantization_%28signal_processing%29 sstv.random = MagicMock(return_value=0.4) # xkcd:221 expected = pickle.load(open(get_asset_filename("SSTV_gen_samples.p"))) actual = list(islice(gen_values, 0, 1000)) for e, a in izip(expected, actual): self.assertAlmostEqual(e, a, delta=1)
def test_gen_values(self): gen_values = self.s.gen_values() expected = pickle.load(open(get_asset_filename("SSTV_gen_values.p"))) for e, g in izip(expected, gen_values): self.assertAlmostEqual(e, g, delta=0.000000001)
def test_gen_freq_bits_lena(self): expected = pickle.load(open(get_asset_filename("MartinM1_freq_bits_lena.p"))) actual = list(islice(self.lena.gen_freq_bits(), 0, 1000)) self.assertEqual(expected, actual)
def setUp(self): self.image = Image.new("RGB", (320, 256)) self.s = color.MartinM1(self.image, 48000, 16) lena = Image.open(get_asset_filename("320x256.png")) self.lena = color.MartinM1(lena, 48000, 16)