Add snapcraft examples to scaffold getting started examples #513

Merged
merged 39 commits into from Jun 3, 2016

Conversation

Projects
None yet
5 participants
Contributor

didrocks commented May 24, 2016

Adds unit and integration tests for it, reusing and making more generic all demos tests helper.

Note that first commit is on another PR (move examples to demos): ubuntu-core#506 which needs to be merged first for review clarity.

This one will then be followed up by one PR changing the url for eamples 05- to point to this repository, and as well for disabling the manual run_demos() additional run when the "example" target is selected once CI changes the runner script.

Contributor

didrocks commented May 24, 2016

Rebased on latest master changes

Contributor

didrocks commented May 24, 2016

mock doesn't behave the same between python 3.4 (travis CI) and 3.5 (xenial), seems we have to patch builtins to be compatible in 3.4, gave it a shot for Travis CI.

Contributor

didrocks commented May 25, 2016

ok, pushed and hoping this is the last time I had to rebase :)

So, for now, we are now shipping (as per demand) the binary in the snapcraft package (it needs to be installed alongside snapcraft). Ship them the scaffolding get started with it.

I still have hope to get it renamed from snapcraft-examples to "snapcraft learn", but that will be in another separated PR.

Do you mind merging this please? I'm away for a couple of days, FYI

Member

kyrofa commented May 27, 2016

Note Mark's comment on bug #1586137: "Let's call this snapcraft examples please, not snapcraft-examples."

@didrocks didrocks changed the title from Add snapcraft-examples binary to scaffold getting started examples to Add snapcraft examples to scaffold getting started examples May 30, 2016

demos_tests/__main__.py
@@ -67,7 +68,7 @@ def main():
# them again.
argv = [sys.argv[0]]
argv.append('discover')
- argv.append('demos_tests')
+ argv.append(os.path.dirname(__file__).split(os.path.sep)[-1])
@elopio

elopio Jun 1, 2016

Member

I think you want here os.path.basename, instead of split and [-1]

@didrocks

didrocks Jun 1, 2016

Contributor

Oh, good catch!, I must have my head broken when writing this :)

+version: 0.1
+summary: Hello World simple C app
+description: |
+ This demo is intended to show how to build a C app
@elopio

elopio Jun 1, 2016

Member

s/demo/example ?

@didrocks

didrocks Jun 1, 2016

Contributor

Well, you can ignore the current examples directory, they are being renamed as "tour" and Mark is rewriting them.

snapcraft/main.py
+ dest_dir = os.path.join(dest_dir, _SNAPCRAFT_TOUR_DIR)
+ shutil.copytree(get_examplesdir(), dest_dir)
+
+ print("Snapcraft tour initialized in {}.\n"
@elopio

elopio Jun 1, 2016

Member

I think this should be logger.info, but we have some inconsistencies here in how to handle errors and messages in main. That's a bug for the next milestone.

@didrocks

didrocks Jun 1, 2016

Contributor

ok, I can rename and use logger.info if the output is the same.

Member

elopio commented Jun 1, 2016

This is great didrocks. For the tests, what if instead of having a demos_tests and examples_tests, we put them all in a user_tests dir or snaps_tests dir?
For the point of view of our CI pipeline, the two serve the same purpose, so I see no reason why we would like to have them separated. I would prefer a single ./runtests command to run both.

Contributor

didrocks commented Jun 1, 2016

I'm all for having just one single _tests directory. Let me try to play with this (have both under snaps_tests/ dir) and then, looping on the 2 subdirs to tests tour/ (replacing examples/) and demos/.

Do you still want the CI target to be "examples" or should be replace it with "snaps"?

I'll rebase on this, push Mark's current changes (so /!\ not to merge, and Mark did some changes in term of help text content in the same branch, so the diff will be a little bit larger…), rebasing on master and implementing the above change for pre-review.

Member

elopio commented Jun 1, 2016

I'd like the ci target to have the same name of that new demos+tours tests directory.
We will have to change the jobs in jenkins, which is easy but requires syncronization or dealing with failed executions. So I'll just keep an eye on your proposals. Let me know if you need a hand dealing with the test suites.

Contributor

didrocks commented Jun 1, 2016

Excellent! I'll push something with both targets "examples" and "snaps" first, running the some run_snaps tests (to ensure we always run something and I can see I didn't make a booboo ;)). We can even land it, and then, once CI has migrated (when most of current PR are rebased on master to change the targets), do another PR to remove the "examples" target.

I'll go for pushing the update today and will ping you :)

Collaborator

sergiusens commented Jun 2, 2016

If we land this tomorrow, can we update .gitignore?

The move from examples to demos is driving my status nuts :-P

Contributor

didrocks commented Jun 2, 2016

Here we go, rebased on master and with changes to have demos_tests and tour_tests under the same directory.
Note that the command is backward-comptible:
./runtests examples and ./runtests snaps both runs the same tests.

Seems that autopkgtest are down again.

Examples tests run both the old demos_tests and snaps_tests and the result is: [1;32mEverything passed�[0m. Unsure why the result doesn't reflect this.

(Note that the docstring changes are comming directly from Mark's branch as this one includes his current modifications: https://github.com/markshuttle/snapcraft/commits/tour)

bin/snapcraft-examples
+ sys.path = [topdir] + sys.path
+
+
+if __name__ == '__main__':
@sergiusens

sergiusens Jun 2, 2016

Collaborator

I thought this was supposed to be snapcraft tour (no - dash)

What is this for, I might be missing something?

@didrocks

didrocks Jun 2, 2016

Contributor

It's me, this binary should be removed and is useless, I forgot to delete it. Pushing the removal right away

setup.py
@@ -43,7 +43,7 @@
'snapcraft.plugins',
'snapcraft.storeapi'],
package_data={'snapcraft.internal': ['manifest.txt']},
- scripts=['bin/snapcraft'],
+ scripts=['bin/snapcraft', 'bin/snapcraft-examples'],
@sergiusens

sergiusens Jun 2, 2016

Collaborator

ditto, what is snapcraft-examples?

@didrocks

didrocks Jun 2, 2016

Contributor

yeah, leftover as well (now fixed and pushed). Good catch!

snaps_tests/demos_tests/test_ros.py
import os
import subprocess
-class ROSTestCase(demos_tests.ExampleTestCase):
+class ROSTestCase(snaps_tests.SnapsTestCase):
demo_dir = 'ros'
@elopio

elopio Jun 2, 2016

Member

s/demo_dir/snap_content_dir

@didrocks

didrocks Jun 2, 2016

Contributor

Good catch! Fixed

Collaborator

sergiusens commented Jun 2, 2016

demostests FAIL non-zero exit status 1

Collaborator

sergiusens commented Jun 2, 2016

/usr/bin/python3: No module named demos_tests

didrocks and others added some commits May 24, 2016

snapcraft-examples binary to scaffold getting started examples
Add helpers and unit tests around those examples.
Add the examples themselves in examples/ directory
Those examples are the getting started one. Note that for example 05-, we will
then reference the snapcraft git tree itself once this is merged.
Rename keyword and make demo_tests helper more generic
We want to reuse them to add integration tests to examples as well as demos
using the same code (symlinks).
Add integration tests for examples
* Reuse (symlinks) helpers from demos_tests
* Add tests for each example
Add a temporary demo run as part of examples
This is to ensure we are still building and testing demos until CI adds
the demo target testrun.
Move to "snapcraft examples"
Remove tweaked snapcraft-examples command to an independent snapcraft examples
argument.
Adapt snapcraft example to snapcraft tour
Copy from the new directory
Change CI to trigger new tests
Remove old tests for previous tour examples and replace with the new "GNU hello" one.
Adapt unit and integration tests for this.
Support running tests in subdirectories
Structure of the test runner should follow the tour structure. Then, we run
and build from the correct subdirectory the tests.
Move test content to snaps_tests
The idea is to be merge demos_tests and tour_tests in a single test structure.
This one has 2 subdirectories: demos_tests and tour_tests.
Add a way to run tests in subdirectories
It's better to separate tests runs, so let's run them in subdirectories
for each kind of tests (demos and tour). Add a regexp to know where to look
for the snaps, and then, follow natural relative path
Point the runner to snaps_tests now and rename modules
All modules now refers to the same snaps_tests one. Also, tweak the test runner
to include this directory in static checks and run build tests on both
"examples" (for backward compatibility) and "snaps" targets.
Add some .gitignore
The ones in the tour are inline, so that they are copied to the final
scaffolded directory for our users to follow best practices.
Disable "tour" command for now
Only disable user-visible feature for now. This will enable us to easily
get the additional tour examples in the next release.
Member

elopio commented Jun 3, 2016

There is one error in one of the tests, but they are failing anyway. Skipped in #544

Contributor

didrocks commented Jun 3, 2016

Seems like the forked version is now passing tests (I have no idea about the bad system calls though, seems like an apparmor issue when trying echo?)

Use now bash --version instead of -c for tests
bash -c is using an inappropriate syscalls breaking confinement. This will
get worked out with upstream.
Use --version instead and just ensure the command works.

Replace thus the skip tests message with the other one (due to IS)
Contributor

didrocks commented Jun 3, 2016

retest this please

(seems the autopkgtest issue was a transient failure, connection dropped)

Contributor

didrocks commented Jun 3, 2016

and everything pass! This branch should be good to merge, containing latest elopio's changes :)

@sergiusens sergiusens merged commit 7f334a5 into snapcore:master Jun 3, 2016

4 checks passed

Examples tests Success
Details
autopkgtest Success
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.0008%) to 95.728%
Details

kalikiana pushed a commit to kalikiana/snapcraft that referenced this pull request Apr 6, 2017

Add snapcraft examples to scaffold getting started tour (#513)
Add helpers and unit tests around those tours

LP: #1586137
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment