def main(width, height, image, grayscale, blur, save_path, save_ext, show_url): """Retrieve an image from picsum.photos and save it.""" p = Picsum(width, height, image, grayscale, blur) p.save(save_path, save_ext) click.echo("Image saved to {}".format(p.filename)) if show_url: click.echo("Image retrieved from {}".format(p.url)) return 0
class TestImg500x500Id3Blur: p = Picsum(width=500, id_=3, blur=5) def test_request_url(self): """Test the request URL generated by the Picsum class.""" expect = "https://picsum.photos/id/3/500/?blur=5" result = self.p.request_url assert result == expect def test_url(self): """Test the actual URL returned by picsum.photos.""" expect = "https://picsum.photos/id/3/500/500?blur=5" result = self.p.url assert result == expect def test_image(self, img_500x500_id_3_blur): """Test the actual image returned.""" self.p.save(TESTIMG) assert equal_imgs(img_500x500_id_3_blur, TESTIMG) @classmethod def teardown_class(cls): os.remove(TESTIMG)
class TestImg800x600Id5: p = Picsum(width=800, height=600, id_=5) def test_request_url(self): """Test the request URL generated by the Picsum class.""" expect = "https://picsum.photos/id/5/800/600" result = self.p.request_url assert result == expect def test_url(self): """Test the actual URL returned by picsum.photos.""" expect = "https://picsum.photos/id/5/800/600" result = self.p.url assert result == expect def test_image(self, img_800x600_id_5): """Test the actual image returned.""" self.p.save(TESTIMG) assert equal_imgs(img_800x600_id_5, TESTIMG) @classmethod def teardown_class(cls): os.remove(TESTIMG)
def test_random_string(): expect = "bRYxrzgWQRQh" random.seed(420) result = Picsum().random_string() assert result == expect
def test_random_string_custom_length(): expect = 6 result = len(Picsum().random_string(6)) assert result == expect
def test_random_string_default_length(): expect = 12 result = len(Picsum().random_string()) assert result == expect