Python Forum
I have 'Failed: DID NOT RAISE <class 'Exception'>'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I have 'Failed: DID NOT RAISE <class 'Exception'>'
#4
Quote:Code to write
You are asked to write the following classes:
Pixel in a pixel.py file
Image in an image.py file;
Encoder and Decoder in an encocher.py file.
The Pixel class represents, as its name suggests, a pixel and can contain three integers between 0 and 255: the values for the red, green, and blue channels. This type must be immutable: the RGB values cannot be changed, but the instances themselves can be compared. Two instances of Pixel must be comparable using the operator.
The Image class must contain the following methods:

__init__(self, width: int, height: int, pixels: list[Pixel]), the constructor which takes parameters width and height representing the dimensions of the image, and a list of size width-height of instances of the Pixel class representing the image pixels.
__getitem__(self, pos: tuple[int,int]) -> Pixel, to override the indexing operator [] for reading pixels.
__setitem__(self, pos: tuple[int,int], value: Pixel), to override the assignment operator for writing pixels.
__eq__(self, other: 'Image') -> bool, to override the equality operator.
The special methods __getitem__ and __setitem__ should raise an IndexError exception if pos is not a valid position in the image.
The Encoder class should contain the following methods:
__init__(self, img: Image), the constructor which takes as parameter the image to be encoded.
A method, let's call it encode, which encodes the received image and saves it in ULBMP version 1.0 format in the file whose path is provided as a parameter.
On the other hand, the Decoder class should have a single static method load_from(path: str) -> Image which loads the encoded image file from the specified path and returns it as an Image object. If there is an error in the format of the file, this function should raise an exception.
buran write Feb-20-2024, 08:59 PM:
Please,post in English
Reply


Messages In This Thread
RE: I have 'Failed: DID NOT RAISE <class 'Exception'>' - by williamKrakos - Feb-20-2024, 09:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Smile Exception with raise and input artemisellada 3 2,541 Apr-23-2021, 08:19 PM
Last Post: jefsummers
  Raise an exception for syntax error sbabu 8 3,275 Feb-10-2020, 01:57 AM
Last Post: sbabu
  raise error mcgrim 4 2,884 May-09-2019, 08:37 PM
Last Post: mcgrim

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020