package com.jetbrains.env;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.testFramework.UsefulTestCase;
import org.junit.Test;

import java.util.List;
import java.util.Set;

import static com.intellij.testFramework.UsefulTestCase.assertEmpty;

/**
 * @author traff
 */
public class PyEnvSufficiencyTest extends PyEnvTestCase {
  private static final List<String> BASE_TAGS =
    ImmutableList.<String>builder().add("python3", "django", "jython", "ipython", "ipython011", "ipython012", "nose", "pytest").build();

  @Test
  @Staging
  public void testSufficiency() {
    if (UsefulTestCase.IS_UNDER_TEAMCITY && SETTINGS.isEnvConfiguration()) {
      checkStaging();

      Set<String> tags = Sets.newHashSet();
      List<String> roots = getPythonRoots();
      if (roots.size() == 0) {
        return;         // not on env agent
      }
      for (String root : roots) {
        tags.addAll(loadEnvTags(root));
      }

      List<String> missing = Lists.newArrayList();
      for (String tag : necessaryTags()) {
        if (!tags.contains(tag)) {
          missing.add(tag);
        }
      }


      assertEmpty("Agent is missing environments: " + StringUtil.join(missing, ", "), missing);
    }
  }

  private static List<String> necessaryTags() {
    if (SystemInfo.isWindows) {
      return ImmutableList.<String>builder().addAll(BASE_TAGS).add("iron").build();
    }
    else {
      return ImmutableList.<String>builder().addAll(BASE_TAGS).add("packaging").build();
    }
  }
}

@@ -629,17 +629,8 @@
 o%22, 
-%22jython%22,
  %22ip
@@ -641,35 +641,8 @@
 n%22, 
-%22ipython011%22, %22ipython012%22,
  %22no
@@ -678,19 +678,8 @@
 est%0A
-  @Staging%0A
   pu

Fix test: jython is not installed by build.gradle and ipython is called ipython, not ipython012.