<commit_before># coding=utf-8
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
                        unicode_literals, with_statement)

import platform
import unittest

from pants_test.pants_run_integration_test import PantsRunIntegrationTest


class TestPantsDaemonIntegration(PantsRunIntegrationTest):
  def _print_pantsd_log(self, workdir):
    # Surface the pantsd log for easy viewing via pytest's `-s` (don't redirect stdio) option.
    print('pantsd.log:\n')
    with open('{}/pantsd/pantsd.log'.format(workdir)) as f:
      for line in f:
        print(line, end='')

  def test_pantsd_run(self):
    pantsd_config = {'GLOBAL': {'enable_pantsd': True, 'level': 'debug'}}

    with self.temporary_workdir() as workdir:
      # Explicitly kill any running pantsd instances for the current buildroot.
      self.assert_success(
        self.run_pants_with_workdir(['kill-pantsd'], workdir)
      )

      # Start pantsd implicitly via a throwaway invocation.
      self.assert_success(
        self.run_pants_with_workdir(['help'], workdir, pantsd_config)
      )

      # This run should execute via pantsd testing the end to end client/server.
      self.assert_success(
        self.run_pants_with_workdir(['help-advanced'], workdir, pantsd_config)
      )

      # This tests a deeper pantsd-based run by actually invoking a full compile.
      self.assert_success(
        self.run_pants_with_workdir(
          ['compile', 'examples/src/scala/org/pantsbuild/example/hello/welcome'],
          workdir,
          pantsd_config)
      )

      # Explicitly kill pantsd (from a pantsd-launched runner).
      self.assert_success(
        self.run_pants_with_workdir(['kill-pantsd'], workdir, pantsd_config)
      )

      self._print_pantsd_log(workdir)

  @unittest.skipIf(platform.system() != 'Darwin', 'https://github.com/pantsbuild/pants/issues/3377')
  def test_pantsd_run_with_watchman(self):
    pantsd_config = {'GLOBAL': {'enable_pantsd': True,
                                'level': 'debug'},
                     'pantsd': {'fs_event_detection': True}}

    with self.temporary_workdir() as workdir:
      # Explicitly kill any running pantsd instances for the current buildroot.
      self.assert_success(
        self.run_pants_with_workdir(['kill-pantsd'], workdir)
      )

      # Start pantsd implicitly via a throwaway invocation.
      self.assert_success(
        self.run_pants_with_workdir(['help'], workdir, pantsd_config)
      )

      # This run should execute via pantsd testing the end to end client/server.
      self.assert_success(
        self.run_pants_with_workdir(['list', '3rdparty/python::'], workdir, pantsd_config)
      )

      # And again using the cached BuildGraph.
      self.assert_success(
        self.run_pants_with_workdir(['list', '3rdparty/python::'], workdir, pantsd_config)
      )

      # Explicitly kill pantsd (from a pantsd-launched runner).
      self.assert_success(
        self.run_pants_with_workdir(['kill-pantsd'], workdir, pantsd_config)<commit_msg>Skip test_pantsd_run_with_watchman on OSX.<commit_after># coding=utf-8
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
                        unicode_literals, with_statement)

import unittest

from pants_test.pants_run_integration_test import PantsRunIntegrationTest


class TestPantsDaemonIntegration(PantsRunIntegrationTest):
  def _print_pantsd_log(self, workdir):
    # Surface the pantsd log for easy viewing via pytest's `-s` (don't redirect stdio) option.
    print('pantsd.log:\n')
    with open('{}/pantsd/pantsd.log'.format(workdir)) as f:
      for line in f:
        print(line, end='')

  def test_pantsd_run(self):
    pantsd_config = {'GLOBAL': {'enable_pantsd': True, 'level': 'debug'}}

    with self.temporary_workdir() as workdir:
      # Explicitly kill any running pantsd instances for the current buildroot.
      self.assert_success(
        self.run_pants_with_workdir(['kill-pantsd'], workdir)
      )

      # Start pantsd implicitly via a throwaway invocation.
      self.assert_success(
        self.run_pants_with_workdir(['help'], workdir, pantsd_config)
      )

      # This run should execute via pantsd testing the end to end client/server.
      self.assert_success(
        self.run_pants_with_workdir(['help-advanced'], workdir, pantsd_config)
      )

      # This tests a deeper pantsd-based run by actually invoking a full compile.
      self.assert_success(
        self.run_pants_with_workdir(
          ['compile', 'examples/src/scala/org/pantsbuild/example/hello/welcome'],
          workdir,
          pantsd_config)
      )

      # Explicitly kill pantsd (from a pantsd-launched runner).
      self.assert_success(
        self.run_pants_with_workdir(['kill-pantsd'], workdir, pantsd_config)
      )

      self._print_pantsd_log(workdir)

  @unittest.skipIf(True, 'https://github.com/pantsbuild/pants/issues/3377')
  def test_pantsd_run_with_watchman(self):
    pantsd_config = {'GLOBAL': {'enable_pantsd': True,
                                'level': 'debug'},
                     'pantsd': {'fs_event_detection': True}}

    with self.temporary_workdir() as workdir:
      # Explicitly kill any running pantsd instances for the current buildroot.
      self.assert_success(
        self.run_pants_with_workdir(['kill-pantsd'], workdir)
      )

      # Start pantsd implicitly via a throwaway invocation.
      self.assert_success(
        self.run_pants_with_workdir(['help'], workdir, pantsd_config)
      )

      # This run should execute via pantsd testing the end to end client/server.
      self.assert_success(
        self.run_pants_with_workdir(['list', '3rdparty/python::'], workdir, pantsd_config)
      )

      # And again using the cached BuildGraph.
      self.assert_success(
        self.run_pants_with_workdir(['list', '3rdparty/python::'], workdir, pantsd_config)
      )

      # Explicitly kill pantsd (from a pantsd-launched runner).
      self.assert_success(
        self.run_pants_with_workdir(['kill-pantsd'], workdir, pantsd_config)
{'fraction_non_alphanumeric': 0.10034385745545484, 'fraction_numerical': 0.004063769928102532, 'mean_word_length': 3.1933158584534733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4041127', 'n_tokens_mistral': 2039, 'n_tokens_neox': 1966, 'n_words': 457}