Skip to content

Commit

Permalink
Add test for Project.walk_codebase_path #180
Browse files Browse the repository at this point in the history
    * Format code

Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed May 11, 2022
1 parent a9410f8 commit 24902bf
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scanpipe/pipes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

from django.db.models import Count

from scanpipe.models import ROOT_SYMBOL
from scanpipe.models import CodebaseResource
from scanpipe.models import DiscoveredPackage
from scanpipe.models import ROOT_SYMBOL
from scanpipe.pipes import scancode

logger = logging.getLogger("scanpipe.pipes")
Expand Down
2 changes: 1 addition & 1 deletion scanpipe/pipes/codebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

from django.core.exceptions import ObjectDoesNotExist

from scanpipe.models import Project
from scanpipe.models import ROOT_SYMBOL
from scanpipe.models import Project


def sort_by_lower_name(resource):
Expand Down
2 changes: 1 addition & 1 deletion scanpipe/tests/regen_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from django.core.management import call_command
from django.test import TestCase

from scanpipe.models import Project
from scanpipe.models import ROOT_SYMBOL
from scanpipe.models import Project
from scanpipe.pipes import codebase
from scanpipe.pipes import output

Expand Down
31 changes: 31 additions & 0 deletions scanpipe/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,37 @@ def test_scanpipe_project_model_raise_if_run_in_progress(self):
with self.assertRaises(RunInProgressError):
self.project1.reset()

def test_scanpipe_project_model_walk_codebase_path(self):
expected_truncated_paths = [
"asgiref-3.3.0-py3-none-any.whl-extract",
"asgiref-3.3.0-py3-none-any.whl",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref-3.3.0.dist-info",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref/sync.py",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref/testing.py",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref/server.py",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref/compatibility.py",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref/local.py",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref/current_thread_executor.py",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref/timeout.py",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref/wsgi.py",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref/__init__.py",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref-3.3.0.dist-info/LICENSE",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref-3.3.0.dist-info/WHEEL",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref-3.3.0.dist-info/top_level.txt",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref-3.3.0.dist-info/RECORD",
"asgiref-3.3.0-py3-none-any.whl-extract/asgiref-3.3.0.dist-info/METADATA",
]
# We need to truncate the paths to avoid false test failures due to the
# difference in temporary directory names where the test Project lives
truncated_paths = []
for resource_path in self.project_asgiref.walk_codebase_path():
split_path = str(resource_path).split("/codebase/")
if len(split_path) > 1:
truncated_path = split_path[1]
truncated_paths.append(truncated_path)
self.assertEquals(expected_truncated_paths, truncated_paths)

def test_scanpipe_run_model_set_scancodeio_version(self):
run1 = Run.objects.create(project=self.project1)
self.assertEqual("", run1.scancodeio_version)
Expand Down
7 changes: 4 additions & 3 deletions scanpipe/tests/test_pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
from commoncode.resource import VirtualCodebase
from scancode.interrupt import TimeoutError as InterruptTimeoutError

from scanpipe.models import ROOT_SYMBOL
from scanpipe.models import CodebaseResource
from scanpipe.models import DiscoveredPackage
from scanpipe.models import Project
from scanpipe.models import ProjectError
from scanpipe.models import ROOT_SYMBOL
from scanpipe.pipes import codebase
from scanpipe.pipes import fetch
from scanpipe.pipes import filename_now
Expand Down Expand Up @@ -532,7 +532,9 @@ def test_scanpipe_pipes_scancode_virtual_codebase(self):
self.assertEqual(19, CodebaseResource.objects.count())
self.assertEqual(1, DiscoveredPackage.objects.count())
# Make sure the root CodebaseResource has been created as ROOT_SYMBOL
self.assertTrue(CodebaseResource.objects.filter(path=ROOT_SYMBOL, name=ROOT_SYMBOL).exists())
self.assertTrue(
CodebaseResource.objects.filter(path=ROOT_SYMBOL, name=ROOT_SYMBOL).exists()
)
# Make sure that the root was not created with a path of "codebase"
self.assertFalse(CodebaseResource.objects.filter(path="codebase").exists())

Expand Down Expand Up @@ -698,7 +700,6 @@ def test_scanpipe_pipes_codebase_project_codebase_class_with_resources(self):

self.assertEqual(expected, tree)


def test_scanpipe_pipes_codebase_project_codebase_class_walk(self):
fixtures = self.data_location / "asgiref-3.3.0_walk_test_fixtures.json"
call_command("loaddata", fixtures, **{"verbosity": 0})
Expand Down

0 comments on commit 24902bf

Please sign in to comment.