Search in sources :

Example 1 with PoetryLockParser

use of com.synopsys.integration.detectable.detectables.poetry.parser.PoetryLockParser in project synopsys-detect by blackducksoftware.

the class PoetryLockParserTest method testParseComplexDependencyHierarchy.

@Test
public void testParseComplexDependencyHierarchy() throws IOException {
    String input = String.join(System.lineSeparator(), Arrays.asList("[[package]]", "name = \"test1\"", "version = \"1.0.0\"", "", "[package.dependencies]", "test2 = \">=1.0\"", "", "[[package]]", "name = \"test2\"", "version = \"2.0\"", "", "[package.dependencies]", "test4 = \"<4.4\"", "", "[[package]]", "name = \"test3\"", "version = \"3.0\"", "", "[[package]]", "name = \"test4\"", "version = \"4.0\"", "", "[package.dependencies]", "test1 = \"~1.0.0\""));
    PoetryLockParser poetryLockParser = new PoetryLockParser();
    DependencyGraph graph = poetryLockParser.parseLockFile(input);
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.PYPI, graph);
    graphAssert.hasRootSize(1);
    graphAssert.hasRootDependency("test3", "3.0");
    graphAssert.hasParentChildRelationship("test1", "1.0.0", "test2", "2.0");
    graphAssert.hasParentChildRelationship("test2", "2.0", "test4", "4.0");
    graphAssert.hasParentChildRelationship("test4", "4.0", "test1", "1.0.0");
}
Also used : NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) PoetryLockParser(com.synopsys.integration.detectable.detectables.poetry.parser.PoetryLockParser) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.jupiter.api.Test)

Example 2 with PoetryLockParser

use of com.synopsys.integration.detectable.detectables.poetry.parser.PoetryLockParser in project synopsys-detect by blackducksoftware.

the class PoetryLockParserTest method testParseNameAndVersionSimple.

@Test
public void testParseNameAndVersionSimple() {
    String input = String.join(System.lineSeparator(), Arrays.asList("[[package]]", "name = \"pytest-cov\"", "version = \"2.8.1\"", "", "[[package]]", "name = \"pytest-mock\"", "version = \"2.0.0\""));
    PoetryLockParser poetryLockParser = new PoetryLockParser();
    DependencyGraph graph = poetryLockParser.parseLockFile(input);
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.PYPI, graph);
    graphAssert.hasRootSize(2);
    graphAssert.hasRootDependency("pytest-cov", "2.8.1");
    graphAssert.hasRootDependency("pytest-mock", "2.0.0");
}
Also used : NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) PoetryLockParser(com.synopsys.integration.detectable.detectables.poetry.parser.PoetryLockParser) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.jupiter.api.Test)

Example 3 with PoetryLockParser

use of com.synopsys.integration.detectable.detectables.poetry.parser.PoetryLockParser in project synopsys-detect by blackducksoftware.

the class PoetryLockParserTest method testEmptyGraphWhenNoPackageObjects.

@Test
public void testEmptyGraphWhenNoPackageObjects() throws IOException {
    String input = String.join(System.lineSeparator(), Arrays.asList("package", "name = \"pytest\"", "version = \"1.0.0\"", "", "package", "name = \"python\"", "version = \"3.0\""));
    PoetryLockParser poetryLockParser = new PoetryLockParser();
    DependencyGraph graph = poetryLockParser.parseLockFile(input);
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.PYPI, graph);
    graphAssert.hasRootSize(0);
}
Also used : NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) PoetryLockParser(com.synopsys.integration.detectable.detectables.poetry.parser.PoetryLockParser) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.jupiter.api.Test)

Example 4 with PoetryLockParser

use of com.synopsys.integration.detectable.detectables.poetry.parser.PoetryLockParser in project synopsys-detect by blackducksoftware.

the class PoetryFalsePositiveTest method testApplicableNoFalsePositive.

@Test
public void testApplicableNoFalsePositive() throws URISyntaxException {
    FileFinder fileFinder = Mockito.mock(SimpleFileFinder.class);
    File currentDirectory = new File(System.getProperty("user.dir"));
    File pyprojectToml = new File(getClass().getClassLoader().getResource("detectables/unit/pip/poetry/false_positive_pyproject.toml").toURI());
    Mockito.when(fileFinder.findFile(currentDirectory, "pyproject.toml")).thenReturn(pyprojectToml);
    PoetryDetectable poetryDetectable = new PoetryDetectable(new DetectableEnvironment(currentDirectory), fileFinder, new PoetryExtractor(new PoetryLockParser()), new ToolPoetrySectionParser());
    Assertions.assertFalse(poetryDetectable.applicable().getPassed());
}
Also used : PoetryExtractor(com.synopsys.integration.detectable.detectables.poetry.PoetryExtractor) PoetryDetectable(com.synopsys.integration.detectable.detectables.poetry.PoetryDetectable) PoetryLockParser(com.synopsys.integration.detectable.detectables.poetry.parser.PoetryLockParser) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) ToolPoetrySectionParser(com.synopsys.integration.detectable.detectables.poetry.parser.ToolPoetrySectionParser) File(java.io.File) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) Test(org.junit.jupiter.api.Test)

Example 5 with PoetryLockParser

use of com.synopsys.integration.detectable.detectables.poetry.parser.PoetryLockParser in project synopsys-detect by blackducksoftware.

the class PoetryLockParserTest method testParseDependencies.

@Test
public void testParseDependencies() {
    String input = String.join(System.lineSeparator(), Arrays.asList("[[package]]", "name = \"pytest-cov\"", "python-versions = \">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*\"", "version = \"2.8.1\"", "", "[package.dependencies]", "coverage = \">=4.4\"", "pytest = \">=3.6\"", "", "[[package]]", "name = \"coverage\"", "version = \"4.4\"", "", "[[package]]", "name = \"pytest\"", "version = \"3.7\""));
    PoetryLockParser poetryLockParser = new PoetryLockParser();
    DependencyGraph graph = poetryLockParser.parseLockFile(input);
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.PYPI, graph);
    graphAssert.hasRootSize(1);
    graphAssert.hasRootDependency("pytest-cov", "2.8.1");
    graphAssert.hasParentChildRelationship("pytest-cov", "2.8.1", "coverage", "4.4");
    graphAssert.hasParentChildRelationship("pytest-cov", "2.8.1", "pytest", "3.7");
}
Also used : NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) PoetryLockParser(com.synopsys.integration.detectable.detectables.poetry.parser.PoetryLockParser) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.jupiter.api.Test)

Aggregations

PoetryLockParser (com.synopsys.integration.detectable.detectables.poetry.parser.PoetryLockParser)5 Test (org.junit.jupiter.api.Test)5 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)4 NameVersionGraphAssert (com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert)4 FileFinder (com.synopsys.integration.common.util.finder.FileFinder)1 SimpleFileFinder (com.synopsys.integration.common.util.finder.SimpleFileFinder)1 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)1 PoetryDetectable (com.synopsys.integration.detectable.detectables.poetry.PoetryDetectable)1 PoetryExtractor (com.synopsys.integration.detectable.detectables.poetry.PoetryExtractor)1 ToolPoetrySectionParser (com.synopsys.integration.detectable.detectables.poetry.parser.ToolPoetrySectionParser)1 File (java.io.File)1