-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit Test cases clean up, bug fixes, new functionality (#231)
Unit Test cases clean up, bug fixes, new functionality
- Loading branch information
1 parent
a06b563
commit bdcf85c
Showing
11 changed files
with
224 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import unittest | ||
from tkinter import Tk | ||
# from customtkinter import CTk | ||
|
||
# Assuming SelectableTextComponent is defined in a module named selectable_text_component | ||
from app.transcribe.uicomp.selectable_text import SelectableText | ||
|
||
|
||
class TestSelectableText(unittest.TestCase): | ||
def setUp(self): | ||
# Set up a root window and the component for testing | ||
self.root = Tk() | ||
self.root.withdraw() # Hide the root window | ||
self.component = SelectableText(self.root) | ||
self.component.pack() | ||
|
||
def tearDown(self): | ||
self.component.destroy() | ||
self.root.destroy() | ||
|
||
def test_insert_text_at_top(self): | ||
self.component.add_text_to_top("First line at top") | ||
result = self.component.text_widget.get("1.0", "2.0").strip() | ||
self.assertEqual(result, "First line at top") | ||
|
||
def test_insert_text_at_bottom(self): | ||
self.component.add_text_to_bottom("First line at bottom") | ||
result = self.component.text_widget.get("end-2l", "end-1l").strip() | ||
self.assertEqual(result, "First line at bottom") | ||
|
||
def test_scroll_to_top(self): | ||
self.component.add_text_to_top("Line 1\nLine 2\nLine 3\n") | ||
self.component.scroll_to_bottom() | ||
self.component.scroll_to_top() | ||
self.assertEqual(self.component.text_widget.yview()[0], 0.0) | ||
|
||
def test_scroll_to_bottom(self): | ||
self.component.add_text_to_bottom("Line 1\nLine 2\nLine 3\n") | ||
self.component.scroll_to_bottom() | ||
self.assertEqual(self.component.text_widget.yview()[1], 1.0) | ||
|
||
def test_delete_last_two_rows(self): | ||
self.component.add_text_to_bottom("Line 1") | ||
self.component.add_text_to_bottom("Line 2") | ||
self.component.add_text_to_bottom("Line 3") | ||
self.component.delete_last_2_row() | ||
result = self.component.text_widget.get("1.0", "end").strip() | ||
self.assertEqual(result, "Line 1") | ||
|
||
def test_clear_all_text(self): | ||
self.component.add_text_to_bottom("Line 1") | ||
self.component.add_text_to_bottom("Line 2") | ||
self.component.clear_all_text() | ||
result = self.component.text_widget.get("1.0", "end").strip() | ||
self.assertEqual(result, "") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
import datetime | ||
from tsutils.duration import Duration | ||
|
||
|
||
class TestDuration(unittest.TestCase): | ||
"""Unit Tests for Duration class | ||
""" | ||
|
||
@patch('datetime.datetime') | ||
def test_enter_method(self, mock_datetime): | ||
"""Test that __enter__ method records the start time correctly.""" | ||
mock_datetime.now.return_value = datetime.datetime(2023, 1, 1, 12, 0, 0) | ||
duration = Duration() | ||
with duration: | ||
self.assertEqual(duration.start, datetime.datetime(2023, 1, 1, 12, 0, 0)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
from tsutils.utilities import ( | ||
merge, incrementing_filename, naturalsize, | ||
download_using_bits, ensure_directory_exists | ||
) | ||
|
||
|
||
class TestFunctions(unittest.TestCase): | ||
|
||
def test_merge(self): | ||
first = {'a': 1, 'b': {'c': 3}} | ||
second = {'b': {'d': 4}, 'e': 5} | ||
result = merge(first, second) | ||
self.assertEqual(result, {'a': 1, 'b': {'c': 3, 'd': 4}, 'e': 5}) | ||
|
||
@patch('os.path.exists', side_effect=[True, True, False]) | ||
def test_incrementing_filename(self, mock_exists): | ||
result = incrementing_filename('file', 'txt') | ||
self.assertEqual(result, 'file-2.txt') | ||
|
||
def test_naturalsize(self): | ||
result = naturalsize(3000000) | ||
self.assertEqual(result, '3.0 MB') | ||
result = naturalsize(300, False, True) | ||
self.assertEqual(result, '300.0B', f'Expected 300.0B got {result}') | ||
|
||
@patch('subprocess.check_output') | ||
def test_download_using_bits(self, mock_subproc): | ||
download_using_bits('https://github.com/vivekuppal/transcribe/archive/refs/heads/main.zip', 'transcribe.zip') | ||
mock_subproc.assert_called_once_with(['powershell', | ||
'-NoProfile', | ||
'-ExecutionPolicy', | ||
'Bypass', | ||
'-Command', | ||
'Start-BitsTransfer', | ||
'-Source', | ||
'https://github.com/vivekuppal/transcribe/archive/refs/heads/main.zip', | ||
'-Destination', | ||
'transcribe.zip']) | ||
|
||
@patch('os.makedirs') | ||
@patch('os.path.exists', return_value=False) | ||
def test_ensure_directory_exists(self, mock_exists, mock_makedirs): | ||
ensure_directory_exists('.') | ||
mock_makedirs.assert_called_once_with('.') | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters