def test_write_namespaces(self): """Tests skeleton.examples.basicpackage.BasicPackage with namespaces """ skel = BasicPackage( project_name='foo.bar.baz', package_name='foo.bar.baz', author='Damien Lebrun', author_email='*****@*****.**' ) with TempDir() as tmp: skel.write(tmp.path) self.assertEqual(set(skel['ns_packages']), set(['foo', 'foo.bar'])) self.assertEqual( set(skel['packages']), set(['foo', 'foo.bar', 'foo.bar.baz'])) self.assertTrue(tmp.exists('distribute_setup.py')) self.assertTrue(tmp.exists('MANIFEST.in')) self.assertTrue(tmp.exists('README.rst')) self.assertTrue(tmp.exists('LICENSE')) self.assertTrue(tmp.exists('setup.py')) self.assertTrue(tmp.exists('foo/__init__.py')) self.assertTrue(tmp.exists('foo/bar/__init__.py')) self.assertTrue(tmp.exists('foo/bar/baz/__init__.py'))
def test_lgpl_write_fails(self): """Tests write of a LicenceChoice fails if a key is missing """ skel = LicenseChoice(author='Damien Lebrun', license='LGPL') with TempDir() as tmp: self.assertRaises(KeyError, skel.write, tmp.path)
def test_main(self): """Tests basicpackage.main()""" resps = ['foo', 'foo', 'Damien Lebrun', '*****@*****.**', 'BSD', ''] self.input_mock.side_effect = lambda x: resps.pop(0) with TempDir() as tmp: main([tmp.path]) self.assertTrue(tmp.exists('distribute_setup.py')) self.assertTrue(tmp.exists('MANIFEST.in')) self.assertTrue(tmp.exists('README.rst')) self.assertTrue(tmp.exists('foo/__init__.py')) setup = tmp.join('setup.py') # Test egg_info can be run proc = subprocess.Popen( [sys.executable, setup, 'egg_info'], shell=False, stdout=subprocess.PIPE) self.assertEqual(proc.wait(), 0) # Test classifiers proc = subprocess.Popen( [sys.executable, setup, '--classifiers'], shell=False, stdout=subprocess.PIPE) self.assertEqual(proc.wait(), 0) classifiers = proc.stdout.read().decode().splitlines() self.assertTrue( "License :: OSI Approved" in classifiers) self.assertTrue( "License :: OSI Approved :: BSD License" in classifiers)
def test_write(self): """Tests write of a NoLicense skeleton""" skel = NoLicense(author='Damien Lebrun') with TempDir() as tmp: skel.write(tmp.path) self.assertTrue(tmp.exists('LICENSE'))
def test_jinja(self): """Tests Skeleton.write() with dynamic content using jinja.""" skel = Jinja(foo='foo', bar='bar') with TempDir() as tmp_dir: skel.write(tmp_dir.path) self.assertEqual(open(tmp_dir.join('foo.txt')).read(), 'foo\n') self.assertEqual(open(tmp_dir.join('bar/baz.txt')).read(), 'baz')
def test_overwrite_required_skel(self): """Tests it write the of required """ skel = StaticWithRequirement(file_name="foo") with TempDir() as tmp_dir: skel.write(tmp_dir.path) with open(tmp_dir.join('foo.txt')) as foo_file: self.assertEqual(foo_file.read().strip(), 'foo')
def test_write_2clause(self): """Tests write of a 2-clauses BSD license.""" skel = BSD(author='Damien Lebrun', organization='') with TempDir() as tmp: skel.write(tmp.path) self.assertEqual(skel['third_clause'], '') self.assertTrue(tmp.exists('LICENSE'))
def test_write(self): """Tests write of a GPL skeleton""" skel = GPL(author='Damien Lebrun', project_name='Foo') with TempDir() as tmp: skel.write(tmp.path) self.assertTrue(tmp.exists('LICENSE')) self.assertTrue(tmp.exists('COPYING'))
def test_write_static_file(self): """Tests Skeleton.write() with static file""" skel = Static() with TempDir() as tmp_dir: skel.write(tmp_dir.path) self.assertEqual( open(tmp_dir.join('foo.txt')).read().strip(), 'foo') self.assertEqual( open(tmp_dir.join('bar/baz.txt')).read().strip(), 'baz')
def test_write_required_skel(self): """Tests it write the of required """ skel = StaticWithRequirement(file_name="fooz") with TempDir() as tmp_dir: skel.write(tmp_dir.path) self.assertTrue(tmp_dir.exists('foo.txt')) self.assertTrue(tmp_dir.exists('bar/baz.txt')) self.assertTrue(tmp_dir.exists('fooz.txt'))
def test_write_file_name_fails(self): """Tests Skeleton.write() with dynamic file name fails""" skel = MissingVariableForFileName() with TempDir() as tmp_dir: try: skel.write(tmp_dir.path) self.fail("An exception should be raised") except (FileNameKeyError, ), exc: self.assertTrue(exc.file_path.endswith('bar/{baz}.txt')) self.assertEqual(exc.variable_name, 'baz')
def test_write_dynamic_file_names(self): """Tests Skeleton.write() with dynamic file name""" skel = DynamicFileName(baz="replaced-name") with TempDir() as tmp_dir: skel.write(tmp_dir.path) self.assertEqual( open(tmp_dir.join('foo.txt')).read().strip(), 'foo') self.assertEqual( open(tmp_dir.join('bar/replaced-name.txt')).read().strip(), 'baz')
def test_write_dynamic_content(self): """Tests Skeleton.write() with dynamic content.""" skel = DynamicContent(baz="<replaced>") with TempDir() as tmp_dir: skel.write(tmp_dir.path) self.assertEqual( open(tmp_dir.join('foo.txt')).read().strip(), 'foo') self.assertEqual( open(tmp_dir.join('bar/baz.txt')).read().strip(), 'foo <replaced> bar')
def test_write_3clause(self): """Tests write of a 3-clauses BSD license.""" skel = BSD(author='Damien Lebrun', organization='Foo inc') with TempDir() as tmp: skel.write(tmp.path) self.assertEqual(skel['third_clause'], BSD_THIRD_CLAUSE.format(organization='Foo inc')) self.assertTrue(tmp.exists('LICENSE'))
def test_write_missing_variable(self): """Tests write raise KeyError if a variable is not set.""" skel = MissingVariable() with TempDir() as tmp_dir: try: skel.write(tmp_dir.path) self.fail("An exception should be raised") except (TemplateKeyError, ), exc: self.assertTrue(exc.file_path.endswith('bar/baz.txt_tmpl')) self.assertEqual(exc.variable_name, 'baz')
def test_insert_and_remove_marker(self): """Tests skeleton.insert_into_file() with keep_marker off""" with TempDir() as tmp_dir: target = tmp_dir.join('test.txt') with open(target, 'w') as f_target: f_target.write("""foo\n# -*- insert here -*- #\nbaz\n""") insert_into_file(target, 'insert here', 'bar\n', keep_marker=False) with open(target) as f_target: self.assertEqual(f_target.readlines(), ['foo\n', 'bar\n', 'baz\n'])
def test_write_create_dst_dir(self): """tests Skeleton.write() create the missing dst directory""" skel = Static() with TempDir() as tmp_dir: skel.write(tmp_dir.join('missing-dir')) self.assertEqual( open(tmp_dir.join('missing-dir/foo.txt')).read().strip(), 'foo') self.assertEqual( open(tmp_dir.join('missing-dir/bar/baz.txt')).read().strip(), 'baz')
def test_insert_with_indent_to_lose(self): """Tests skeleton.insert_into_file() with indent to lose""" with TempDir() as tmp_dir: target = tmp_dir.join('test.txt') with open(target, 'w') as f_target: f_target.write("""foo\n # -*- insert here -*- #\nbaz\n""") insert_into_file(target, 'insert here', 'bar\n', keep_indent=False) with open(target) as f_target: self.assertEqual( f_target.readlines(), ['foo\n', ' # -*- insert here -*- #\n', 'bar\n', 'baz\n'])
def test_insert_with_indent(self): """Tests skeleton.insert_into_file() with indent to keep""" with TempDir() as tmp_dir: target = tmp_dir.join('test.txt') with open(target, 'w') as f_target: f_target.write("""foo\n # -*- insert here -*- #\nbaz\n""") insert_into_file(target, 'insert here', 'bar\nfooz\n') with open(target) as f_target: self.assertEqual( f_target.read().strip(), 'foo\n # -*- insert here -*- #\n bar\n fooz\nbaz')
def test_lgpl_write(self): """Tests write of a LicenceChoice with license set to "LGPL" """ skel = LicenseChoice( author='Damien Lebrun', project_name='Foo', license='LGPL' ) with TempDir() as tmp: skel.write(tmp.path) self.assertTrue(tmp.exists('LICENSE')) self.assertTrue(tmp.exists('COPYING')) self.assertTrue(tmp.exists('COPYING.LESSER'))
def test_lgpl_run(self): """Tests run of a LicenceChoice with license set to "LGPL" """ resps = ['Foo', 'Damien Lebrun', '*****@*****.**', 'LGPL', ] self.input_mock.side_effect = lambda x: resps.pop(0) skel = LicenseChoice() with TempDir() as tmp: skel.run(tmp.path) self.assertTrue(tmp.exists('LICENSE')) self.assertTrue(tmp.exists('COPYING')) self.assertTrue(tmp.exists('COPYING.LESSER'))
def test_run_with_var(self): """Tests Skeleton.run() with dynamic content and variable prompt.""" resps = ['<input replacement>'] self.input_mock.side_effect = lambda x: resps.pop(0) skel = DynamicContent() with TempDir() as tmp_dir: skel.run(tmp_dir.path) self.assertEqual( open(tmp_dir.join('foo.txt')).read().strip(), 'foo') self.assertEqual( open(tmp_dir.join('bar/baz.txt')).read().strip(), 'foo <input replacement> bar')
def test_write(self): """Tests BasicModule.write() """ skel = BasicModule( module_name='foo', author='Damien Lebrun', author_email='*****@*****.**', ) with TempDir() as tmp: skel.write(tmp.path) self.assertTrue(tmp.exists('README.rst')) self.assertTrue(tmp.exists('setup.py')) self.assertTrue(tmp.exists('foo.py'))
def test_write_with_bsd(self): """Tests skeleton.examples.basicpackage.BasicPackage add BSD license """ skel = BasicPackage(project_name='foo', package_name='foo', author='Damien Lebrun', author_email='*****@*****.**', license='BSD') with TempDir() as tmp: skel.write(tmp.path) self.assertTrue(tmp.exists('LICENSE')) fragment = """ Redistributions of source code must retain the above copyright notice """.strip() with open(tmp.join('LICENSE')) as license_file: content = license_file.read() self.assertTrue(fragment in content)
def test_write_without_src(self): """tests skeleton src pointing to a missing folder""" skel = Skeleton() with TempDir() as tmp_dir: self.assertRaises(AttributeError, skel.write, tmp_dir.path)