Example #1
0
 def test_file_deleted(self):
     """
     Check that an error is not raised if the file is deleted by the caller
     """
     try:
         with get_temp_file() as (fd, name):
             os.unlink(name)
     except Exception as err:
         self.fail('Failed with exception "{}"'.format(err))
Example #2
0
 def test_file_deleted(self):
     """
     Check that an error is not raised if the file is deleted by the caller
     """
     try:
         with get_temp_file() as (fd, name):
             os.unlink(name)
     except Exception as err:
         self.fail('Failed with exception "{}"'.format(err))
Example #3
0
 def test_file_closed(self):
     """
     Check that an error is not raised if the file is closed by the caller
     """
     try:
         with get_temp_file() as (fd, name):
             os.close(fd)
     except Exception as err:
         self.fail('Failed with exception "{}"'.format(err))
     else:
         file_exists = os.access(name, os.F_OK)
         self.assertFalse(file_exists)
Example #4
0
 def test_file_closed(self):
     """
     Check that an error is not raised if the file is closed by the caller
     """
     try:
         with get_temp_file() as (fd, name):
             os.close(fd)
     except Exception as err:
         self.fail('Failed with exception "{}"'.format(err))
     else:
         file_exists = os.access(name, os.F_OK)
         self.assertFalse(file_exists)
Example #5
0
def get_qrcode(data):
    """
    Return a QR Code PNG (binary data)
    """
    height = width = 250
    code = QRChart(height, width)
    code.set_ec('L', 0)  # "Level L" error correction with a 0 pixel margin
    code.add_data(data)
    with get_temp_file() as (__, fname):
        code.download(fname)
        with open(fname, "rb") as f:
            png_data = f.read()
    return png_data
Example #6
0
def get_qrcode(data):
    """
    Return a QR Code PNG (binary data)
    """
    height = width = 250
    code = QRChart(height, width)
    code.set_ec('L', 0)  # "Level L" error correction with a 0 pixel margin
    code.add_data(data)
    with get_temp_file() as (__, fname):
        code.download(fname)
        with open(fname, "rb") as f:
            png_data = f.read()
    return png_data