@Test
  public void baseModule() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:lib");
    String sourceName = "main.py";
    SourcePath source = new FakeSourcePath("foo/" + sourceName);

    // Run without a base module set and verify it defaults to using the build target
    // base name.
    PythonLibrary normal =
        (PythonLibrary)
            new PythonLibraryBuilder(target)
                .setSrcs(SourceList.ofUnnamedSources(ImmutableSortedSet.of(source)))
                .build(
                    new BuildRuleResolver(
                        TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    assertEquals(
        ImmutableMap.of(target.getBasePath().resolve(sourceName), source),
        normal.getSrcs(PythonTestUtils.PYTHON_PLATFORM));

    // Run *with* a base module set and verify it gets used to build the main module path.
    String baseModule = "blah";
    PythonLibrary withBaseModule =
        (PythonLibrary)
            new PythonLibraryBuilder(target)
                .setSrcs(SourceList.ofUnnamedSources(ImmutableSortedSet.of(source)))
                .setBaseModule("blah")
                .build(
                    new BuildRuleResolver(
                        TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    assertEquals(
        ImmutableMap.of(Paths.get(baseModule).resolve(sourceName), source),
        withBaseModule.getSrcs(PythonTestUtils.PYTHON_PLATFORM));
  }
 @Test
 public void platformSrcs() throws Exception {
   BuildTarget target = BuildTargetFactory.newInstance("//foo:lib");
   SourcePath matchedSource = new FakeSourcePath("foo/a.py");
   SourcePath unmatchedSource = new FakeSourcePath("foo/b.py");
   PythonLibrary library =
       (PythonLibrary)
           new PythonLibraryBuilder(target)
               .setPlatformSrcs(
                   PatternMatchedCollection.<SourceList>builder()
                       .add(
                           Pattern.compile(PythonTestUtils.PYTHON_PLATFORM.getFlavor().toString()),
                           SourceList.ofUnnamedSources(ImmutableSortedSet.of(matchedSource)))
                       .add(
                           Pattern.compile("won't match anything"),
                           SourceList.ofUnnamedSources(ImmutableSortedSet.of(unmatchedSource)))
                       .build())
               .build(
                   new BuildRuleResolver(
                       TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
   assertThat(
       library.getSrcs(PythonTestUtils.PYTHON_PLATFORM).values(),
       Matchers.contains(matchedSource));
 }