Skip to content

Commit

Permalink
use inflection package to convert camel case to underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
bubenkoff committed Apr 9, 2015
1 parent a459f39 commit d513492
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
@@ -1,6 +1,11 @@
Changelog
=========

1.0.1
-----

- use ``inflection`` package to convert camel case to underscore (bubenkoff)

1.0.0
-----

Expand Down
4 changes: 2 additions & 2 deletions pytest_factoryboy/__init__.py
@@ -1,11 +1,11 @@
"""pytest-factoryboy public API."""

__version__ = '1.0.0'
__version__ = '1.0.1'

try:
from .fixture import register

__all__ = [register.__name__]
except ImportError:
except ImportError: # pragma: no cover
# avoid import errors when only __version__ is needed (for setup.py)
pass
12 changes: 4 additions & 8 deletions pytest_factoryboy/fixture.py
@@ -1,21 +1,17 @@
"""Factory boy fixture integration."""
import re
import sys
import inspect
from types import CodeType

import factory
import inflection
import pytest
import six


SEPARATOR = "__"


def to_underscore(value):
return re.sub("(?!^)([A-Z]+)", r"_\1", value).lower()


def register(factory_class):
"""Register fixtures for the factory class."""
module = get_caller_module()
Expand Down Expand Up @@ -45,11 +41,11 @@ def register(factory_class):


def get_model_name(factory_class):
return to_underscore(factory_class._meta.model.__name__)
return inflection.underscore(factory_class._meta.model.__name__)


def get_factory_name(factory_class):
return to_underscore(factory_class.__name__)
return inflection.underscore(factory_class.__name__)


def get_deps(factory_class, parent_factory_class=None):
Expand Down Expand Up @@ -112,7 +108,7 @@ def attr_fixture():


def make_subfactory_fixture(factory_class):
fixture = to_underscore(factory_class._meta.model.__name__)
fixture = inflection.underscore(factory_class._meta.model.__name__)

@pytest.fixture
def subfactory_fixture(request):
Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -40,6 +40,7 @@
] + [("Programming Language :: Python :: %s" % x) for x in "2.6 2.7 3.0 3.1 3.2 3.3 3.4".split()],
install_requires=[
"six",
"inflection",
"factory_boy",
],
# the following makes a plugin available to py.test
Expand Down

0 comments on commit d513492

Please sign in to comment.