<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Luc Stepniewski&#039;s Blog &#187; ruby</title>
	<atom:link href="http://www.gradstein.info/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gradstein.info</link>
	<description></description>
	<lastBuildDate>Thu, 29 Dec 2011 22:59:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://www.gradstein.info/?pushpress=hub'/>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>How to make the simplest unittests in Python</title>
		<link>http://www.gradstein.info/python/simplest-unittests-python/</link>
		<comments>http://www.gradstein.info/python/simplest-unittests-python/#comments</comments>
		<pubDate>Wed, 15 Sep 2010 12:21:43 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python projects]]></category>
		<category><![CDATA[tests]]></category>
		<category><![CDATA[unittests]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=405</guid>
		<description><![CDATA[Testing your code is nearly a requirement (even more so in Ruby). Unittests are now the most vital elements for evaluating the quality/viability of a project. I was a little jealous of Ruby where you don&#8217;t have so much to write to implement unittests. Here is a simple example: 1 2 3 4 5 6 [...]]]></description>
			<content:encoded><![CDATA[<p>Testing your code is nearly a requirement (even more so in Ruby). Unittests are now the most vital elements for evaluating the quality/viability of a project.<br />
I was a little jealous of Ruby where you don&#8217;t have so much to write to implement unittests. Here is a simple example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;mymodule&quot;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;test/unit&quot;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> TestMyModule <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#CC00FF; font-weight:bold;"><span style="color:#6666ff; font-weight:bold;">Test::Unit::TestCase</span></span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> test_simple
     assert_equal<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">1</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Now, using <a href="http://somethingaboutorange.com/mrl/projects/nose" class="liexternal">Nose</a>, you can get even shorter code. If you do standard Python projects, you&#8217;ll use a setup.py file. To use nose, you do not even need to specify the path where to find the tests, just add two lines (tests_require and test_suite) to call nosetest:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> setuptools <span style="color: #ff7700;font-weight:bold;">import</span> setup, find_packages
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>, <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> mymodule
&nbsp;
version = mymodule.__version__
&nbsp;
setup<span style="color: black;">&#40;</span>name=<span style="color: #483d8b;">'myproject'</span>,
      version=version,
      description=<span style="color: #483d8b;">&quot;Module to display blah blah blah.&quot;</span>,
      long_description=<span style="color: #483d8b;">&quot;&quot;&quot; &quot;&quot;&quot;</span>,
      classifiers=<span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>, <span style="color: #808080; font-style: italic;"># Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers</span>
      keywords=<span style="color: #483d8b;">'mymodule foobar'</span>,
      author=<span style="color: #483d8b;">'Luc Stepniewski'</span>,
      author_email=<span style="color: #483d8b;">'lior@gradstein.info'</span>,
      url=<span style="color: #483d8b;">''</span>,
      license=<span style="color: #483d8b;">'GPL'</span>,
      packages=find_packages<span style="color: black;">&#40;</span>exclude=<span style="color: black;">&#91;</span><span style="color: #483d8b;">'ez_setup'</span>, <span style="color: #483d8b;">'examples'</span>, <span style="color: #483d8b;">'tests'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>,
      include_package_data=<span style="color: #008000;">True</span>,
      tests_require=<span style="color: #483d8b;">'nose'</span>,
      test_suite=<span style="color: #483d8b;">'nose.collector'</span>,
      zip_safe=<span style="color: #008000;">False</span>,
      install_requires=<span style="color: black;">&#91;</span>
          <span style="color: #808080; font-style: italic;"># -*- Extra requirements: -*-</span>
          <span style="color: #483d8b;">'simplejson'</span>,
      <span style="color: black;">&#93;</span>,
      entry_points=<span style="color: #483d8b;">&quot;&quot;&quot;
      # -*- Entry points: -*-
      [console_scripts]
      mymodule = mymodule.mainmodule:main
      &quot;&quot;&quot;</span>,
      <span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Now, to add tests, you just have to create a directory named tests (in the root of your project, where your setup.py resides, and then add a python file()s. No need to add a __init__.py to set the directory as a module. Now just add simple python files, like my-tests.py :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> mymodule
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> TestAstInfoCli<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> setup<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> teardown<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> test_annuaire_inverse<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">assert</span> <span style="color: #ff4500;">1</span> == <span style="color: #ff4500;">1</span></pre></td></tr></table></div>

<p>As you can see, no need to import anything for doing unittests, not even the standard python unittest module! That&#8217;s better than ruby! The downside of this is that nose is an &#8216;external&#8217; package, so you&#8217;ll have to install it first (or set it as a dependency in your setup.py file, as shown above).</p>
<p>If you don&#8217;t use a setup.py, you can call nose directly from the command line, with &#8216;nosetest&#8217;.</p>
<p>Now, let&#8217;s find an equivalent to the really cool rspec ruby module!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/python/simplest-unittests-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Puppet: Files found in modules without specifying &#8216;modules&#8217; in file path will be deprecated in the next major release</title>
		<link>http://www.gradstein.info/network/puppet-files-modules-modules-file-path-deprecated-major-release/</link>
		<comments>http://www.gradstein.info/network/puppet-files-modules-modules-file-path-deprecated-major-release/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 14:11:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[network]]></category>
		<category><![CDATA[puppet]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[deprecation]]></category>
		<category><![CDATA[notice]]></category>
		<category><![CDATA[warning]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=351</guid>
		<description><![CDATA[DEPRECATION NOTICE: Files found in modules without specifying &#8216;modules&#8217; in file path will be deprecated in the next major release. If you get this warning in your puppet logs, you should take action (only if you don&#8217;t have any Puppet agent with a version]]></description>
			<content:encoded><![CDATA[<blockquote><p>DEPRECATION NOTICE: Files found in modules without specifying &#8216;modules&#8217; in file path will be deprecated in the next major release.
</p></blockquote>
<p>If you get this warning in your puppet logs, you should take action (only if you don&#8217;t have any Puppet agent with a version <= 0.24) and modify all you references to file resources.<br />
For example, if you have a module named 'ssh', normally, up to puppet 0.25 you would reference a file to it as:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">source <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;puppet:///ssh/authorized_keys&quot;</span>,<span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>But now, you need to insert a &#8216;module&#8217; identifier in between like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">source <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;puppet:///modules/ssh/authorized_keys&quot;</span>,<span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p><em>Just a small note: It seems that the templates do not need any modification.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/network/puppet-files-modules-modules-file-path-deprecated-major-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Synchronization methods of a file with Puppet</title>
		<link>http://www.gradstein.info/ruby/synchronization-methods-of-a-file-with-puppet/</link>
		<comments>http://www.gradstein.info/ruby/synchronization-methods-of-a-file-with-puppet/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 12:39:32 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[puppet]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[cluster]]></category>
		<category><![CDATA[management]]></category>
		<category><![CDATA[reductivelabs]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/?p=37</guid>
		<description><![CDATA[Usually, to synchronize a file with remote hosts, using puppet, one would use the following pattern: file { "/etc/init.d/pvfs2-server": owner => root, group => root, mode => 755, source => "puppet:///files/pvfs2-server" } (using &#8220;source&#8221; to copy data as-is, and using &#8220;template(&#8220;filename&#8221;) to use a template structure as data). Or, if one wishes to directly set [...]]]></description>
			<content:encoded><![CDATA[<p>Usually, to synchronize a file with remote hosts, using <a href="http://reductivelabs.com/trac/puppet/" class="liexternal">puppet</a>, one would use the following pattern:<br />
<code><br />
file { "/etc/init.d/pvfs2-server":<br />
      owner => root, group => root,<br />
      mode => 755,<br />
      source => "puppet:///files/pvfs2-server"<br />
}</code><br />
(using &#8220;source&#8221; to copy data as-is, and using &#8220;template(&#8220;filename&#8221;) to use a template structure as data).</p>
<p>Or, if one wishes to directly set the content of the target file:<br />
<code><br />
file { "/etc/init.d/pvfs2-server":<br />
   owner => root, group => root,<br />
   mode => 755,<br />
   source => "puppet:///files/pvfs2-server"<br />
}</code> </p>
<p>Please note that on the first line, for example &#8216;file { &#8220;/etc/mpd.conf&#8221;:&#8217;), the &#8220;/etc/mpd.conf&#8221; is a merge of two functionalities/concepts: Usually, the syntax is clear and simple:<br />
<code><br />
file { mon_fichier_mpd_conf:<br />
     path => "/etc/mpd.conf",<br />
     [...]<br />
}</code></p>
<p>The first line is about the resource description. Its goal is to be able to reference to it a little later from another resources (Notify[], etc.). By putting directly the file path and name (I think it&#8217;s identified as a filename and not as a description because there are quotes, or maybe it&#8217;s because it begins with a slash?) you mege the &#8220;path&#8221; attribute with its description.<br />
On the other end, we&#8217;ll not be able to reference to it later, if you need to.</p>
<p>You may also need to synchronize a file that is not present in the repository (puppet:///files/*). That usually happens, for example, when that file is regenerated by an external program or an external action (like /etc/passwd).<br />
<code><br />
file {"/etc/passwd":<br />
     owner => root, group => root, mode => 644,<br />
     content => file("/etc/passwd")<br />
}</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/ruby/synchronization-methods-of-a-file-with-puppet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Troll of the day: Why Ruby sucks and why Python rocks!</title>
		<link>http://www.gradstein.info/python/troll-of-the-day-why-ruby-sucks-and-why-python-rocks/</link>
		<comments>http://www.gradstein.info/python/troll-of-the-day-why-ruby-sucks-and-why-python-rocks/#comments</comments>
		<pubDate>Wed, 25 Apr 2007 15:06:00 +0000</pubDate>
		<dc:creator>Lior Gradstein</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[twisted]]></category>

		<guid isPermaLink="false">http://www.gradstein.info/uncategorized/troll-of-the-day-why-ruby-sucks-and-why-python-rocks/</guid>
		<description><![CDATA[I found a nicely written article about the problems with Ruby, written by a Ruby user, and why he found Python to be really good. There&#8217;s even a quote about Twisted! And, there are a bunch of things available to a Python guy that Ruby just canâ€™t compete with that are of particular interest to [...]]]></description>
			<content:encoded><![CDATA[<p>I found a <a href="http://blog.cbcg.net/articles/2007/04/22/python-up-ruby-down-if-that-runtime-dont-work-then-its-bound-to-drizzown" class="liexternal">nicely written article</a> about the problems with Ruby, written by a Ruby user, and why he found Python to be really good. There&#8217;s even a quote about Twisted!<br />
<blockquote>And, there are a bunch of things available to a Python guy that Ruby just canâ€™t compete with that are of particular interest to me. Two that come to mind immediately are <a href="http://twistedmatrix.com/trac/" class="liexternal">Twisted</a> and <a href="http://www.stackless.com/" class="liexternal">Stackless Python</a>. The former was used by others at TurnTide for creating a really powerful <span class="caps">SMTP</span> testing tool and the latter was used by TurnTideâ€™s competitor <a href="http://www.ironport.com/" class="liexternal">IronPort</a> to build one of the industryâ€™s best MTAs.</p></blockquote>
<p>I didn&#8217;t knew that IronPort was done in Python, even in Stackless Python!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gradstein.info/python/troll-of-the-day-why-ruby-sucks-and-why-python-rocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using memcached

Served from: www.stepniewski.fr @ 2012-02-06 07:39:24 -->
