Skip to content

Commit

Permalink
autogen tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sirfoga committed Oct 13, 2018
1 parent e6597ad commit 91b542e
Show file tree
Hide file tree
Showing 59 changed files with 2,564 additions and 480 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Say you want to
- [edit the tags of all the songs in a folder](#using-pyhal)
- [plot 2D/3D or even 4D points](#using-pyhal-1)
- [fetch the RSS feed of a YouTube channel](#using-pyhal-2)
- [generate tests code for a module](#generate-module-tests-code)

If you want to do this stuff in a fast and easy way, this library is for you

Expand Down Expand Up @@ -90,6 +91,20 @@ channel_name = "my awesome channel"
channel_feed = YoutubeChannel(channel_name).get_feed_url()
```

### Generate module tests code

#### Classic way

No easy way that I know of

#### Using `pyhal`
```python
from hal.tests.gen import TestWriter
src = "path to module source folder"
out = "path to output folder"
w = TestWriter(src)
w.write_tests(out)
```

## Install
<a href="https://pypi.org/project/PyHal/"><img alt="PyPI version" src="https://badge.fury.io/py/PyHal.svg"></a> <a href="https://requires.io/github/sirfoga/pyhal/requirements/?branch=master"><img alt="Requirements Status" src="https://requires.io/github/sirfoga/pyhal/requirements.svg?branch=master"></a> <a href="https://snyk.io/test/github/sirfoga/pyhal?targetFile=requirements.txt"><img src="https://snyk.io/test/github/sirfoga/pyhal/badge.svg?targetFile=requirements.txt" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/sirfoga/pyhal?targetFile=requirements.txt" style="max-width:100%;"></a>
Expand Down
23 changes: 23 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,29 @@ Using ``pyhal``
>>> channel_name = "my awesome channel"
>>> channel_feed = YoutubeChannel(channel_name).get_feed_url()
Generate module tests code
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. _classic-way-3:

Classic way
^^^^^^^^^^^

No easy way that I know of

.. _using-pyhal-3:

Using ``pyhal``
^^^^^^^^^^^^^^^

.. code:: python
>>> from hal.tests.gen import TestWriter
>>> src = "path to module source folder"
>>> out = "path to output folder"
>>> w = TestWriter(src)
>>> w.write_tests(out)
Install
-------
Expand Down
2 changes: 1 addition & 1 deletion hal/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__description__ = 'Your swiss knife to perform fast and easy pythonic stuff'
__url__ = 'https://sirfoga.github.io/pyhal/'
__version__ = '10.2.3'
__build__ = 'b6ced3eee748fff6c16e7093d38f4ebe3f48c660'
__build__ = 'de8b8fd4a82ec5d5a8f0179b003996bdbbdf8c40'
__author__ = 'Stefano Fogarollo'
__author_email__ = 'sirfoga@protonmail.com'
__license__ = 'MIT'
Expand Down
20 changes: 13 additions & 7 deletions hal/tests/autogen.py → hal/tests/gen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from meta.attributes import get_modules, ModuleFile, MODULE_SEP
from hal.meta.attributes import get_modules, ModuleFile, MODULE_SEP

DOCS = "\"\"\"{}\"\"\""
TODO = "# todo auto generated method stub"
Expand Down Expand Up @@ -47,11 +47,12 @@ def get_imports(to_import):
]

@staticmethod
def get_functions_tests(functions, indent=0):
def get_functions_tests(functions, indent=0, static=False):
"""Auto generates functions tests
:param functions: list of functions
:param indent: indentation level
:param static: whether is a static method or not
:return: list of tests
"""

Expand All @@ -63,12 +64,17 @@ def get_functions_tests(functions, indent=0):
for func in functions:
name = "test_" + func.get_name()
signature = METHOD_KEYWORD + " " + name + "():"
content = "assert True " + TODO
content = "pass " + TODO
docs = DOCS.format("Tests " + func.full_package + " method")

test = start_indent + signature
if static:
test = start_indent + "@staticmethod" + "\n"
else:
test = ""

test += start_indent + signature
test += new_line + docs
test += new_line + content
test += "\n" + new_line + content

tests.append(test)

Expand Down Expand Up @@ -96,10 +102,10 @@ def get_classes_tests(classes, indent=0):

if functions:
content = "\n\n".join(
TestWriter.get_functions_tests(functions, indent + 1)
TestWriter.get_functions_tests(functions, indent + 1, True)
)
else:
content = inner_indent + TODO
content = inner_indent + "pass " + TODO

test = start_indent + signature
test += new_line + cl_docs
Expand Down
10 changes: 10 additions & 0 deletions tests/test_hal_charts_correlation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-


"""Tests hal.charts.correlation implementation"""


def test_create_correlation_matrix_plot():
"""Tests hal.charts.correlation.create_correlation_matrix_plot method"""

pass # todo auto generated method stub
44 changes: 44 additions & 0 deletions tests/test_hal_charts_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-


"""Tests hal.charts.models implementation"""


class TestSimpleChart:
"""Tests SimpleChart class"""

@staticmethod
def test_setup():
"""Tests hal.charts.models.SimpleChart.setup method"""

pass # todo auto generated method stub

@staticmethod
def test_get_fig():
"""Tests hal.charts.models.SimpleChart.get_fig method"""

pass # todo auto generated method stub

@staticmethod
def test_get_ax():
"""Tests hal.charts.models.SimpleChart.get_ax method"""

pass # todo auto generated method stub

@staticmethod
def test_create_bar_chart():
"""Tests hal.charts.models.SimpleChart.create_bar_chart method"""

pass # todo auto generated method stub

@staticmethod
def test_create_multiple_bar_chart():
"""Tests hal.charts.models.SimpleChart.create_multiple_bar_chart method"""

pass # todo auto generated method stub

@staticmethod
def test_create_sym_log_bar_chart():
"""Tests hal.charts.models.SimpleChart.create_sym_log_bar_chart method"""

pass # todo auto generated method stub
104 changes: 104 additions & 0 deletions tests/test_hal_charts_plotter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# -*- coding: utf-8 -*-


"""Tests hal.charts.plotter implementation"""


class TestPlotter:
"""Tests Plotter class"""

@staticmethod
def test_scatter():
"""Tests hal.charts.plotter.Plotter.scatter method"""

pass # todo auto generated method stub

@staticmethod
def test_param():
"""Tests hal.charts.plotter.Plotter.param method"""

pass # todo auto generated method stub

@staticmethod
def test_plot():
"""Tests hal.charts.plotter.Plotter.plot method"""

pass # todo auto generated method stub

@staticmethod
def test_show_plot():
"""Tests hal.charts.plotter.Plotter.show_plot method"""

pass # todo auto generated method stub


class TestPlot2d:
"""Tests Plot2d class"""

@staticmethod
def test_scatter():
"""Tests hal.charts.plotter.Plot2d.scatter method"""

pass # todo auto generated method stub

@staticmethod
def test_param():
"""Tests hal.charts.plotter.Plot2d.param method"""

pass # todo auto generated method stub

@staticmethod
def test_plot():
"""Tests hal.charts.plotter.Plot2d.plot method"""

pass # todo auto generated method stub


class TestPlot3d:
"""Tests Plot3d class"""

@staticmethod
def test_scatter():
"""Tests hal.charts.plotter.Plot3d.scatter method"""

pass # todo auto generated method stub

@staticmethod
def test_param():
"""Tests hal.charts.plotter.Plot3d.param method"""

pass # todo auto generated method stub

@staticmethod
def test_plot():
"""Tests hal.charts.plotter.Plot3d.plot method"""

pass # todo auto generated method stub


class TestPlot4d:
"""Tests Plot4d class"""

@staticmethod
def test_scatter():
"""Tests hal.charts.plotter.Plot4d.scatter method"""

pass # todo auto generated method stub

@staticmethod
def test_param():
"""Tests hal.charts.plotter.Plot4d.param method"""

pass # todo auto generated method stub

@staticmethod
def test_plot():
"""Tests hal.charts.plotter.Plot4d.plot method"""

pass # todo auto generated method stub

@staticmethod
def test_plot_type():
"""Tests hal.charts.plotter.Plot4d.plot_type method"""

pass # todo auto generated method stub
70 changes: 70 additions & 0 deletions tests/test_hal_cvs_gits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-


"""Tests hal.cvs.gits implementation"""


class TestDiff:
"""Tests Diff class"""

@staticmethod
def test_get_totals():
"""Tests hal.cvs.gits.Diff.get_totals method"""

pass # todo auto generated method stub


class TestCommit:
"""Tests Commit class"""

@staticmethod
def test_get_author():
"""Tests hal.cvs.gits.Commit.get_author method"""

pass # todo auto generated method stub


class TestRepository:
"""Tests Repository class"""

@staticmethod
def test_get_last_commit():
"""Tests hal.cvs.gits.Repository.get_last_commit method"""

pass # todo auto generated method stub

@staticmethod
def test_get_diff_amounts():
"""Tests hal.cvs.gits.Repository.get_diff_amounts method"""

pass # todo auto generated method stub

@staticmethod
def test_get_diff():
"""Tests hal.cvs.gits.Repository.get_diff method"""

pass # todo auto generated method stub

@staticmethod
def test_get_version():
"""Tests hal.cvs.gits.Repository.get_version method"""

pass # todo auto generated method stub

@staticmethod
def test_get_new_version():
"""Tests hal.cvs.gits.Repository.get_new_version method"""

pass # todo auto generated method stub

@staticmethod
def test_get_pretty_version():
"""Tests hal.cvs.gits.Repository.get_pretty_version method"""

pass # todo auto generated method stub

@staticmethod
def test_get_last_commit_hash():
"""Tests hal.cvs.gits.Repository.get_last_commit_hash method"""

pass # todo auto generated method stub

0 comments on commit 91b542e

Please sign in to comment.