forked from rachelslaybaugh/python-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08-ci.html
More file actions
170 lines (170 loc) · 9.01 KB
/
08-ci.html
File metadata and controls
170 lines (170 loc) · 9.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<title>Software Carpentry: Testing</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap-theme.css" />
<link rel="stylesheet" type="text/css" href="css/swc.css" />
<link rel="alternate" type="application/rss+xml" title="Software Carpentry Blog" href="http://software-carpentry.org/feed.xml"/>
<meta charset="UTF-8" />
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="lesson">
<div class="container card">
<div class="banner">
<a href="http://software-carpentry.org" title="Software Carpentry">
<img alt="Software Carpentry banner" src="img/software-carpentry-banner.png" />
</a>
</div>
<article>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<a href="index.html"><h1 class="title">Testing</h1></a>
<h2 class="subtitle">Continuous Integration</h2>
<section class="objectives panel panel-warning">
<div class="panel-heading">
<h2><span class="glyphicon glyphicon-certificate"></span>Learning Objectives</h2>
</div>
<div class="panel-body">
<ul>
<li>Understand how continuous integration speeds software development</li>
<li>Understand the benefits of continuous integration</li>
<li>Implement a continuous integration server</li>
<li>Identify a few options for hosting a continuous integration server</li>
</ul>
</div>
</section>
<p>To make running the tests as easy as possible, many software development teams implement a strategy called <strong>continuous integration</strong>. As its name implies, continuous integration integrates the test suite into the development process. Every time a change is made to the repository, the continuous integration system builds and checks that code.</p>
<section class="challenge panel panel-success">
<div class="panel-heading">
<h2><span class="glyphicon glyphicon-pencil"></span>Thought Experiment: Does Your Software Work on Your Colleague’s Computer?</h2>
</div>
<div class="panel-body">
<p>Imagine you developed software on a MacOSX computer. Last week, you helped your office mate build and run it on their Linux computer. You’ve made some changes since then.</p>
<ol style="list-style-type: decimal">
<li>How can you be sure it will still work if they update their repository when they come back from vacation?</li>
<li>How long will that process take? machine until you try rebuilding it on their machine.</li>
</ol>
</div>
</section>
<p>The typical story in a research lab is that, well, you don’t know whether it will work on your colleagues’ machine until you try rebuilding it on their machine. If you have a build system, it might take a few minutes to update the repository, rebuild the code, and run the tests. If you don’t have a build system, it could take all afternoon just to see if your new changes are compatible.</p>
<aside class="callout panel panel-info">
<div class="panel-heading">
<h2><span class="glyphicon glyphicon-pushpin"></span>Let The Computers Do The Work</h2>
</div>
<div class="panel-body">
<p>Scientists are good at creative insights, conceptual understanding, critical analysis, and consuming espresso. Computers are good at following instructions. Science would be more fun if the scientists could just give the computers the instructions and go grab an espresso.</p>
<p>Continuous integration servers allow just that. Based on your instructions, a continuous integration server can:</p>
<ul>
<li>check out new code from a repository</li>
<li>spin up instances of supported operating systems (i.e., various versions of OSX, Linux, Windows, etc.).</li>
<li>spin up those instances with different software versions (i.e., python 2.7 and python 3.0)</li>
<li>run the build and test scripts</li>
<li>check for errors</li>
<li>and report the results.</li>
</ul>
</div>
</aside>
<p>Since the first step the server conducts is to check out the code from a repository, we’ll need to put our code online to make use of this kind of server (unless we are able/willing to set up our own CI server).</p>
<section class="challenge panel panel-success">
<div class="panel-heading">
<h2><span class="glyphicon glyphicon-pencil"></span>Set Up a Mean Git Repository on GitHub</h2>
</div>
<div class="panel-body">
<p>Your <code>mean.py</code> <code>test_mean.py</code> files can be the contents of a repository on GitHub.</p>
<ol style="list-style-type: decimal">
<li>Go to GitHub and <a href="https://github.com/new">create a repository</a> called mean.</li>
<li>Clone that repository (git clone https://github.com:yourusername/mean)</li>
<li>Copy the <code>mean.py</code> and <code>test_mean.py</code> files into the repository directory.</li>
<li>Use git to <code>add</code>, <code>commit</code>, and <code>push</code> the two files to GitHub.</li>
</ol>
</div>
</section>
<h2 id="giving-instructions">Giving Instructions</h2>
<p>Your work on the mean function has both code and tests. Let’s copy that code into its own repository and add continuous integration to that repository.</p>
<section class="challenge panel panel-success">
<div class="panel-heading">
<h2><span class="glyphicon glyphicon-pencil"></span>Decide How To Set Up the Server</h2>
</div>
<div class="panel-body">
<p>It doesn’t need a build system, because Python does not need to be compiled.</p>
<ol style="list-style-type: decimal">
<li>What does it need?</li>
<li>Write the names of the software dependencies in a file called requirements.txt and save the file.</li>
<li>In fact, why don’t you go ahead and version control it?</li>
</ol>
</div>
</section>
<h3 id="travis-ci">Travis-CI</h3>
<p><a href="https://travis-ci.org/">Travis</a> is a continous integration server hosting platform. It’s commonly used in Ruby development circles as well as in the scientific python community.</p>
<aside class="callout panel panel-info">
<div class="panel-heading">
<h2><span class="glyphicon glyphicon-pushpin"></span>Get a Travis-CI Account</h2>
</div>
<div class="panel-body">
<p>To use Travis, all you need is an account. It’s free.</p>
<ol style="list-style-type: decimal">
<li>Someone in your group should sign up for a Travis account.</li>
<li>Follow the instructions on the Travis website to connect your Travis account with GitHub.</li>
</ol>
</div>
</aside>
<p>A file called <code>.travis.yml</code> in your repository will signal to Travis that you want to build and test this repository on Travis-CI. Such a file, for our purposes, is very simple:</p>
<pre><code>language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "nightly"
# command to install dependencies
install:
- "pip install -r requirements.txt"
# command to run tests
script: nosetests</code></pre>
<p>You can see how the python package manager, pip, will use your requirements.txt file from the previous exercise. That requirements.txt file is a conventional way to list all of the python packages that we need. If we needed nose, numpy, and pymol, the requirements.txt file would look like this:</p>
<pre><code>nose
numpy
pymol</code></pre>
<section class="challenge panel panel-success">
<div class="panel-heading">
<h2><span class="glyphicon glyphicon-pencil"></span>Add a .travis.yml File</h2>
</div>
<div class="panel-body">
<ol style="list-style-type: decimal">
<li>Add .travis.yml to your repository</li>
<li>Commit and push it.</li>
<li>Check the situation at <a href="https://travis-ci.org/">your server</a></li>
</ol>
</div>
</section>
<h2 id="continuous-integration-hosting">Continuous Integration Hosting</h2>
<p>We gave the example of Travis because it’s very very simple to spin up. While it is able to run many flavors of Linux, it currently doesn’t support other platforms as well. Depending on your needs, you may consider other services such as:</p>
<ul>
<li><a href="http://buildbot.net/">buildbot</a></li>
<li><a href="http://www.cdash.org/">CDash</a></li>
<li><a href="https://jenkins-ci.org/">Jenkins</a></li>
</ul>
</div>
</div>
</article>
<div class="footer">
<a class="label swc-blue-bg" href="http://software-carpentry.org">Software Carpentry</a>
<a class="label swc-blue-bg" href="https://github.com/swcarpentry/lesson-template">Source</a>
<a class="label swc-blue-bg" href="LICENSE.html">License</a>
</div>
</div>
<!-- Javascript placed at the end of the document so the pages load faster -->
<script src="http://software-carpentry.org/v5/js/jquery-1.9.1.min.js"></script>
<script src="css/bootstrap/bootstrap-js/bootstrap.js"></script>
</body>
</html>