Merge lp:~snappy-dev/click/lp1400308 into lp:~snappy-dev/click/snappy

Proposed by Barry Warsaw
Status: Merged
Merge reported by: Michael Vogt
Merged at revision: not available
Proposed branch: lp:~snappy-dev/click/lp1400308
Merge into: lp:~snappy-dev/click/snappy
Diff against target: 96 lines (+49/-6)
2 files modified
click/build.py (+11/-2)
click/tests/test_build.py (+38/-4)
To merge this branch: bzr merge lp:~snappy-dev/click/lp1400308
Reviewer Review Type Date Requested Status
Michael Vogt (community) Approve
James Hunt Pending
Snappy Developers Pending
Review via email: mp+244242@code.launchpad.net

Description of the change

Fixes LP: #1400308 by complaining loudly (i.e. raising ClickBuildError) if the meta/readme.md file isn't just so. Remember that fp.readline() returns the empty string at EOF!

To post a comment you must log in.
Revision history for this message
Barry Warsaw (barry) wrote :

With tests! :)

Revision history for this message
Michael Vogt (mvo) wrote :

Thanks, looks good. I merged it and also fixed the parsing to of the paragraph in a seperate commit so this bug is done :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'click/build.py'
--- click/build.py 2014-12-09 16:30:57 +0000
+++ click/build.py 2014-12-09 23:25:25 +0000
@@ -131,9 +131,18 @@
131 self.manifest["version"] = str(self.manifest["version"])131 self.manifest["version"] = str(self.manifest["version"])
132 readme = os.path.join(os.path.dirname(manifest_path), "readme.md")132 readme = os.path.join(os.path.dirname(manifest_path), "readme.md")
133 with io.open(readme) as fp:133 with io.open(readme) as fp:
134 self.manifest["title"] = fp.readline().strip()134 title = fp.readline().strip()
135 # FIXME: read paragraph here instead of just the second line135 # FIXME: read paragraph here instead of just the second line
136 self.manifest["description"] = fp.readline()136 description = fp.readline()
137 # fp.readline() returns the empty string at EOF; check that condition
138 # now. Downstream consumers of the manifest require some non-empty
139 # text in these fields.
140 if title == '' or description == '':
141 raise ClickBuildError(
142 '{} must contain at least two non-empty lines'.format(
143 manifest_path))
144 self.manifest["title"] = title
145 self.manifest["description"] = description
137 # a ".snap" package always implicitly depends on a core framework146 # a ".snap" package always implicitly depends on a core framework
138 # the user does not have to specify this147 # the user does not have to specify this
139 if "frameworks" not in self.manifest:148 if "frameworks" not in self.manifest:
140149
=== modified file 'click/tests/test_build.py'
--- click/tests/test_build.py 2014-12-09 16:30:57 +0000
+++ click/tests/test_build.py 2014-12-09 23:25:25 +0000
@@ -19,7 +19,9 @@
1919
20__metaclass__ = type20__metaclass__ = type
21__all__ = [21__all__ = [
22 'TestClickBuildYaml',
22 'TestClickBuilder',23 'TestClickBuilder',
24 'TestClickFrameworkValidation',
23 'TestClickSourceBuilder',25 'TestClickSourceBuilder',
24 ]26 ]
2527
@@ -493,17 +495,19 @@
493 super(TestClickBuildYaml, self).setUp()495 super(TestClickBuildYaml, self).setUp()
494 self.builder = ClickBuilder()496 self.builder = ClickBuilder()
495497
496 def _make_metadata(self, scratch, template=SIMPLE_TEMPLATE):498 def _make_metadata(self, scratch, template=SIMPLE_TEMPLATE, readme=None):
497 with mkfile(os.path.join(scratch, "meta", "package.yaml")) as f:499 with mkfile(os.path.join(scratch, "meta", "package.yaml")) as f:
498 f.write(dedent(template))500 f.write(dedent(template))
499 with mkfile(os.path.join(scratch, "meta", "readme.md")) as f:501 if readme is None:
500 f.write(dedent("""test title502 readme = dedent("""test title
501503
502 Long description that spawns504 Long description that spawns
503 two lines.505 two lines.
504506
505 Some more random data.507 Some more random data.
506 """))508 """)
509 with mkfile(os.path.join(scratch, "meta", "readme.md")) as f:
510 f.write(readme)
507511
508 def test_build_valid_pkg(self):512 def test_build_valid_pkg(self):
509 self.use_temp_dir()513 self.use_temp_dir()
@@ -875,3 +879,33 @@
875 "policy_version": 1.3879 "policy_version": 1.3
876 }880 }
877 """))881 """))
882
883 def test_empty_readme(self):
884 # LP: #1400308, case 1
885 self.use_temp_dir()
886 self._make_metadata(self.temp_dir, readme='')
887 with self.assertRaises(ClickBuildError) as cm:
888 self.builder.read_manifest(self.temp_dir + "/meta/package.yaml")
889 self.assertEqual(
890 str(cm.exception)[-59:],
891 'meta/package.yaml must contain at least two non-empty lines')
892
893 def test_readme_with_nonempty_blank_first_line(self):
894 # LP: #1400308, case 1; first line is .strip()'d
895 self.use_temp_dir()
896 self._make_metadata(self.temp_dir, readme=' ')
897 with self.assertRaises(ClickBuildError) as cm:
898 self.builder.read_manifest(self.temp_dir + "/meta/package.yaml")
899 self.assertEqual(
900 str(cm.exception)[-59:],
901 'meta/package.yaml must contain at least two non-empty lines')
902
903 def test_single_line_readme(self):
904 # LP: #1400308, case 2
905 self.use_temp_dir()
906 self._make_metadata(self.temp_dir, readme='a title\n')
907 with self.assertRaises(ClickBuildError) as cm:
908 self.builder.read_manifest(self.temp_dir + "/meta/package.yaml")
909 self.assertEqual(
910 str(cm.exception)[-59:],
911 'meta/package.yaml must contain at least two non-empty lines')

Subscribers

People subscribed via source and target branches

to all changes: