Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the beginning of a test suite 馃帀
- Loading branch information
1 parent
d519a96
commit 82c77d1
Showing
1 changed file
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Testing libraries | ||
import unittest | ||
try: | ||
import coverage | ||
has_coverage = True | ||
except ImportError: | ||
has_coverage = False | ||
|
||
# Modules used in testing | ||
import ui | ||
import ui2 | ||
import ui2.ui_io | ||
|
||
import os | ||
|
||
LOCALDIR = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
class TestDump(unittest.TestCase): | ||
""" Test ui2.dump_view to ensure the preservation of all attributes """ | ||
# SETUP | ||
path = "test.pyui" | ||
|
||
def tearDown(self): | ||
""" Called after each test to remove the pyui file created """ | ||
if os.path.exists(self.path): | ||
os.remove(self.path) | ||
|
||
# MAIN TESTS | ||
|
||
def test_Generic(self): | ||
""" Test all generic attributes of any ui.View class """ | ||
a = ui.View() | ||
# Store attributes | ||
a.background_color = "#ff00ff" | ||
# Encode + decode | ||
b = ui._view_from_dict(ui2.ui_io._view_to_dict(a), globals(), locals()) | ||
# Check that type and attributes were preserved | ||
self.assertIsInstance(b, type(a)) | ||
self.assertEqual(a.background_color, b.background_color) | ||
|
||
def test_Button(self): | ||
a = ui.Button() | ||
# Store attributes | ||
a.title = "Hey, it's a thing!" | ||
# Encode + decode | ||
b = ui._view_from_dict(ui2.ui_io._view_to_dict(a), globals(), locals()) | ||
# Check that type and attributes were preserved | ||
self.assertIsInstance(b, type(a)) | ||
self.assertEqual(a.title, b.title) | ||
|
||
if __name__ == "__main__": | ||
if has_coverage: | ||
cov = coverage.Coverage(source=["ui2"]) | ||
cov.start() | ||
|
||
unittest.main(exit=False) | ||
|
||
if has_coverage: | ||
print("\n") | ||
cov.stop() | ||
cov.report() | ||
else: | ||
print("Install the 'coverage' module with StaSh to see more detailed " | ||
"reports!") | ||
|