Skip to content
Permalink
Browse files

First pass at using pytest instead of unittest.

  • Loading branch information...
captainhammy committed Sep 7, 2019
1 parent defe5d8 commit c14030e85ff928153d66e0607d3c77ec46d0415c
Showing with 2,660 additions and 2,983 deletions.
  1. +5 −25 bin/run_tests.py
  2. +3 −0 pytest.ini
  3. +2 −1 requirements.txt
  4. +29 −30 tests/events/events/test_rop_render.py
  5. +10 −10 tests/events/events/test_scene_load.py
  6. +13 −13 tests/events/test_callbacks.py
  7. +29 −28 tests/events/test_event.py
  8. +13 −13 tests/events/test_group.py
  9. +32 −34 tests/events/test_item.py
  10. +31 −30 tests/events/test_manager.py
  11. +122 −121 tests/events/test_stats.py
  12. +658 −751 tests/inline/test_api.py
  13. +253 −286 tests/inline/test_api_integration.py
  14. +85 −98 tests/inline/test_utils.py
  15. +25 −35 tests/logging/test_adapters.py
  16. +12 −11 tests/logging/test_shellio.py
  17. +10 −10 tests/nodes/styles/test_event.py
  18. +64 −63 tests/nodes/styles/test_manager.py
  19. +59 −61 tests/nodes/styles/test_styles.py
  20. +7 −14 tests/nodes/test_badges.py
  21. +130 −147 tests/pyfilter/operations/test_deepimage.py
  22. +178 −272 tests/pyfilter/operations/test_ipoverrides.py
  23. +6 −18 tests/pyfilter/operations/test_logoutput.py
  24. +48 −33 tests/pyfilter/operations/test_operation.py
  25. +41 −41 tests/pyfilter/operations/test_primaryimage.py
  26. +142 −118 tests/pyfilter/operations/test_setproperties.py
  27. +28 −29 tests/pyfilter/operations/test_settilecallback.py
  28. +66 −74 tests/pyfilter/operations/test_zdepth.py
  29. +27 −33 tests/pyfilter/test_manager.py
  30. +58 −76 tests/pyfilter/test_property.py
  31. +48 −68 tests/pyfilter/test_utils.py
  32. +221 −254 tests/sohohooks/aovs/test_aov.py
  33. +132 −107 tests/sohohooks/aovs/test_manager.py
  34. +37 −33 tests/sohohooks/test_manager.py
  35. +8 −11 tests/ui/menus/test_opmenu.py
  36. +28 −35 tests/ui/menus/test_parmmenu.py
@@ -5,35 +5,15 @@
# IMPORTS
# =============================================================================

# Standard Library Imports
import os
import unittest

# Third Party Imports
import coverage
import six
import pytest

# Houdini Imports
import hou

# Start the coverage reporting.
cov = coverage.Coverage()
cov.start()

# Find and run tests
loader = unittest.TestLoader()
suite = loader.discover(".")
runner = unittest.TextTestRunner()
result = runner.run(suite)

# Stop the coverage operation, generate reports.
cov.stop()
cov.save()
cov.html_report()
cov.xml_report()
# =============================================================================

html_path = os.path.join(os.path.realpath(os.path.curdir), "coverage_html_report/index.html")
six.print_("View coverage report at file://{}".format(html_path))
result = pytest.main()

if not result.wasSuccessful():
hou.exit(1)
if not result:
hou.exit(result)
@@ -0,0 +1,3 @@
[pytest]
addopts = --cov --cov-report=html

@@ -1,9 +1,10 @@
coverage
enum34
humanfriendly
jinja2
mock
numpy
pytest
pytest-cov
requets
scipy
six
@@ -4,9 +4,11 @@
# IMPORTS
# =============================================================================

# Python Imports
# Standard Library Imports
import imp

# Third Party Imports
from mock import MagicMock, patch
import unittest

# Houdini Toolbox Imports
import ht.events.events.rop_render
@@ -17,21 +19,23 @@
# Houdini Imports
import hou

reload(ht.events.events.rop_render)
# Reload the module to test to capture load evaluation since it has already
# been loaded.
imp.reload(ht.events.events.rop_render)


# =============================================================================
# CLASSES
# =============================================================================

class Test_RopRenderEvent(unittest.TestCase):
class Test_RopRenderEvent(object):
"""Test ht.events.events.rop_render.RopRenderEvent class."""

def test___init__(self):
event = ht.events.events.rop_render.RopRenderEvent()

self.assertIsNone(event._frame_start)
self.assertIsNone(event._render_start)
assert event._frame_start is None
assert event._render_start is None

expected_map = {
RopEvents.PreRender: HoudiniEventItem((event.pre_render,)),
@@ -41,7 +45,7 @@ def test___init__(self):
RopEvents.PostWrite: HoudiniEventItem((event.post_write,)),
}

self.assertEqual(event.event_map, expected_map)
assert event.event_map == expected_map

# Methods

@@ -57,7 +61,7 @@ def test_pre_frame(self, mock_logger):

event.pre_frame(scriptargs)

self.assertEqual(event._frame_start, 123)
assert event._frame_start == 123

mock_logger.info.assert_called()

@@ -73,7 +77,7 @@ def test_pre_render__with_frame_range(self, mock_logger):

event.pre_render(scriptargs)

self.assertEqual(event._render_start, 123)
assert event._render_start == 123

mock_logger.info.assert_called()

@@ -87,7 +91,7 @@ def test_pre_render__no_frame_range(self, mock_logger):

event.pre_render(scriptargs)

self.assertEqual(event._render_start, 123)
assert event._render_start == 123

mock_logger.info.assert_called()

@@ -172,7 +176,7 @@ def test_post_write__no_path(self, mock_logger):
mock_logger.info.assert_called()


class Test__get_target_file(unittest.TestCase):
class Test__get_target_file(object):
"""Test ht.events.events.rop_render._get_target_file."""

def test_geometry(self):
@@ -186,15 +190,15 @@ def test_geometry(self):

result = ht.events.events.rop_render._get_target_file(mock_node)

self.assertEqual(result, "/var/tmp/test.bgeo")
assert result == "/var/tmp/test.bgeo"
mock_node.evalParm.assert_called_with("sopoutput")

# Try again but with rop_geometry.
mock_type.name.return_value = "rop_geometry"

result = ht.events.events.rop_render._get_target_file(mock_node)

self.assertEqual(result, "/var/tmp/test.bgeo")
assert result == "/var/tmp/test.bgeo"
mock_node.evalParm.assert_called_with("sopoutput")

def test_alembic(self):
@@ -208,15 +212,15 @@ def test_alembic(self):

result = ht.events.events.rop_render._get_target_file(mock_node)

self.assertEqual(result, "/var/tmp/test.abc")
assert result == "/var/tmp/test.abc"
mock_node.evalParm.assert_called_with("filename")

# Try again but with rop_alembic.
mock_type.name.return_value = "rop_alembic"

result = ht.events.events.rop_render._get_target_file(mock_node)

self.assertEqual(result, "/var/tmp/test.abc")
assert result == "/var/tmp/test.abc"
mock_node.evalParm.assert_called_with("filename")

def test_ifd(self):
@@ -231,7 +235,7 @@ def test_ifd(self):

result = ht.events.events.rop_render._get_target_file(mock_node)

self.assertEqual(result, "/var/tmp/test.ifd")
assert result == "/var/tmp/test.ifd"
mock_node.evalParm.assert_any_call("soho_outputmode")
mock_node.evalParm.assert_any_call("soho_diskfile")

@@ -242,7 +246,7 @@ def test_ifd(self):

result = ht.events.events.rop_render._get_target_file(mock_node)

self.assertEqual(result, "/var/tmp/test.exr")
assert result == "/var/tmp/test.exr"
mock_node.evalParm.assert_any_call("soho_outputmode")
mock_node.evalParm.assert_any_call("vm_picture")

@@ -255,10 +259,10 @@ def test_unknown(self):

result = ht.events.events.rop_render._get_target_file(mock_node)

self.assertIsNone(result)
assert result is None


class Test__print_frame_write(unittest.TestCase):
class Test__print_frame_write(object):
"""Test ht.events.events.rop_render._print_frame_write."""

def test_no_path(self):
@@ -298,7 +302,7 @@ def test_path_no_post_script(self, mock_logger):
mock_logger.info.assert_called()


class Test_build_scriptargs(unittest.TestCase):
class Test_build_scriptargs(object):
"""Test ht.events.events.rop_render.build_scriptargs."""

@patch("ht.events.events.rop_render._get_target_file")
@@ -318,7 +322,7 @@ def test_no_args(self, mock_time, mock_hou, mock_get):
"time": 123,
}

self.assertEqual(result, expected)
assert result == expected

mock_get.assert_not_called()

@@ -345,7 +349,7 @@ def test_no_trange(self, mock_time, mock_hou, mock_get):
"path": "/var/tmp/test.bgeo",
}

self.assertEqual(result, expected)
assert result == expected

mock_get.assert_called_with(mock_node)

@@ -375,7 +379,7 @@ def test_trange_off(self, mock_time, mock_hou, mock_get):
"path": "/var/tmp/test.bgeo"
}

self.assertEqual(result, expected)
assert result == expected

mock_get.assert_called_with(mock_node)

@@ -406,7 +410,7 @@ def test_found_frame_range(self, mock_time, mock_hou, mock_get):
"path": "/var/tmp/test.bgeo"
}

self.assertEqual(result, expected)
assert result == expected

mock_get.assert_called_with(mock_node)

@@ -437,11 +441,6 @@ def test_no_path(self, mock_time, mock_hou, mock_get):
"time": 123
}

self.assertEqual(result, expected)
assert result == expected

mock_get.assert_called_with(mock_node)

# =============================================================================

if __name__ == '__main__':
unittest.main()
@@ -4,23 +4,28 @@
# IMPORTS
# =============================================================================

# Python Imports
# Standard Library Imports
import imp

# Third Party Imports
from mock import patch
import unittest

# Houdini Toolbox Imports
import ht.events.events.scene_load

from ht.events.item import HoudiniEventItem
from ht.events.types import SceneEvents

reload(ht.events.events.scene_load)
# Reload the module to test to capture load evaluation since it has already
# been loaded.
imp.reload(ht.events.events.scene_load)


# =============================================================================
# CLASSES
# =============================================================================

class Test_SceneLoadEvent(unittest.TestCase):
class Test_SceneLoadEvent(object):
"""Test ht.events.events.scene_load.SceneLoadEvent class."""

def test___init__(self):
@@ -30,7 +35,7 @@ def test___init__(self):
SceneEvents.Load: HoudiniEventItem((event.clear_session_settings,)),
}

self.assertEqual(event.event_map, expected_map)
assert event.event_map == expected_map

# Methods

@@ -42,8 +47,3 @@ def test_clear_session_settings(self, mock_hscript):
event.clear_session_settings({})

mock_hscript.assert_called_with("set -u HOUDINI_ICON_CACHE_DIR")

# =============================================================================

if __name__ == '__main__':
unittest.main()
@@ -4,20 +4,25 @@
# IMPORTS
# =============================================================================

# Python Imports
# Standard Library Imports
import imp

# Third Party Imports
from mock import MagicMock, patch
import unittest

# Houdini Toolbox Imports
from ht.events import SceneEvents, callbacks

reload(callbacks)
# Reload the module to test to capture load evaluation since it has already
# been loaded.
imp.reload(callbacks)


# =============================================================================
# CLASSES
# =============================================================================

class Test__atexit_callback(unittest.TestCase):
class Test__atexit_callback(object):
"""Test ht.events.callbacks._atexit_callback."""

@patch("ht.events.callbacks.run_event")
@@ -28,7 +33,7 @@ def test(self, mock_run):
mock_run.assert_called_with(SceneEvents.Exit)


class Test__emit_ui_available(unittest.TestCase):
class Test__emit_ui_available(object):
"""Test ht.events.callbacks._emit_ui_available."""

@patch("ht.events.callbacks.run_event")
@@ -39,7 +44,7 @@ def test(self, mock_run):
mock_run.assert_called_with(SceneEvents.WhenUIAvailable)


class Test__hip_event_callback(unittest.TestCase):
class Test__hip_event_callback(object):
"""Test ht.events.callbacks._hip_event_callback."""

@patch("ht.events.callbacks.run_event")
@@ -71,7 +76,7 @@ def test_no_event_name(self, mock_run):
mock_run.assert_not_called()


class Test__register_when_ui_available(unittest.TestCase):
class Test__register_when_ui_available(object):
"""Test ht.events.callbacks._register_when_ui_available."""

def test(self):
@@ -89,7 +94,7 @@ def test(self):
mock_hdefereval.executeDeferredAfterWaiting.assert_called_once_with(callbacks._emit_ui_available, 1)


class Test_register_callbacks(unittest.TestCase):
class Test_register_callbacks(object):
"""Test ht.events.callbacks.register_callbacks."""

@patch("ht.events.callbacks.hou.hipFile.addEventCallback")
@@ -124,8 +129,3 @@ def test_ui_available(self, mock_available, mock_register, mock_emit, mock_add):
mock_emit.assert_called_once()

mock_add.assert_called_with(callbacks._hip_event_callback)

# =============================================================================

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

0 comments on commit c14030e

Please sign in to comment.
You can’t perform that action at this time.