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_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_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_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 _add_classifier(self, dst_dir): """Add license classifiers """ setup = os.path.join(dst_dir, 'setup.py') license_name = self.get('license', '').upper() if license_name not in self.licence_classifiers: return classifiers = [ "License :: OSI Approved", self.licence_classifiers[license_name], ] insert_into_file(setup, "Classifiers", '\n'.join(['%r,' % cla for cla in classifiers]))
def _add_classifier(self, dst_dir): """Add license classifiers """ setup = os.path.join(dst_dir, 'setup.py') license_name = self.get('license', '').upper() if license_name not in self.licence_classifiers: return classifiers = [ "License :: OSI Approved", self.licence_classifiers[license_name], ] insert_into_file( setup, "Classifiers", '\n'.join(['%r,' % cla for cla in classifiers]) )