Skip to content

Commit

Permalink
add unit test and change field name
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Apr 25, 2018
1 parent 241692f commit 056c125
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/python/pants/backend/native/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pants.util.osutil import get_normalized_os_name


class Platform(datatype('Platform', ['normed_os_name'])):
class Platform(datatype('Platform', ['normalized_os_name'])):

def __new__(cls):
return super(Platform, cls).__new__(cls, get_normalized_os_name())
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/python/tasks/setup_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def as_env_dict(self):

@rule(SetupPyInvocationEnvironment, [Select(Platform), Select(NativeToolchain)])
def get_setup_py_env(platform, native_toolchain):
is_linux = platform.normed_os_name == 'linux'
is_linux = platform.normalized_os_name == 'linux'
joined_path = get_joined_path(
native_toolchain.path_entries(), os.environ.copy(), prepend=is_linux)
return SetupPyInvocationEnvironment(joined_path)
Expand Down
3 changes: 3 additions & 0 deletions tests/python/pants_test/init/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ python_tests(
'3rdparty/python:setuptools',
'src/python/pants/base:exceptions',
'src/python/pants/build_graph',
'src/python/pants/engine:rules',
'src/python/pants/engine:selectors',
'src/python/pants/goal',
'src/python/pants/goal:task_registrar',
'src/python/pants/init',
'src/python/pants/option',
'src/python/pants/subsystem',
'src/python/pants/util:contextutil',
'src/python/pants/util:dirutil',
'src/python/pants/util:objects',
'tests/python/pants_test:base_test',
'tests/python/pants_test/subsystem:subsystem_utils'
],
Expand Down
28 changes: 27 additions & 1 deletion tests/python/pants_test/init/test_extension_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
from pants.build_graph.build_configuration import BuildConfiguration
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.build_graph.target import Target
from pants.engine.rules import RootRule, rule
from pants.engine.selectors import Select
from pants.goal.goal import Goal
from pants.goal.task_registrar import TaskRegistrar
from pants.init.extension_loader import (PluginLoadOrderError, PluginNotFound, load_backend,
load_backends_and_plugins, load_plugins)
from pants.subsystem.subsystem import Subsystem
from pants.task.task import Task
from pants.util.objects import datatype


class MockMetadata(EmptyProvider):
Expand Down Expand Up @@ -80,6 +83,19 @@ class DummyTask(Task):
def execute(self): return 42


class RootType(datatype('RootType', ['value'])):
pass


class WrapperType(datatype('WrapperType', ['value'])):
pass


@rule(WrapperType, [Select(RootType)])
def example_rule(root_type):
yield WrapperType(root_type.value)


class LoaderTest(unittest.TestCase):

def setUp(self):
Expand All @@ -93,7 +109,7 @@ def tearDown(self):

@contextmanager
def create_register(self, build_file_aliases=None, register_goals=None, global_subsystems=None,
module_name='register'):
rules=None, module_name='register'):

package_name = b'__test_package_{0}'.format(uuid.uuid4().hex)
self.assertFalse(package_name in sys.modules)
Expand All @@ -113,6 +129,7 @@ def register_entrypoint(function_name, function):
register_entrypoint('build_file_aliases', build_file_aliases)
register_entrypoint('global_subsystems', global_subsystems)
register_entrypoint('register_goals', register_goals)
register_entrypoint('rules', rules)

yield package_name
finally:
Expand All @@ -125,6 +142,7 @@ def assert_empty_aliases(self):
self.assertEqual(0, len(registered_aliases.objects))
self.assertEqual(0, len(registered_aliases.context_aware_object_factories))
self.assertEqual(self.build_configuration.subsystems(), set())
self.assertEqual(0, len(self.build_configuration.rules()))

def test_load_valid_empty(self):
with self.create_register() as backend_package:
Expand Down Expand Up @@ -292,6 +310,14 @@ def global_subsystems():
self.assertEqual(self.build_configuration.subsystems(),
{DummySubsystem1, DummySubsystem2})

def test_rules(self):
def rules():
return [example_rule, RootRule(RootType)]
with self.create_register(rules=rules) as backend_package:
load_backend(self.build_configuration, backend_package)
self.assertEqual(self.build_configuration.rules(),
[example_rule, RootRule(RootType)])

def test_backend_plugin_ordering(self):
def reg_alias():
return BuildFileAliases(targets={'override-alias': DummyTarget2})
Expand Down

0 comments on commit 056c125

Please sign in to comment.