def test_read_entries(self): """Check if it imports a set of entries""" titles = ['first change', 'next change', 'last change'] categories = [ CategoryChange.ADDED, CategoryChange.FIXED, CategoryChange.DEPRECATED ] authors = ['jsmith', 'jdoe', 'jsmith'] with tempfile.TemporaryDirectory() as dirpath: # Create some entries for x in range(0, 3): filepath = os.path.join(dirpath, str(x) + '.yml') with open(filepath, mode='w') as f: msg = "---\ntitle: {}\ncategory: {}\n" msg += "author: {}\nissue: '{}'\nnotes: null\n" msg = msg.format(titles[x], categories[x].category, authors[x], x) f.write(msg) # This non-yml file is not read filepath = os.path.join(dirpath, 'no-yml.txt') with open(filepath, mode='w') as f: f.write("no YAML file") # Import the entries entries = read_changelog_entries(dirpath) self.assertEqual(len(entries), 3) entry = entries['0.yml'] self.assertEqual(entry.title, 'first change') self.assertEqual(entry.category, CategoryChange.ADDED) self.assertEqual(entry.author, 'jsmith') self.assertEqual(entry.issue, '0') self.assertEqual(entry.notes, None) entry = entries['1.yml'] self.assertEqual(entry.title, 'next change') self.assertEqual(entry.category, CategoryChange.FIXED) self.assertEqual(entry.author, 'jdoe') self.assertEqual(entry.issue, '1') self.assertEqual(entry.notes, None) entry = entries['2.yml'] self.assertEqual(entry.title, 'last change') self.assertEqual(entry.category, CategoryChange.DEPRECATED) self.assertEqual(entry.author, 'jsmith') self.assertEqual(entry.issue, '2') self.assertEqual(entry.notes, None)
def read_unreleased_changelog_entries(project): """Returns entries stored in the unreleased changelog entries dir.""" dirpath = project.unreleased_changes_path if not os.path.exists(dirpath): msg = "changelog entries directory {} does not exist.".format(dirpath) raise click.ClickException(msg) try: entries = read_changelog_entries(dirpath) except Exception as exc: raise click.ClickException(exc) return entries
def read_unreleased_changelog_entries(project): """Import changelog entries to include in the notes.""" dirpath = project.unreleased_changes_path if not os.path.exists(dirpath): msg = "changelog entries directory '{}' does not exist.".format(dirpath) raise click.ClickException(msg) try: entries = read_changelog_entries(dirpath) except Exception as exc: raise click.ClickException(exc) entries = organize_entries_by_category(entries) return entries
def remove_unreleased_changelog_entries(project): """Delete changelog entries files included within the release.""" click.echo("Cleaning directories...", nl=False) dirpath = project.unreleased_changes_path if not os.path.exists(dirpath): msg = "changelog entries directory '{}' does not exist.".format( dirpath) raise click.ClickException(msg) entries = read_changelog_entries(dirpath).keys() for filename in entries: filepath = os.path.join(dirpath, filename) project.repo.rm(filepath) click.echo("done")
def test_read_entries_empty_dir(self): """Check if nothing is imported when reading an empty directory""" with tempfile.TemporaryDirectory() as dirpath: entries = read_changelog_entries(dirpath) self.assertDictEqual(entries, {})