examples_tests: fix the libpipeline test. #326

Merged
merged 1 commit into from Feb 24, 2016

Conversation

Projects
None yet
3 participants
Member

elopio commented Feb 18, 2016

Refactor the examples tests to be able to write them independently, each
on its own file.

LP: #1546771

Member

elopio commented Feb 18, 2016

I ended up doing a massive refactor because I hated writing the installed tests. I'm sorry about the size of this one.

@@ -0,0 +1,161 @@
+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
+#
+# Copyright (C) 2015, 2016 Canonical Ltd
@fgimenez

fgimenez Feb 22, 2016

Contributor

If this is a new file it should only include 2016

@elopio

elopio Feb 23, 2016

Member

The file is new, but I started writing this code last year. I'm just refactoring it now. So as I understand it, it should have both years.

+ # per execution.
+ config['snappy_image'] = snappy_image
+ # Delete the image when the execution exits.
+ atexit.register(shutil.rmtree, temp_dir)
@fgimenez

fgimenez Feb 22, 2016

Contributor

Why not using addCleanup for this?

@elopio

elopio Feb 23, 2016

Member

The idea is to create the image only once per execution, because it's what takes more time.
I tried using setupModule, but with this refactor it will mean once per example, which is also a lot of time. So the remaining options were to do it on main.py, or do a lazy creation and delete when the main thread exits. I liked a little more this last one, but I'm ok to change it if you have a better option in mind.

@@ -0,0 +1,34 @@
+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
+#
+# Copyright (C) 2015, 2016 Canonical Ltd
@fgimenez

fgimenez Feb 22, 2016

Contributor

If this is a new file it should only include 2016

@elopio

elopio Feb 23, 2016

Member

ditto.

@@ -0,0 +1,112 @@
+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
+#
+# Copyright (C) 2015, 2016 Canonical Ltd
@fgimenez

fgimenez Feb 22, 2016

Contributor

If this is a new file it should only include 2016

@elopio

elopio Feb 23, 2016

Member

ditto.

+ 'custom libpipeline called\n'
+ 'command-pipelinetest.wrapper\n'
+ 'include\n')
+ self.assertEqual(output, expected)
@fgimenez

fgimenez Feb 22, 2016

Contributor

Very nice! :)

examples_tests/__init__.py
+ snap_local_path = os.path.join(
+ 'examples', example_dir, snap_file_name)
+ self.snappy_testbed.copy_file(snap_local_path, '/home/ubuntu')
+ self.snappy_testbed.run_command([
@fgimenez

fgimenez Feb 22, 2016

Contributor

Maybe you could check the output from run_command here, or catch any possible exception.

@elopio

elopio Feb 23, 2016

Member

I pushed a check for the output. Any possible exception will be raised and the test will fail, which I think is enough.

+ subprocess.check_call(
+ ['sudo', 'ubuntu-device-flash', '--verbose',
+ 'core', '15.04', '--channel', 'stable',
+ '--output', image_path, '--developer-mode'])
@fgimenez

fgimenez Feb 22, 2016

Contributor

You could check the return code here, or possible exceptions raised. The textual output from udf could also be helpful, maybe at a high verbosity log level.

@elopio

elopio Feb 23, 2016

Member

check_call will raise an exception if the return code is different than 0. That will stop the test and show the traceback, which I think it's enough.

+ return image_path
+
+
+class SshTestbed:
@fgimenez

fgimenez Feb 22, 2016

Contributor

Have you considered using a library like paramiko? http://docs.paramiko.org/en/1.16/api/client.html

@elopio

elopio Feb 23, 2016

Member

That could be nice. And pexpect + paramiko might be a good combination. After finishing my tasks for this week, I'll take a look at rewriting this with the lib.

Contributor

fgimenez commented Feb 22, 2016

Looks very good, only real concerns about checking the output and eventual exceptions from command calls.

Contributor

fgimenez commented Feb 23, 2016

👍

Member

elopio commented Feb 23, 2016

retest this please

Collaborator

sergiusens commented Feb 23, 2016

So the plan is to slowly move away from the big fixture of scenarios? I actually like this 👍

examples_tests: fix the libpipeline test.
Refactor the examples tests to be able to write them independently, each
on its own file.

LP: #1546771

sergiusens added a commit that referenced this pull request Feb 24, 2016

Merge pull request #326 from elopio/bug/1546771/examples_typo-2
examples_tests: fix the libpipeline test.

@sergiusens sergiusens merged commit 8e2bff0 into snapcore:master Feb 24, 2016

3 checks passed

Examples tests Success 13 tests run, 0 skipped, 0 failed.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.2%) to 94.643%
Details

@elopio elopio deleted the elopio:bug/1546771/examples_typo-2 branch Feb 24, 2016

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

Merge pull request #326 from elopio/bug/1546771/examples_typo-2
examples_tests: fix the libpipeline test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment