Exemple #1
0
 def testConstructor(self):
     doc1 = TextDocument(self.text_id1[0], self.text_id1[1])
     expected_dict1 = {"the":1, "fat": 1, "cat":1, "sat":1, "on":1, "a":1, "mat":1}
     self.assertEqual(doc1.word_to_count, expected_dict1)
     doc2 = TextDocument(self.text_id2[0], self.text_id2[1])
     expected_dict2 = {"a":2, "rose":2, "is":1}
     self.assertEqual(doc2.word_to_count, expected_dict2)
 def __init__(self, ssid, password, auth_type="WPA"):
     super().__init__()
     text = f"WIFI:T:{auth_type};S:{ssid};P:{password};;"
     self.qr_image_doc = QRCodeImage(text)
     self.title_doc = TextDocument().add_title(ssid).nl()
     self.pass_doc = TextDocument().add_bold_text("Password: ").add_text(
         password)
     self.encoded = ConcatDocument(
         [self.title_doc, self.qr_image_doc, self.pass_doc]).encoded
    def testToString(self):
        doc1 = TextDocument(self.text_id1[0], self.text_id1[1])
        self.assertEqual(str(doc1), "the fat cat sat on a mat")

        doc2 = TextDocument(self.text_id2[0], self.text_id2[1])
        self.assertEqual(str(doc2), "a rose is a rose")

        doc3 = TextDocument(self.text)
        self.assertEqual(str(doc3), "Dr. Strangelove is the...")
    def testFromFileMethod(self):
        doc1 = TextDocument.from_file("./hw03_documents/example_document1.txt")
        token_set = set(doc1.word_to_count.keys())
        expected_token_set = {'dr.', 'strangelove', 'is', 'the', 'u.s.', 'president', \
                              "'s", 'advisor', '.'}
        self.assertEqual(token_set, expected_token_set)

        doc2 = TextDocument.from_file("./hw03_documents/example_document2.txt")
        self.assertEqual(doc2.word_to_count["die"], 2)
        self.assertTrue("länder" in doc2.word_to_count)
 def testWordOverlap(self):
     doc_1 = TextDocument(self.text_id1[0], self.text_id1[1])
     doc_2 = TextDocument(self.text_id2[0], self.text_id2[1])
     doc_3 = TextDocument(self.text_id3[0], self.text_id3[1])
     self.assertEqual(doc_1.word_overlap(doc_2), 1)
     self.assertEqual(doc_2.word_overlap(doc_3), 2)
     self.assertEqual(doc_1.word_overlap(doc_3), 2)
Exemple #6
0
 def print(self, printer: Printer):
     """
     Outputs HAL9000's warning from the end of 2010:Odyssey Two
     """
     document = TextDocument()\
         .add_bold_centered_text("ALL THESE WORLDS ARE YOURS-EXCEPT EUROPA").nl()\
         .add_bold_centered_text("ATTEMPT NO LANDING THERE")
     printer.print_document(document)
Exemple #7
0
    def print(self, printer: Printer):
        """
        Recites the tech support oath.
        Parody of the Night's Watch oath.
        """
        output = """\
User issues gather, and now my watch begins.
It shall not end until my death.
I shall take no wife (that I will ever see except on weekends),
hold no lands (because I don't make nearly enough),
father no children (because I will never be home anyway).
I shall receive no thanks and win no glory.
I shall live and die at my desk.
I am the antivirus in the darkness.
I am the coder on the walls.
I am the password reset that guards the logins of men.
I pledge my life and honor to the Help Desk's Watch,
for this night and all the nights to come."""
        document = TextDocument().add_title("Tech support oath")
        document.add_line_wrapped_text(output)
        printer.print_document(document)
Exemple #8
0
 def test_print(self):
     document = TextDocument().add_text("normal text").nl() \
         .add_bold_text("bold text").nl()\
         .add_invert_colours_text("invert text").nl()\
         .add_underlined_text("underline").nl()
     for num in range(256):
         document.add_text_with_control_code("test #" + str(num), num).nl()
     document.add_text("normal")
     self.default_printer().print_document(document)
Exemple #9
0
    def print(self, printer: Printer):
        """
        Outputs Niyi Osundere's "Not my business"
        """
        poem = """ \
They picked Akanni up one morning
Beat him soft like clay
And stuffed him down the belly
Of a waiting jeep.
What business of mine is it
So long they don't take the yam
From my savouring mouth?
        
They came one night
Booted the whole house awake
And dragged Danladi out,
Then off to a lengthy absence.
What business of mine is it
So long they don't take the yam
From my savouring mouth?

Chinwe went to work one day
Only to find her job was gone:
No query, no warning, no probe -
Just one neat sack for a stainless record.
What business of mine is it
So long they don't take the yam
From my savouring mouth?

And then one evening
As I sat down to eat my yam
A knock on the door froze my hungry hand.
The jeep was waiting on my bewildered lawn
Waiting, waiting in its usual silence."""
        document = TextDocument().add_title("Not My Business")
        document.add_title("by Niyi Osundere")
        document.add_line_wrapped_text(poem)
        printer.print_document(document)
Exemple #10
0
 def print(self, printer: Printer):
     doc = TextDocument().add_title("Print menu")
     for request_name in self.all_request_names:
         doc.add_text(request_name).nl()
     printer.print_document(doc)
Exemple #11
0
 def print(self, printer: Printer):
     document = TextDocument().add_text(self.text)
     printer.print_document(document)
Exemple #12
0
 def print_order(self, company_name, order_data, printer):
     doc = TextDocument().add_title(company_name).nl()
     # Order date
     order_date = order_data['Open_Date']
     date_format = "{:02d}/{:02d} {:02d}:{:02d}".format(
         order_date.day, order_date.month, order_date.hour,
         order_date.minute)
     doc.add_bold_text("Order placed: ").add_text(date_format).nl()
     # Delivery time
     delivery_time = order_data['DeliveryTime']
     pm = delivery_time['Hour'] != "ASAP" and delivery_time[
         'Meridiem'] == "PM"
     delivery_hour = int(
         delivery_time['Hour']) + 12 if pm else delivery_time['Hour']
     doc.add_bold_text("Time wanted: ")
     if delivery_time['Hour'] == "ASAP":
         doc.add_text("ASAP").nl()
     else:
         doc.add_text("{:02d}:{:02d}".format(delivery_hour,
                                             delivery_time['Minute'])).nl()
     doc.add_bold_text("Customer: ").add_text(order_data['Customer']).nl()
     doc.add_bold_text("Number: ").add_text(
         order_data['CustomerData']['Number']).nl()
     doc.add_text("  {}".format(order_data['CustomerData']['Street'])).nl()
     doc.add_text("  {}".format(order_data['CustomerData']['City'])).nl()
     doc.add_text("  {}".format(
         order_data['CustomerData']['Postcode'])).nl()
     if order_data['Notes']:
         doc.add_bold_text("Notes:").nl()
         doc.add_line_wrapped_text(order_data['Notes']).nl()
     if order_data['Driver']:
         doc.add_bold_text("Driver: ").add_text(order_data['Driver']).nl()
     column_spec = ColumnsSpec([
         ColumnSpec(3, ColumnAlign.right),
         ColumnSpec(None, ColumnAlign.left),
         ColumnSpec(6, ColumnAlign.right),
         ColumnSpec(6, ColumnAlign.right)
     ])
     doc.nl()
     doc.add_columns(column_spec, ["Qty", "Item", "Price", "Total"])
     doc.add_dashed_line()
     delivery_items = []
     for item in order_data['Items']:
         if item['Category'][:8] == 'Delivery':
             delivery_items.append(item)
             continue
         doc.add_columns(
             column_spec,
             [(item['Amount'], doc.add_number), item['Name'],
              (item['Price'], doc.add_price),
              (float(item['Price']) * item['Amount'], doc.add_price)])
         if item['Additional_Text']:
             doc.add_text("      {}".format(item['Additional_Text'])).nl()
     if len(delivery_items) != 0:
         doc.add_dashed_line()
     for item in delivery_items:
         doc.add_left_right_text(item['Name'],
                                 item['Price'],
                                 right_func=doc.add_price)
         if item['Additional_Text'] != '':
             doc.add_text("      {}".format(item['Additional_Text'])).nl()
     doc.add_dashed_line()
     doc.add_left_right_text("Total:",
                             order_data['Total'],
                             left_func=doc.add_bold_text,
                             right_func=doc.add_price)
     self.default_printer().print_document(doc)