Code Monkey home page Code Monkey logo

maya-mock's Introduction

maya_mock

Actions codecov Code style: black

A mock for Autodesk Maya and it's cmds and pymel API.

Originally developed to ease testing of omtk2.

Installation

You can install the project with all it's dependencies with pip. Navigate to the root directory and run:

pip install .

Testing

To run the tests you'll need to install tox.

pip install tox

Then assuming you have python-2, python-3 and maya-2017 on your system, you can run all checks with:

tox

Tox tips

You can run individual checks with the -e flag. See the tox.ini file for the available targets.

tox -e unit-py2.7

You can also pass additional arguments to your tests with the -- flag. For example, here's how to run a single test named test_node_shape_transform_melobject in python-2.7:

tox -e unit-py2.7 -- -k test_node_shape_transform_melobject

Usage

You can create a session and interact with it directly.

import maya_mock
session = maya_mock.MockedSession()
session.create_node('transform', name='test')

You can also interact with a session via a binding like cmds or pymel.

import maya_mock
session = maya_mock.MockedSession()
cmds = maya_mock.MockedCmdsSession(session)
cmds.createNode('transform', name='test')
import maya_mock
session = maya_mock.MockedSession()
pymel = maya_mock.MockedPymelSession(session)
pymel.createNode('transform', name='test')

Schemas

A schema is a snapshot of a Maya version.

You can generate a search from a maya session with this command:

from maya_mock import MockedSessionSchema
schema = MockedSessionSchema.generate()

You can also use generate a schema from anywhere with this simple script:

./generate ./schemas/test_schema.json

By default, a mocked session instance is schema-less. This mean that a scene will be truly empty and no node type are registered. Off course, a Maya installation is not as minimal, some objects are pre-registered and an empty scene is not empty.

When initializing a session, you can provide the schema to use:

from maya_mock import MockedSession, MockedSessionSchema
schema = MockedSessionSchema.from_json_file('/path/to.json')
session = MockedSession(schema=schema)

Decorators

You also have access to decorators that will temporary expose a binding. This is usefull if you have want to use the mock with already existing code.

These decorators will temporary patch sys.modules so that any import on maya.cmds or pymel will import the mock.

import maya_mock
from maya_mock.decorators import mock_cmds, mock_pymel

session = maya_mock.MockedSession()

with mock_cmds(session) as cmds:
    pass  # Some code


with mock_pymel(session) as pymel:
    pass  # Some code

Contributing

Any contributions are welcome in the form of a PR!

maya-mock's People

Contributors

renaudll avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.