Skip to content

Tests for importing/exporting projects with subdirectories #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ide/tests/test_import_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ def test_import_rocky(self):
self.assertEqual(project.source_files.filter(file_name='lib.js', target='common').count(), 1)
self.assertEqual(project.source_files.filter(file_name='app.js', target='pkjs').count(), 1)

def test_import_source_subdirectories(self):
bundle = build_bundle({
'src/c/subdirectory/lib.c': '',
'src/c/main.c': '',
'package.json': make_package()
})
do_import_archive(self.project_id, bundle)
project = Project.objects.get(pk=self.project_id)
self.assertEqual(project.source_files.filter(file_name='main.c').count(), 1)
self.assertEqual(project.source_files.filter(file_name='subdirectory/lib.c').count(), 1)
print [x.file_name for x in project.source_files.all()]


@mock.patch('ide.models.s3file.s3', fake_s3)
class TestImportLibrary(CloudpebbleTestCase):
Expand Down
27 changes: 22 additions & 5 deletions ide/tests/test_project_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ def make_expected_sdk3_project(**kwargs):
'pebble-jshintrc': True,
'package.json': True,
'src': {
'c': {'lib.c': True, 'main.c': True},
'c': {
'lib.c': True,
'main.c': True,
'subdirectory': {
'lib.c': True
}
},
'rocky': {'index.js': True},
'pkjs': {'index.js': True},
'common': {'shared.js': True},
Expand Down Expand Up @@ -72,18 +78,22 @@ def make_expected_sdk3_project(**kwargs):
'data': {},
}
}
# The spec excludes items from modifies the 'expected' folder structure, determining
# The spec excludes items from the 'union' expected folder structure, determining
# what will actually be expected when the test is run.
spec = {
'worker_src': False,
'include': False,
'src': {
'c': {
'main.c': True,
}
'subdirectory': False
},
},
True: True
}

# By passing in arguments, the spec can be tweaked to create the desired
# expected folder structure.
spec.update(kwargs)
return filter_dict(expected, spec)

Expand Down Expand Up @@ -128,7 +138,6 @@ def test_pebblejs(self):
self.assertTrue(self.tree['src']['js']['app.js'])
self.assertTrue(self.tree['src']['js']['blah.js'])


def test_package(self):
""" Check that a package project looks right """
with self.get_tree(type='package'):
Expand All @@ -139,11 +148,19 @@ def test_package(self):
self.assertDictEqual(self.tree, expected)

def test_rockyjs(self):
""" Check that an SDK 3 project with a worker looks correct """
""" Check that rockyjs project looks correct """
with self.get_tree(type='rocky'):
self.add_file('index.js', target='app')
self.add_file('index.js', target='pkjs')
self.add_file('shared.js', target='common')
expected = self.make_expected_sdk3_project(src={'pkjs': True, 'rocky': True, 'common': True}, resources=False)
self.assertDictEqual(self.tree, expected)

def test_source_subdirectories(self):
""" Check that an SDK 3 project can export to subdirectories"""
with self.get_tree():
self.add_file('main.c')
self.add_file('subdirectory/lib.c')
self.add_resource('image.png')
expected = self.make_expected_sdk3_project(src={'c': {'main.c': True, 'subdirectory': True}})
self.assertDictEqual(self.tree, expected)