def setUp(self): self.buildout = zc.buildout.configparser.parse( StringIO(BUILDOUT), 'buildout.cfg') self.name = 'test' self.options = {} self.recipe = Recipe(self.buildout, self.name, self.options)
class TestNodeClass(TestCase): """ class to unit test the recipe directly """ def setUp(self): self.buildout = zc.buildout.configparser.parse( StringIO(BUILDOUT), 'buildout.cfg') self.name = 'test' self.options = {} self.recipe = Recipe(self.buildout, self.name, self.options) def test_to_relative(self): """ _to_relative should convert absolute buildout paths to relative """ buildout_dir_path = 'foo' self.buildout['buildout']['directory'] = buildout_dir_path test_suffix = os.path.join( "parts", "node", "bin", "node" ) test_absolute_path = os.path.join( buildout_dir_path, test_suffix ) self.assertEquals( self.recipe._to_relative(test_absolute_path), "join(base, '{0}')".format(test_suffix) ) def test_get_path(self): """ _get_path should choose to change the path to relative or not based on the buildout configuration """ buildout_dir_path = 'foo' self.buildout['buildout']['directory'] = buildout_dir_path absolute_path = os.path.join( buildout_dir_path, 'parts', 'node', 'bin', 'node' ) self.recipe._use_relative_paths = True self.assertTrue( 'join(base' in self.recipe._get_path(absolute_path) ) self.recipe._use_relative_paths = False self.assertFalse( 'join(base' in self.recipe._get_path(absolute_path) ) def test_determine_use_relative_paths(self): """ relative paths should be honored """ self.options['relative-paths'] = 'false' self.assertFalse(self.recipe._determine_use_relative_paths()) del(self.options['relative-paths']) self.buildout['buildout']['relative-paths'] = 'true' self.assertTrue(self.recipe._determine_use_relative_paths()) self.buildout['buildout']['relative-paths'] = 'false' self.assertFalse(self.recipe._determine_use_relative_paths()) self.options['relative-paths'] = 'true' self.assertTrue(self.recipe._determine_use_relative_paths())