11package io .joern .pysrc2cpg .passes
22
33import io .joern .pysrc2cpg .testfixtures .PySrc2CpgFixture
4+ import io .shiftleft .codepropertygraph .generated .Operators
45import io .shiftleft .semanticcpg .language .*
56
67class ImportsPassTests extends PySrc2CpgFixture (withOssDataflow = false ) {
78
89 " For a simple import statement, there" should {
910 lazy val cpg = code(" import foo" , " app.py" )
1011 " be a create a call to `import`" in {
11- val List (callToImport) = cpg.call(" import " ).l
12+ val List (callToImport) = cpg.call(Operators .importCall ).l
1213 callToImport.code shouldBe " import foo"
1314 val List (where, what) = callToImport.argument.l
1415 where.code shouldBe " "
1516 what.code shouldBe " foo"
1617 }
1718 " create an assignment with the import on the right-hand-side" in {
18- val List (assignment) = cpg.call(" import " ).inAssignment.l
19+ val List (assignment) = cpg.call(Operators .importCall ).inAssignment.l
1920 assignment.target.code shouldBe " foo"
2021 assignment.source.code shouldBe " import foo"
2122 }
@@ -60,15 +61,15 @@ class ImportsPassTests extends PySrc2CpgFixture(withOssDataflow = false) {
6061 " For an import of the form `from... import`, it" should {
6162 lazy val cpg = code(" from foo import Bar" )
6263 " create a call to `import`" in {
63- val List (callToImport) = cpg.call(" import " ).l
64+ val List (callToImport) = cpg.call(Operators .importCall ).l
6465 callToImport.code shouldBe " from foo import Bar"
6566 val List (where, what) = callToImport.argument.l
6667 where.code shouldBe " foo"
6768 what.code shouldBe " Bar"
6869 }
6970
7071 " create an assignment with the import on the right-hand-side" in {
71- val List (assignment) = cpg.call(" import " ).inAssignment.l
72+ val List (assignment) = cpg.call(Operators .importCall ).inAssignment.l
7273 assignment.target.code shouldBe " Bar"
7374 assignment.source.code shouldBe " from foo import Bar"
7475 }
@@ -84,7 +85,7 @@ class ImportsPassTests extends PySrc2CpgFixture(withOssDataflow = false) {
8485 " For an import of a module with alias, it" should {
8586 lazy val cpg = code(" import foo as bar" )
8687 " create a call to `import`" in {
87- val List (callToImport) = cpg.call(" import " ).l
88+ val List (callToImport) = cpg.call(Operators .importCall ).l
8889 callToImport.code shouldBe " import foo as bar"
8990 val List (where, what, as) = callToImport.argument.l
9091 where.code shouldBe " "
@@ -93,7 +94,7 @@ class ImportsPassTests extends PySrc2CpgFixture(withOssDataflow = false) {
9394 }
9495
9596 " create an assignment with the import on the right-hand-side" in {
96- val List (assignment) = cpg.call(" import " ).inAssignment.l
97+ val List (assignment) = cpg.call(Operators .importCall ).inAssignment.l
9798 assignment.target.code shouldBe " bar"
9899 assignment.source.code shouldBe " import foo as bar"
99100 }
@@ -109,7 +110,7 @@ class ImportsPassTests extends PySrc2CpgFixture(withOssDataflow = false) {
109110 " For an import of a class by alias, it" should {
110111 lazy val cpg = code(" from foo import Bar as Woo" )
111112 " create a call to `import`" in {
112- val List (callToImport) = cpg.call(" import " ).l
113+ val List (callToImport) = cpg.call(Operators .importCall ).l
113114 callToImport.code shouldBe " from foo import Bar as Woo"
114115 val List (where, what, as) = callToImport.argument.l
115116 where.code shouldBe " foo"
@@ -118,7 +119,7 @@ class ImportsPassTests extends PySrc2CpgFixture(withOssDataflow = false) {
118119 }
119120
120121 " create an assignment with the import on the right-hand-side" in {
121- val List (assignment) = cpg.call(" import " ).inAssignment.l
122+ val List (assignment) = cpg.call(Operators .importCall ).inAssignment.l
122123 assignment.target.code shouldBe " Woo"
123124 assignment.source.code shouldBe " from foo import Bar as Woo"
124125 }
0 commit comments