From e880a3c7af988706e2d0c83a144a33c2e401aecd Mon Sep 17 00:00:00 2001 From: "Md. Almas Ali" Date: Tue, 30 May 2023 02:12:47 +0600 Subject: [PATCH] Added tests for fronty internal checking. --- tests/__main__.py | 21 +++++++++++ tests/test_elements.py | 86 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 tests/__main__.py create mode 100644 tests/test_elements.py diff --git a/tests/__main__.py b/tests/__main__.py new file mode 100644 index 0000000..eeabd2c --- /dev/null +++ b/tests/__main__.py @@ -0,0 +1,21 @@ +''' +The main test module for the fronty package. +Here we will call this module from the command line to run all the tests at once. + +Usage: + python -m tests + +''' + +import unittest + + +def main(): + '''Runs all the tests at once.''' + suite = unittest.TestLoader().discover('tests', pattern='test_*.py') + runner = unittest.TextTestRunner() + runner.run(suite) + + +if __name__ == '__main__': + main() diff --git a/tests/test_elements.py b/tests/test_elements.py new file mode 100644 index 0000000..78008ec --- /dev/null +++ b/tests/test_elements.py @@ -0,0 +1,86 @@ +import unittest +from fronty import html + + +class TestElements(unittest.TestCase): + '''Test the BaseElement class.''' + + def test_base_element(self): + ''' + Test the BaseElement class. + This is the base class for all elements. It is used to create new elements. + ''' + self.assertEqual( + + # Test case + html.BaseElement( + 'tag', + ) + .attr('name', 'value') + .id('id') + .class_('class1 class2 classNth') + .style(color='red', background='blue') + .render(), + + # Expected result + '' + ) + + def test_empty_element(self): + '''Test the Empty element.''' + self.assertEqual( + html.Empty().render(), + '' + ) + + def test_website_elements(self): + '''Test the website elements.''' + self.assertEqual( + html.Html( + html.Head( + html.Meta(charset="utf-8"), + html.Title("Test case"), + ), + html.Body( + html.Div( + html.Text( + 'This is a paragraph.' + ) + ).class_('container'), + + html.Footer( + html.Text( + 'This is a footer.' + ) + ).id('footer') + ), + ).render(), + + 'Test case

This is a paragraph.

' + ) + + + def test_attr_counts(self): + '''Test the attr counts method.''' + + # Test case + self.assertEqual( + html.Div( + html.Input() + .attr('type', 'text') + .attr('name', 'InputElement') + .attr('value', 'InputValue') + .attr('placeholder', 'InputPlaceholder') + .attr('required', True) + .attr('disabled', False) + .attr('readonly', False) + , + ), + + # Expected result + '
' + ) + + +if __name__ == '__main__': + unittest.main()