예제 #1
0
 def update(self):
     if not self.waiting:
         return
     self.time -= 1
     if self.time < 0:
         self.time = 5
         Printer.add(f'{self.waiting.pop(0)}번 손님이 계산을 마치고 레스토랑을 떠났습니다.')
예제 #2
0
 def setUp(self) -> None:
     """
         Creates printer Object with each test function call
     :param
         - None
     :return
         - None
     """
     self.printer = Printer(2)
예제 #3
0
 def test_print_zero_line_statement(self):
     """
     If print statement is pass an empty array 
     it will print only account headers:
     date       || credit  || debit  || balance
     """
     printer = Printer()
     self.assertEqual(printer.print_statement([]),
                      "date       || credit  || debit   || balance")
예제 #4
0
 def setUp(self):
     self.printer = Printer()
     # set up positive transaction mock
     self.positive_transaction = mock.Mock()
     self.positive_transaction.date.strftime.return_value = "14/01/2012"
     self.positive_transaction.is_debit.return_value = True
     self.positive_transaction.value = 200.20
     # set up negative transaction mock
     self.negative_transaction = mock.Mock()
     self.negative_transaction.date.strftime.return_value = "20/02/2015"
     self.negative_transaction.is_debit.return_value = False
     self.negative_transaction.value = -50.55
예제 #5
0
    def new_customer(self):
        time = randrange(15, 41)
        if not self.__table.is_waitable(waitable_time=time,
                                        waiting_amount=len(self.waiting)):
            Printer.add(
                f'손님이 기다릴 수 없어 돌아갑니다. 현재대기시간 {self.__table.waitable_time}분 / 대기가능시간 {time}분'
            )
            return

        self.__customer_number += 1
        self.waiting.append(self.__customer_number)
        Printer.add(
            f'{self.__customer_number}번째 손님이 시각 {self.time}분에 레스토랑에 도착했습니다.')
예제 #6
0
    def update(self):
        finished_table = []
        for i in self.table.keys():
            if not self.table[i]:
                continue

            if self.table[i].update():
                customer_num = self.table[i].info.number
                self.table[i] = []
                finished_table.append(customer_num)
                Printer.add(f'{customer_num}번 손님이 식사를 마쳤습니다. {customer_num}번 손님이 계산대 앞에 줄을 섭니다.')
        self.__bill.add(finished_table)
        self.__bill.update()
        return finished_table
    def test_user_can_print_account_statement(self):
        """
        Integration statement output
        date       || credit  || debit   || balance
        14/01/2012 ||         || 200.00  || 0.00   
        20/02/2015 || 50.55   ||         || 200.00 
        21/02/2012 ||         || 3000.00 || 149.45 
        01/03/2015 || 3.50    ||         || 3149.45
        11/01/2016 || 10.20   ||         || 3145.95
        """

        printer = Printer()
        account = Account(Transaction, printer)

        account.deposit(200)
        account.withdraw(50.55)
        account.deposit(3000)
        account.withdraw(3.5)
        account.withdraw(10.20)

        statement = ("date       || credit  || debit   || balance"
                     "\n" + datetime.now().strftime("%d/%m/%Y") +
                     " ||         || 200.00  || 0.00   "
                     "\n" + datetime.now().strftime("%d/%m/%Y") +
                     " || 50.55   ||         || 200.00 "
                     "\n" + datetime.now().strftime("%d/%m/%Y") +
                     " ||         || 3000.00 || 149.45 "
                     "\n" + datetime.now().strftime("%d/%m/%Y") +
                     " || 3.50    ||         || 3149.45"
                     "\n" + datetime.now().strftime("%d/%m/%Y") +
                     " || 10.20   ||         || 3145.95")

        self.assertEqual(account.print_statement(), statement)
예제 #8
0
    def __init__(self, platform_name: str = "", full=True):
        """
        Set up the platform and, if needed, create the Suprenam's data folder.

        Args:
            platform: the current OS, only provided during testing.
        Raises:
            UnsupportedOSError: if the current OS is not supported.
        """
        self.platform = platform_name or get_platform_long_string().partition("-")[0]

        if self.platform == "macOS":
            self.workspace = Path.home() / "Library" / "Application Support" / "Suprenam"
        elif self.platform == "Linux":
            self.workspace = Path.home() / ".suprenam"
        elif self.platform == "Windows":
            self.workspace = Path.home() / "AppData" / "Roaming" / "Suprenam"
        elif self.platform == "mockOS":
            self.workspace = Path("test") / "workspace"
        else:
            raise UnsupportedOSError(f"Unsupported operating system: {self.platform}.")

        self.workspace.mkdir(
            parents=True,  # any missing parents of this path are created as needed
            exist_ok=True,  # if the directory already exists, do not raise an exception
        )

        config_path = self.workspace / "config.json"
        if not config_path.is_file():
            config_path.write_text(json.dumps(self.DEFAULT_CONFIG, indent=4))
        self.config = json.loads(config_path.read_text())

        self.logger = Logger(self)

        self.print_ = Printer(self)
예제 #9
0
    def update(self):
        self.__table.update()
        self.__cook.update()

        sittable = self.__table.empty()
        while self.waiting and sittable:
            table_num, food_num = sittable.pop(0), randrange(1, 5)
            info = CustomerInfo(self.waiting.pop(0), table_num, food_num)
            cooking_time = self.cooking_time[food_num]

            total_time = self.__cook.waiting_time(
            ) + self.eating_time[food_num] + cooking_time
            self.__cook.order_time.append(cooking_time)
            self.__table.table[table_num] = Customer(
                info, self.eating_time[food_num], total_time)

            Printer.add(
                f'{info[0]}번 손님이 {info[1]}번 테이블에 앉습니다. {info[2]}번 요리({self.food_name[info[2]]})를 주문합니다.'
            )
예제 #10
0
class TestFloatPrinter(TestCase):
    def setUp(self):
        self.printer = Printer()
        # set up positive transaction mock
        self.positive_transaction = mock.Mock()
        self.positive_transaction.date.strftime.return_value = "14/01/2012"
        self.positive_transaction.is_debit.return_value = True
        self.positive_transaction.value = 200.20
        # set up negative transaction mock
        self.negative_transaction = mock.Mock()
        self.negative_transaction.date.strftime.return_value = "20/02/2015"
        self.negative_transaction.is_debit.return_value = False
        self.negative_transaction.value = -50.55

    def test_print_debit_one_line_statement(self):
        """
        If transactions is contains one transaction for 200.20:
        date       || credit  || debit   || balance
        14/01/2012 ||         || 200.20  || 0.00   
        """
        statement = "date       || credit  || debit   || balance\n14/01/2012 ||         || 200.20  || 0.00   "
        self.assertEqual(
            self.printer.print_statement([self.positive_transaction]),
            statement)

    def test_print_multi_line_statement(self):
        """
        If transactions is two transactions for 200.20 and -50.55:
        date       || credit  || debit   || balance
        14/01/2012 ||         || 200.22  || 0.00   
        20/02/2015 || 50.55   ||         || 200.22 
        """
        statement = "date       || credit  || debit   || balance\n14/01/2012 ||         || 200.20  || 0.00   \n20/02/2015 || 50.55   ||         || 200.20 "
        self.assertEqual(
            self.printer.print_statement(
                [self.positive_transaction, self.negative_transaction]),
            statement)
예제 #11
0
    def run(self):
        Printer.init()
        period = 2
        self.time = 1
        while self.time < 721:

            Printer.add(f'[현재시각 : {self.time}분]')
            is_remained = self.time % period

            if not is_remained:
                self.new_customer()
            self.update()
            Printer.output()
            self.time += 1
예제 #12
0
def get_printer_list() -> List[Printer]:
    try:
        resp = requests.get(PRINTER_LIST_URL)
    except requests.RequestException:
        return []

    table = etree.HTML(resp.content).find("body/table")
    rows = iter(table)
    headers = [col.text for col in next(rows)]
    headers.insert(1, "printer_link")

    table_dict = []
    for row in rows:
        # values = [col.text for col in row]
        values = []

        for col in row:
            if col.text is not None:
                values.append(col.text.strip())
            else:
                for child in col:
                    if child.tag == "a":
                        values.append(child.text.strip())
                        values.append(child.attrib["href"].strip())

        table_dict.append(dict(zip(headers, values)))

    printers = []
    for printer_data in table_dict:
        printer = Printer(
            support=printer_data["Support"],
            color_mode=printer_data["colormode"],
            cost=printer_data["cost Duplex A4 (PQ)"],
            description=printer_data["description"],
            location=printer_data["location"],
            printer=printer_data["printer"],
            printer_link=printer_data["printer_link"],
            size=printer_data["size"]
        )
        printers.append(printer)

    return printers
예제 #13
0
 def test_respond_to_print_statement_method(self):
     printer = Printer()
     self.assertTrue(hasattr(printer, 'print_statement'))
예제 #14
0
파일: phockup.py 프로젝트: fstolba/phockup
#!/usr/bin/env python3
import argparse
import os
import re
import sys

from src.date import Date
from src.dependency import check_dependencies
from src.phockup import Phockup
from src.printer import Printer

__version__ = "1.6.0"

printer = Printer()

PROGRAM_DESCRIPTION = """Media sorting tool to organize photos and videos from your camera in folders by year, month and day.
The software will collect all files from the input directory and copy them to the output directory without
changing the files content. It will only rename the files and place them in the proper directory for year, month and day.
"""

DEFAULT_DIR_FORMAT = ['%Y', '%m', '%d']


def main():
    check_dependencies()

    parser = argparse.ArgumentParser(
        description=PROGRAM_DESCRIPTION,
        formatter_class=argparse.RawTextHelpFormatter,
    )
    parser.version = "v%s" % __version__
예제 #15
0
#!/usr/bin/env python3
import getopt
import os
import re
import sys

from src.date import Date
from src.dependency import check_dependencies
from src.help import help
from src.phockup import Phockup
from src.printer import Printer

version = '1.5.4'
printer = Printer()


def main(argv):
    check_dependencies()

    move = False
    link = False
    date_regex = None
    dir_format = os.path.sep.join(['%Y', '%m', '%d'])

    try:
        opts, args = getopt.getopt(argv[2:], "d:r:mlh", ["date=", "regex=", "move", "link", "help"])
    except getopt.GetoptError:
        help(version)
        sys.exit(2)

    for opt, arg in opts:
예제 #16
0
 def __change_status(self):
     self.__eating = not self.__eating
     print(self.info)
     Printer.add(
         f'{self.info.number}번 손님의 {self.info.food}번 요리({FOOD_NAME[self.info.food]}) 조리가 끝났습니다.'
         f'{self.info.number}번 손님이 식사를 시작합니다.')
예제 #17
0
def check_dependencies():
    if shutil.which('exiftool') is None:
        Printer().error(
            'Exiftool is not installed. Visit http://www.sno.phy.queensu.ca/~phil/exiftool/'
        )
예제 #18
0
class TestPrinter(TestCase):
    """
        TestPrinter Class : Functions to Test Printer Module
    """
    def setUp(self) -> None:
        """
            Creates printer Object with each test function call
        :param
            - None
        :return
            - None
        """
        self.printer = Printer(2)

    def tearDown(self) -> None:
        """
            Deletes the instance of printer after each test
        :param
            - None
        :return
            - None
        """
        del self.printer

    def test_can_print_positive(self):
        """
            Tests the printer capacity with custom print count
        :param
            - None
        :return
            - None
        """
        self.assertEqual(self.printer.can_print(20), False)

    @skip('Testing Skip')
    def test_can_print_negative(self):
        """
            Tests the printer capacity with custom print count
        :param
            - None
        :return
            - None
        """
        self.assertEqual(self.printer.can_print(-2), False)

    def test_get_page_count_in_queue(self):
        """
            Tests the url add functionality of the printer module
        :param
            - None
        :return
            - None
        """
        self.printer.add_page_in_queue('https://www.google.com')
        self.printer.add_page_in_queue('https://www.ubuntu.com')

        self.assertEqual(self.printer.get_page_count_in_queue, 2)

    def test_add_page_in_queue_exception(self):
        """
            Tests the Exception thrown when Printer Capacity is reached
        :param
            - None
        :return
            - None
        """
        with self.assertRaises(PrinterCapacityReached) as context:
            self.printer.add_page_in_queue('https://www.google.com')
            self.printer.add_page_in_queue('https://www.ubuntu.com')
            self.printer.add_page_in_queue('https://www.gmail.com')

        self.assertTrue(
            'ERROR: Printer Capacity is Full' in str(context.exception))

    def test_print_page(self):
        """
            Tests the printer module wheather it calls requests.get using mocks
        :param
            - None
        :return
            - None
        """
        class MockedGet:
            """
                Create a MockedGet Class for replecating requests.get()
            """
            def __init__(self):
                """
                    Creates instance variables for status and content
                :param
                    - None
                :return
                    - None
                """
                self.content = 'Google'
                self.status_code = 200

        self.printer.add_page_in_queue('https://www.google.com')
        self.printer.add_page_in_queue('https://www.ubuntu.com')

        with patch('requests.get', return_value=MockedGet()) as mocked_get:
            result = self.printer.print_page()
            mocked_get.assert_called()
            self.assertEqual(result, 'Google')

    def test_print_page_exception(self):
        """
            Tests the Exception thrown when Printer gets no response
        :param
            - None
        :return
            - None
        """
        with self.assertRaises(NoElementInQueue) as context:
            self.printer.print_page()

        self.assertTrue('ERROR: No Content to Print' in str(context.exception))

    @patch('requests.get')
    def test_requests_get_is_called(self, mocked_get):
        """
            Tests that requests.get method is atleast called in the print_page function
        :param
            - None
        :return
            - None
        """
        self.printer.add_page_in_queue('https://www.ubuntu.com')
        self.printer.print_page()
        mocked_get.assert_called()
예제 #19
0
#!/usr/bin/env python3
import hashlib
import os
import re
import shutil
import sys

from src.date import Date
from src.exif import Exif
from src.printer import Printer

printer = Printer()
ignored_files = (".DS_Store", "Thumbs.db")


class Phockup():
    def __init__(self, input, output, **args):
        input = os.path.expanduser(input)
        output = os.path.expanduser(output)

        if input.endswith(os.path.sep):
            input = input[:-1]
        if output.endswith(os.path.sep):
            output = output[:-1]

        self.input = input
        self.output = output
        self.dir_format = args.get('dir_format',
                                   os.path.sep.join(['%Y', '%m', '%d']))
        self.move = args.get('move', False)
        self.link = args.get('link', False)
예제 #20
0
파일: __main__.py 프로젝트: xibuka/phockup
#!/usr/bin/env python3
import sys

from phockup import main
from src.printer import Printer

if __name__ == '__main__':
    try:
        main(sys.argv[1:])
    except KeyboardInterrupt:
        Printer().empty().line('Exiting...')
        sys.exit(0)