Skip to content

Commit

Permalink
Port BaseTest to v2 engine
Browse files Browse the repository at this point in the history
This reverts commit 45d0f3a.
  • Loading branch information
stuhood committed Mar 19, 2018
1 parent ac0b7e4 commit b0aafa8
Show file tree
Hide file tree
Showing 143 changed files with 958 additions and 334 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ python_tests(
'contrib/android/tests/python/pants_test/contrib/android:android_base',
'src/python/pants/util:contextutil',
'src/python/pants/util:dirutil',
'tests/python/pants_test:base_test',
'tests/python/pants_test:test_base',
]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

from pants.util.contextutil import environment_as, temporary_dir
from pants.util.dirutil import touch
from pants_test.base_test import BaseTest
from pants_test.contrib.android.test_android_base import distribution
from pants_test.test_base import TestBase

from pants.contrib.android.distribution.android_distribution import AndroidDistribution


class TestAndroidDistribution(BaseTest):
class TestAndroidDistribution(TestBase):
"""Test the AndroidDistribution class."""

@contextmanager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ python_tests(
dependencies = [
'contrib/buildgen/src/python/pants/contrib/buildgen:build_file_manipulator',
'src/python/pants/build_graph',
'tests/python/pants_test:base_test',
'tests/python/pants_test:test_base',
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from textwrap import dedent

from pants.build_graph.address import Address
from pants_test.base_test import BaseTest
from pants_test.test_base import TestBase

from pants.contrib.buildgen.build_file_manipulator import (BuildFileManipulator,
BuildTargetParseError)


class BuildFileManipulatorTest(BaseTest):
class BuildFileManipulatorTest(TestBase):

def setUp(self):
super(BuildFileManipulatorTest, self).setUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ python_tests(
'contrib/errorprone/src/python/pants/contrib/errorprone/tasks',
'tests/python/pants_test/jvm:nailgun_task_test_base',
'tests/python/pants_test/option/util',
'tests/python/pants_test:base_test',
'tests/python/pants_test:test_base',
]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ python_tests(
'contrib/findbugs/src/python/pants/contrib/findbugs/tasks',
'tests/python/pants_test/jvm:nailgun_task_test_base',
'tests/python/pants_test/option/util',
'tests/python/pants_test:base_test',
'tests/python/pants_test:test_base',
]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create(cls, parse_context, **kwargs):
if 'name' in kwargs:
raise TargetDefinitionException(Address(parse_context.rel_path, kwargs['name']).spec,
'A {} does not accept a name; instead, the name is taken '
'from the the BUILD file location.'.format(cls.alias()))
'from the BUILD file location.'.format(cls.alias()))
name = os.path.basename(parse_context.rel_path)

if 'sources' in kwargs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ python_tests(
dependencies=[
'contrib/go/src/python/pants/contrib/go/subsystems',
'tests/python/pants_test/subsystem:subsystem_utils',
'tests/python/pants_test:base_test',
'tests/python/pants_test:test_base',
]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from pants_test import base_test
from pants_test.subsystem.subsystem_util import global_subsystem_instance
from pants_test.test_base import TestBase

from pants.contrib.go.subsystems.fetcher_factory import FetcherFactory


class FetchersTest(base_test.BaseTest):
class FetchersTest(TestBase):
def fetcher(self, import_path):
fetcher_factory = global_subsystem_instance(FetcherFactory)
return fetcher_factory.get_fetcher(import_path)
Expand Down
4 changes: 2 additions & 2 deletions contrib/go/tests/python/pants_test/contrib/go/targets/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ python_library(
'contrib/go/src/python/pants/contrib/go:plugin',
'src/python/pants/build_graph',
'src/python/pants/util:meta',
'tests/python/pants_test:base_test',
'tests/python/pants_test:test_base',
]
)

Expand All @@ -17,6 +17,6 @@ python_tests(
'contrib/go/src/python/pants/contrib/go:plugin',
'contrib/go/src/python/pants/contrib/go/targets',
'src/python/pants/build_graph',
'tests/python/pants_test:base_test',
'tests/python/pants_test:test_base',
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@

from pants.build_graph.address_lookup_error import AddressLookupError
from pants.util.meta import AbstractClass
from pants_test.base_test import BaseTest
from pants_test.test_base import TestBase

from pants.contrib.go.register import build_file_aliases


class GoLocalSourceTestBase(AbstractClass):
# NB: We assume we're mixed into a BaseTest - we can't extend that directly or else unittest tries
# NB: We assume we're mixed into a TestBase - we can't extend that directly or else unittest tries
# to run our test methods in the subclass (OK), and against us (not OK).
# NB: We use aliases and BUILD files to test proper registration of anonymous targets and macros.

@classmethod
def setUpClass(cls):
if not issubclass(cls, BaseTest):
raise TypeError('Subclasses must mix in BaseTest')
if not issubclass(cls, TestBase):
raise TypeError('Subclasses must mix in TestBase')
super(GoLocalSourceTestBase, cls).setUpClass()

def setUp(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from pants_test.base_test import BaseTest
from pants_test.contrib.go.targets.go_local_source_test_base import GoLocalSourceTestBase
from pants_test.test_base import TestBase

from pants.contrib.go.targets.go_binary import GoBinary


class GoBinaryTest(GoLocalSourceTestBase, BaseTest):
class GoBinaryTest(GoLocalSourceTestBase, TestBase):

@property
def target_type(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from pants_test.base_test import BaseTest
from pants_test.contrib.go.targets.go_local_source_test_base import GoLocalSourceTestBase
from pants_test.test_base import TestBase

from pants.contrib.go.targets.go_library import GoLibrary


class GoLibraryTest(GoLocalSourceTestBase, BaseTest):
class GoLibraryTest(GoLocalSourceTestBase, TestBase):

@property
def target_type(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from textwrap import dedent

from pants.build_graph.address_lookup_error import AddressLookupError
from pants_test.base_test import BaseTest
from pants_test.test_base import TestBase

from pants.contrib.go.register import build_file_aliases
from pants.contrib.go.targets.go_remote_library import GoRemoteLibrary


class GoRemoteLibraryTest(BaseTest):
class GoRemoteLibraryTest(TestBase):
# NB: We use aliases and BUILD files to test proper registration of anonymous targets and macros.

def setUp(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ def test_stitch_deps_remote_existing_rev_respected(self):
pkg='prod',
rev='v1.2.3')
pre_execute_files = self.stitch_deps_remote(materialize=True)
self.build_graph.reset() # Force targets to be loaded off disk
self.reset_build_graph(reset_build_files=True) # Force targets to be loaded off disk
print('>>> {}'.format(self.buildroot_files()))
self.assertEqual('v1.2.3', self.target('3rdparty/go/pantsbuild.org/fake:prod').rev)
self.assertEqual({'src/go/src/jane/BUILD', '3rdparty/go/pantsbuild.org/fake/BUILD'},
self.buildroot_files() - pre_execute_files)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ python_tests(
'contrib/jax_ws/src/python/pants/contrib/jax_ws/tasks',
'tests/python/pants_test/jvm:nailgun_task_test_base',
'tests/python/pants_test/option/util',
'tests/python/pants_test:base_test',
'tests/python/pants_test:test_base',
]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ python_tests(
sources=['test_node_remote_module.py'],
dependencies=[
'contrib/node/src/python/pants/contrib/node/targets:node_remote_module',
'tests/python/pants_test:base_test'
'tests/python/pants_test:test_base'
]
)

Expand All @@ -15,6 +15,6 @@ python_tests(
sources=['test_node_package.py'],
dependencies=[
'contrib/node/src/python/pants/contrib/node/targets:node_package',
'tests/python/pants_test:base_test'
'tests/python/pants_test:test_base'
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from pants_test.base_test import BaseTest
from pants_test.test_base import TestBase

from pants.contrib.node.targets.node_package import NodePackage


class NodePackageTest(BaseTest):
class NodePackageTest(TestBase):
def test_implicit_package_name(self):
target = self.make_target(spec=':name', target_type=NodePackage)
self.assertEqual('name', target.address.target_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from pants_test.base_test import BaseTest
from pants_test.test_base import TestBase

from pants.contrib.node.targets.node_remote_module import NodeRemoteModule


class NodeRemoteModuleTest(BaseTest):
class NodeRemoteModuleTest(TestBase):
def test_unconstrained(self):
target1 = self.make_target(spec=':unconstrained1', target_type=NodeRemoteModule)
target2 = self.make_target(spec=':unconstrained2', target_type=NodeRemoteModule, version=None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ python_tests(
'src/python/pants/util:dirutil',
'tests/python/pants_test/backend/python/tasks:python_task_test_base',
'tests/python/pants_test/option/util',
'tests/python/pants_test:base_test',
'tests/python/pants_test:test_base',
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import logging
import textwrap

from pants_test.base_test import BaseTest
from pants_test.test_base import TestBase

from pants.contrib.python.checks.tasks.checkstyle.file_excluder import FileExcluder


logger = logging.getLogger(__name__)


class TestExcluder(BaseTest):
class TestExcluder(TestBase):

def setUp(self):
super(TestExcluder, self).setUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pants.python.python_repos import PythonRepos
from pants_test.backend.python.tasks.python_task_test_base import PythonTaskTestBase

from pants.contrib.python.checks.tasks2.python_eval import PythonEval
from pants.contrib.python.checks.tasks.python_eval import PythonEval


class PythonEvalTest(PythonTaskTestBase):
Expand All @@ -25,7 +25,7 @@ def setUp(self):
self._create_graph(broken_b_library=True)

def _create_graph(self, broken_b_library):
self.reset_build_graph()
self.reset_build_graph(delete_build_files=True)

self.a_library = self.create_python_library('src/python/a', 'a', {'a.py': dedent("""
import inspect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ python_tests(
'contrib/scrooge/src/python/pants/contrib/scrooge/tasks:thrift_util',
'src/python/pants/util:contextutil',
'src/python/pants/util:dirutil',
'tests/python/pants_test:base_test',
'tests/python/pants_test:test_base',
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

from pants.backend.codegen.thrift.java.java_thrift_library import JavaThriftLibrary
from pants.backend.codegen.thrift.java.thrift_defaults import ThriftDefaults
from pants_test.base_test import BaseTest
from pants_test.test_base import TestBase

from pants.contrib.scrooge.tasks.java_thrift_library_fingerprint_strategy import \
JavaThriftLibraryFingerprintStrategy


class JavaThriftLibraryFingerprintStrategyTest(BaseTest):
class JavaThriftLibraryFingerprintStrategyTest(TestBase):

options1 = {'compiler': 'scrooge',
'language': 'java',
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/bin/goal_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from pants.base.cmd_line_spec_parser import CmdLineSpecParser
from pants.base.workunit import WorkUnit, WorkUnitLabel
from pants.bin.engine_initializer import EngineInitializer
from pants.bin.repro import Reproducer
from pants.binaries.binary_util import BinaryUtilPrivate
from pants.build_graph.build_file_parser import BuildFileParser
Expand All @@ -20,6 +19,7 @@
from pants.goal.goal import Goal
from pants.goal.run_tracker import RunTracker
from pants.help.help_printer import HelpPrinter
from pants.init.engine_initializer import EngineInitializer
from pants.init.subprocess import Subprocess
from pants.init.target_roots_calculator import TargetRootsCalculator
from pants.java.nailgun_executor import NailgunProcessGroup
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/build_graph/build_file_address_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def _raise_incorrect_address_error(self, spec_path, wrong_target_name, addresses

if not addresses:
raise self.EmptyBuildFileError(
'{was_not_found_message}, because that directory contains no BUILD files defining addressable entities.'
'{was_not_found_message}, because that directory does not contain any BUILD files defining addressable entities.'
.format(was_not_found_message=was_not_found_message))
# Print BUILD file extensions if there's more than one BUILD file with targets only.
if (any(not hasattr(address, 'rel_path') for address in addresses) or
Expand Down
8 changes: 8 additions & 0 deletions src/python/pants/build_graph/build_file_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import six

from pants.base.build_file_target_factory import BuildFileTargetFactory
from pants.base.deprecated import deprecated_conditional
from pants.build_graph.target import Target
from pants.util.memo import memoized_property

Expand Down Expand Up @@ -40,6 +41,13 @@ def wrap(cls, context_aware_object_factory, *target_types):
if not target_types:
raise ValueError('The given `context_aware_object_factory` {} must expand at least 1 '
'produced type; none were registered'.format(context_aware_object_factory))
deprecated_conditional(
lambda: len(target_types) > 1,
'1.7.0.dev0',
'TargetMacro.Factory instances that construct more than one type are no longer supported. '
'Consider using a `context_aware_object_factory, which can construct any number of '
'different objects.'
)

class Factory(cls):
@property
Expand Down
Loading

0 comments on commit b0aafa8

Please sign in to comment.