Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added robyn_api/tests/__init__.py
Empty file.
45 changes: 45 additions & 0 deletions robyn_api/tests/test_hex_to_png.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import unittest
import os
import binascii
from PIL import Image
import io
import sys
sys.path.append('..') # Add parent directory to path
from python_helper import hexToPng

class TestPythonHelper(unittest.TestCase):
def setUp(self):
# Create a small test image in memory
self.test_image = Image.new('RGB', (100, 100), color='red')
# Save it to a bytes buffer
img_buffer = io.BytesIO()
self.test_image.save(img_buffer, format='PNG')
# Convert to hex
self.test_hex = binascii.hexlify(img_buffer.getvalue()).decode()

def test_hexToPng(self):
# Test file name
test_file = 'test_output.png'

# Run the function
hexToPng(test_file, self.test_hex)

# Check if file exists
self.assertTrue(os.path.exists(test_file))

# Check if it's a valid image
try:
img = Image.open(test_file)
self.assertEqual(img.size, (100, 100))
finally:
# Cleanup
if os.path.exists(test_file):
os.remove(test_file)

def test_invalid_hex(self):
# Test with invalid hex data
with self.assertRaises(binascii.Error):
hexToPng('invalid.png', 'invalid_hex')

if __name__ == '__main__':
unittest.main()