Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port BaseTest to v2 engine (attempt two) #5611

Merged
merged 12 commits into from May 26, 2018
Expand Up @@ -30,9 +30,9 @@ class AvroJavaGenTest(NailgunTaskTestBase):
def task_type(cls):
return MockAvroJavaGenTest

@property
def alias_groups(self):
return super(AvroJavaGenTest, self).alias_groups.merge(
@classmethod
def alias_groups(cls):
return super(AvroJavaGenTest, cls).alias_groups().merge(
BuildFileAliases(targets={'java_avro_library': JavaAvroLibrary}))

def _test_avro(self, target_spec):
Expand Down
Expand Up @@ -17,7 +17,7 @@ python_tests(
'src/python/pants/backend/jvm/targets:java',
'src/python/pants/util:contextutil',
'tests/python/pants_test/subsystem:subsystem_utils',
'tests/python/pants_test/tasks:task_test_base',
'tests/python/pants_test:task_test_base',
]
)

Expand All @@ -31,7 +31,7 @@ python_tests(
'src/python/pants/backend/jvm/targets:java',
'src/python/pants/base:build_environment',
'tests/python/pants_test/subsystem:subsystem_utils',
'tests/python/pants_test/tasks:task_test_base',
'tests/python/pants_test:task_test_base',
]
)

Expand Down
Expand Up @@ -12,16 +12,16 @@
from pants.base.exceptions import TaskError
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants_test.contrib.buildrefactor.buildozer_util import prepare_dependencies
from pants_test.tasks.task_test_base import TaskTestBase
from pants_test.task_test_base import TaskTestBase

from pants.contrib.buildrefactor.buildozer import Buildozer


class BuildozerTest(TaskTestBase):
"""Test the buildozer tool"""

@property
def alias_groups(self):
@classmethod
def alias_groups(cls):
return BuildFileAliases(targets={ 'java_library': JavaLibrary })

@classmethod
Expand Down
Expand Up @@ -10,7 +10,7 @@
from pants.backend.jvm.targets.java_library import JavaLibrary
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants_test.contrib.buildrefactor.buildozer_util import prepare_dependencies
from pants_test.tasks.task_test_base import TaskTestBase
from pants_test.task_test_base import TaskTestBase

from pants.contrib.buildrefactor.meta_rename import MetaRename

Expand All @@ -22,8 +22,8 @@ class MetaRenameTest(TaskTestBase):
def task_type(cls):
return MetaRename

@property
def alias_groups(self):
@classmethod
def alias_groups(cls):
return BuildFileAliases(targets={ 'java_library': JavaLibrary })

def setUp(self):
Expand Down
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
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
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
Expand Up @@ -8,6 +8,7 @@
import hashlib

from pants.base.fingerprint_strategy import FingerprintStrategy

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


Expand Down
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
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
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',
]
)
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 All @@ -35,8 +35,8 @@ def setUp(self):
def target_type(self):
"""Subclasses should return a GoLocalSource target subclass."""

@property
def alias_groups(self):
@classmethod
def alias_groups(cls):
return build_file_aliases()

def test_default_name_and_sources(self):
Expand Down
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
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
Expand Up @@ -8,22 +8,22 @@
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):
super(GoRemoteLibraryTest, self).setUp()
# Force setup of SourceRootConfig subsystem, as go targets do computation on source roots.
self.context()

@property
def alias_groups(self):
@classmethod
def alias_groups(cls):
return build_file_aliases()

def test_default_package(self):
Expand Down
7 changes: 4 additions & 3 deletions contrib/go/tests/python/pants_test/contrib/go/tasks/BUILD
Expand Up @@ -13,8 +13,9 @@ python_tests(
'src/python/pants/util:contextutil',
'src/python/pants/util:dirutil',
'tests/python/pants_test/subsystem:subsystem_utils',
'tests/python/pants_test/tasks:task_test_base',
]
'tests/python/pants_test:task_test_base',
],
timeout=120,
)


Expand All @@ -31,5 +32,5 @@ python_tests(
'tests/python/pants_test:int-test',
],
tags={'integration'},
timeout=180,
timeout=360,
)
Expand Up @@ -10,7 +10,7 @@
from pants.build_graph.target import Target
from pants.util.contextutil import temporary_dir
from pants.util.dirutil import touch
from pants_test.tasks.task_test_base import TaskTestBase
from pants_test.task_test_base import TaskTestBase

from pants.contrib.go.targets.go_binary import GoBinary
from pants.contrib.go.tasks.go_binary_create import GoBinaryCreate
Expand Down
Expand Up @@ -9,7 +9,7 @@
from textwrap import dedent

from pants.build_graph.target import Target
from pants_test.tasks.task_test_base import TaskTestBase
from pants_test.task_test_base import TaskTestBase

from pants.contrib.go import register
from pants.contrib.go.subsystems.fetcher import Fetcher
Expand Down Expand Up @@ -43,8 +43,8 @@ def create_task(self, context, workdir=None):
task.get_fetcher_factory = types.MethodType(lambda s: FakeFetcherFactory(), task)
return task

@property
def alias_groups(self):
@classmethod
def alias_groups(cls):
# Needed for test_stitch_deps_remote_existing_rev_respected which re-loads a synthetic target
# from a generated BUILD file on disk that needs access to Go target aliases
return register.build_file_aliases()
Expand Down Expand Up @@ -285,7 +285,7 @@ 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
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
Expand Up @@ -9,7 +9,7 @@
import time

from pants.util.dirutil import touch
from pants_test.tasks.task_test_base import TaskTestBase
from pants_test.task_test_base import TaskTestBase

from pants.contrib.go.targets.go_library import GoLibrary
from pants.contrib.go.tasks.go_compile import GoCompile
Expand Down
Expand Up @@ -11,7 +11,7 @@

from pants.build_graph.address import Address
from pants.util.contextutil import temporary_dir
from pants_test.tasks.task_test_base import TaskTestBase
from pants_test.task_test_base import TaskTestBase

from pants.contrib.go.subsystems.fetcher import ArchiveFetcher
from pants.contrib.go.targets.go_remote_library import GoRemoteLibrary
Expand Down
Expand Up @@ -8,7 +8,7 @@
import os

from pants.util.contextutil import temporary_file
from pants_test.tasks.task_test_base import TaskTestBase
from pants_test.task_test_base import TaskTestBase

from pants.contrib.go.targets.go_binary import GoBinary
from pants.contrib.go.tasks.go_go import GoEnv, GoGo, GoInteropTask
Expand Down
Expand Up @@ -5,7 +5,7 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from pants_test.tasks.task_test_base import TaskTestBase
from pants_test.task_test_base import TaskTestBase

from pants.contrib.go.tasks.go_task import GoTask

Expand Down
Expand Up @@ -7,7 +7,7 @@

from pants.backend.codegen.thrift.lib.thrift import Thrift
from pants.base.exceptions import TaskError
from pants_test.tasks.task_test_base import TaskTestBase
from pants_test.task_test_base import TaskTestBase

from pants.contrib.go.tasks.go_thrift_gen import GoThriftGen

Expand Down
Expand Up @@ -12,7 +12,7 @@

from pants.util.contextutil import pushd, temporary_dir
from pants.util.dirutil import safe_mkdir, touch
from pants_test.tasks.task_test_base import TaskTestBase
from pants_test.task_test_base import TaskTestBase

from pants.contrib.go.targets.go_library import GoLibrary
from pants.contrib.go.targets.go_remote_library import GoRemoteLibrary
Expand Down
Expand Up @@ -17,7 +17,7 @@
GoogleJavaFormatCheckFormat)


class BaseTest(NailgunTaskTestBase):
class TestBase(NailgunTaskTestBase):

_BADFORMAT = dedent("""
package org.pantsbuild.contrib.googlejavaformat;
Expand All @@ -38,14 +38,14 @@ class MyClass {
}
""")

@property
def alias_groups(self):
return super(BaseTest, self).alias_groups.merge(
@classmethod
def alias_groups(cls):
return super(TestBase, cls).alias_groups().merge(
register_core().merge(register_jvm())
)


class GoogleJavaFormatTests(BaseTest):
class GoogleJavaFormatTests(TestBase):

@classmethod
def task_type(cls):
Expand All @@ -67,7 +67,7 @@ def test_googlejavaformat(self):
self.assertEqual(actual, self._GOODFORMAT)


class GoogleJavaFormatCheckFormatTests(BaseTest):
class GoogleJavaFormatCheckFormatTests(TestBase):

@classmethod
def task_type(cls):
Expand Down
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