<commit_before>package com.jetbrains.python.testing;

import com.intellij.execution.process.ProcessOutput;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
import com.intellij.util.containers.HashMap;
import com.intellij.util.messages.MessageBus;
import com.intellij.util.ui.update.MergingUpdateQueue;
import com.intellij.util.ui.update.Update;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.jetbrains.python.PythonHelpersLocator;
import com.jetbrains.python.sdk.PySdkUtil;
import com.jetbrains.python.sdk.PythonSdkType;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.List;
import java.util.Map;

/**
 * User: catherine
 */
@State(
  name = "VFSTestFrameworkListener",
  storages = {
    @Storage(
      file = "$APP_CONFIG$/other.xml"
    )}
)
public class VFSTestFrameworkListener implements ApplicationComponent, PersistentStateComponent<VFSTestFrameworkListener> {

  private static final Logger LOG = Logger.getInstance("#com.jetbrains.python.testing.VFSTestFrameworkListener");
  private static final String PYTESTSEARCHER = "pycharm/finders/find_pytest.py";
  private static final String NOSETESTSEARCHER = "pycharm/finders/find_nosetest.py";
  private static final String ATTESTSEARCHER = "pycharm/finders/find_attest.py";

  private static final MergingUpdateQueue myQueue = new MergingUpdateQueue("TestFrameworkChecker", 5000, true, null);

  public VFSTestFrameworkListener() {
    MessageBus messageBus = ApplicationManager.getApplication().getMessageBus();
    messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
      @Override
      public void before(List<? extends VFileEvent> events) {
      }

      @Override
      public void after(List<? extends VFileEvent> events) {
        for (VFileEvent event : events) {
          VirtualFile vFile = event.getFile();
          if (vFile == null) continue;
          String path = vFile.getUrl().toLowerCase();
          boolean containsNose = path.contains("nose");
          boolean containsPy = path.contains("py-1") || path.contains("pytest");
          boolean containsAt = path.contains("attest");
          if (!containsAt && !containsNose && !containsPy) continue;
          SDKLOOP:
          for (Sdk sdk : PythonSdkType.getAllSdks()) {
            for (String root : sdk.getRootProvider().getUrls(OrderRootType.CLASSES)) {
              if (vFile.getUrl().contains(root)) {
                if (containsNose) {
                  updateTestFrameworks(sdk.getHomePath(), NOSETESTSEARCHER, "nosetest");
                  break SDKLOOP;
                }
                else if (containsPy) {
                  updateTestFrameworks(sdk.getHomePath(), PYTESTSEARCHER, "pytest");
                  break SDKLOOP;
                } else {
                  updateTestFrameworks(sdk.getHomePath(), ATTESTSEARCHER, "attest");
                  break SDKLOOP;
                }
              }
            }
          }
        }
      }
    });
  }

  public void updateAllTestFrameworks(final String sdkHome) {
    updateTestFrameworks(sdkHome, PYTESTSEARCHER, "pytest");
    updateTestFrameworks(sdkHome, NOSETESTSEARCHER, "nosetest");
    updateTestFrameworks(sdkHome, ATTESTSEARCHER, "attest");
    myQueue.flush();
  }

  public void updateTestFrameworks(final String sdkHome, final String searcher, final String sdkType) {
    myQueue.queue(new Update(Pair.create(sdkHome, searcher)) {
      public void run() {
        testInstalled(isTestFrameworkInstalled(sdkHome, searcher), sdkHome, sdkType);
      }
    });
  }

  @Override
  public void initComponent() {
  }

  @Override
  public void disposeComponent() {
  }<commit_msg>notnull<commit_after>package com.jetbrains.python.testing;

import com.intellij.execution.process.ProcessOutput;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
import com.intellij.util.containers.HashMap;
import com.intellij.util.messages.MessageBus;
import com.intellij.util.ui.update.MergingUpdateQueue;
import com.intellij.util.ui.update.Update;
import com.intellij.util.xmlb.XmlSerializerUtil;
import com.jetbrains.python.PythonHelpersLocator;
import com.jetbrains.python.sdk.PySdkUtil;
import com.jetbrains.python.sdk.PythonSdkType;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.List;
import java.util.Map;

/**
 * User: catherine
 */
@State(
  name = "VFSTestFrameworkListener",
  storages = {
    @Storage(
      file = "$APP_CONFIG$/other.xml"
    )}
)
public class VFSTestFrameworkListener implements ApplicationComponent, PersistentStateComponent<VFSTestFrameworkListener> {

  private static final Logger LOG = Logger.getInstance("#com.jetbrains.python.testing.VFSTestFrameworkListener");
  private static final String PYTESTSEARCHER = "pycharm/finders/find_pytest.py";
  private static final String NOSETESTSEARCHER = "pycharm/finders/find_nosetest.py";
  private static final String ATTESTSEARCHER = "pycharm/finders/find_attest.py";

  private static final MergingUpdateQueue myQueue = new MergingUpdateQueue("TestFrameworkChecker", 5000, true, null);

  public VFSTestFrameworkListener() {
    MessageBus messageBus = ApplicationManager.getApplication().getMessageBus();
    messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
      @Override
      public void before(@NotNull List<? extends VFileEvent> events) {
      }

      @Override
      public void after(@NotNull List<? extends VFileEvent> events) {
        for (VFileEvent event : events) {
          VirtualFile vFile = event.getFile();
          if (vFile == null) continue;
          String path = vFile.getUrl().toLowerCase();
          boolean containsNose = path.contains("nose");
          boolean containsPy = path.contains("py-1") || path.contains("pytest");
          boolean containsAt = path.contains("attest");
          if (!containsAt && !containsNose && !containsPy) continue;
          SDKLOOP:
          for (Sdk sdk : PythonSdkType.getAllSdks()) {
            for (String root : sdk.getRootProvider().getUrls(OrderRootType.CLASSES)) {
              if (vFile.getUrl().contains(root)) {
                if (containsNose) {
                  updateTestFrameworks(sdk.getHomePath(), NOSETESTSEARCHER, "nosetest");
                  break SDKLOOP;
                }
                else if (containsPy) {
                  updateTestFrameworks(sdk.getHomePath(), PYTESTSEARCHER, "pytest");
                  break SDKLOOP;
                } else {
                  updateTestFrameworks(sdk.getHomePath(), ATTESTSEARCHER, "attest");
                  break SDKLOOP;
                }
              }
            }
          }
        }
      }
    });
  }

  public void updateAllTestFrameworks(final String sdkHome) {
    updateTestFrameworks(sdkHome, PYTESTSEARCHER, "pytest");
    updateTestFrameworks(sdkHome, NOSETESTSEARCHER, "nosetest");
    updateTestFrameworks(sdkHome, ATTESTSEARCHER, "attest");
    myQueue.flush();
  }

  public void updateTestFrameworks(final String sdkHome, final String searcher, final String sdkType) {
    myQueue.queue(new Update(Pair.create(sdkHome, searcher)) {
      @Override
      public void run() {
        testInstalled(isTestFrameworkInstalled(sdkHome, searcher), sdkHome, sdkType);
      }
    });
  }

  @Override
  public void initComponent() {
  }

  @Override
  public void disposeComponent() {
  }
{'fraction_non_alphanumeric': 0.10651240458015267, 'fraction_numerical': 0.0011927480916030535, 'mean_word_length': 3.4365079365079363, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '6273181', 'n_tokens_mistral': 2582, 'n_tokens_neox': 2534, 'n_words': 455}