def test_last_versions_not_printed(monkeypatch): """We should only find the annual editions which have been published already""" # 2001 exists; no other years do monkeypatch.setattr(annual_editions.annual, 'find_volume', Mock()) annual_editions.annual.find_volume = lambda year, title, part: year == 2001 path = entry.Version('12', '1000') (path / '1111').write(Version('1111', date(2000, 12, 1), Citation(1, 1))) (path / '2222').write(Version('2222', date(2001, 12, 1), Citation(1, 1))) results = list(annual_editions.last_versions(12, 1000)) assert results == [annual_editions.LastVersionInYear('1111', 2001)]
def test_last_versions_multiple_versions(monkeypatch): """If multiple versions affect the same annual edition, we should only receive the last""" monkeypatch.setattr(annual_editions.annual, 'find_volume', Mock()) annual_editions.annual.find_volume.return_value = True path = entry.Version('12', '1000') (path / '1111').write(Version('1111', date(2000, 12, 1), Citation(1, 1))) (path / '2222').write(Version('2222', date(2000, 12, 2), Citation(1, 2))) (path / '3333').write(Version('3333', date(2001, 12, 1), Citation(1, 1))) results = list(annual_editions.last_versions(12, 1000)) assert results == [annual_editions.LastVersionInYear('2222', 2001), annual_editions.LastVersionInYear('3333', 2002)]
def test_last_versions_multiple_versions(monkeypatch): """If multiple versions affect the same annual edition, we should only receive the last""" monkeypatch.setattr(annual_editions.annual, 'find_volume', Mock()) annual_editions.annual.find_volume.return_value = True path = entry.Version('12', '1000') (path / '1111').write(Version('1111', date(2000, 12, 1), Citation(1, 1))) (path / '2222').write(Version('2222', date(2000, 12, 2), Citation(1, 2))) (path / '3333').write(Version('3333', date(2001, 12, 1), Citation(1, 1))) results = list(annual_editions.last_versions(12, 1000)) assert results == [ annual_editions.LastVersionInYear('2222', 2001), annual_editions.LastVersionInYear('3333', 2002) ]
def test_last_versions_not_printed(self, find_volume): """We should only find the annual editions which have been published already""" # 2001 exists; no other years do find_volume.side_effect = lambda year, title, part: year == 2001 with self.cli.isolated_filesystem(): path = entry.Version('12', '1000') (path / '1111').write( Version('1111', date(2000, 12, 1), date(2000, 12, 1))) (path / '2222').write( Version('2222', date(2001, 12, 1), date(2001, 12, 1))) results = list(annual_editions.last_versions(12, 1000)) self.assertEqual(results, [annual_editions.LastVersionInYear('1111', 2001)])
def test_last_versions_not_printed(self, find_volume): """We should only find the annual editions which have been published already""" # 2001 exists; no other years do find_volume.side_effect = lambda year, title, part: year == 2001 with self.cli.isolated_filesystem(): path = entry.Version('12', '1000') (path / '1111').write(Version('1111', date(2000, 12, 1), date(2000, 12, 1))) (path / '2222').write(Version('2222', date(2001, 12, 1), date(2001, 12, 1))) results = list(annual_editions.last_versions(12, 1000)) self.assertEqual(results, [ annual_editions.LastVersionInYear('1111', 2001)])
def test_last_versions_multiple_versions(self): """If multiple versions affect the same annual edition, we should only receive the last""" with self.cli.isolated_filesystem(): path = entry.Version('12', '1000') (path / '1111').write(Version('1111', date(2000, 12, 1), date(2000, 12, 1))) (path / '2222').write(Version('2222', date(2000, 12, 2), date(2000, 12, 2))) (path / '3333').write(Version('3333', date(2001, 12, 1), date(2001, 12, 1))) results = list(annual_editions.last_versions(12, 1000)) self.assertEqual(results, [ annual_editions.LastVersionInYear('2222', 2001), annual_editions.LastVersionInYear('3333', 2002)])
def test_last_versions_multiple_versions(self, find_volume): """If multiple versions affect the same annual edition, we should only receive the last""" find_volume.return_value = True with self.cli.isolated_filesystem(): path = entry.Version('12', '1000') (path / '1111').write(Version('1111', date(2000, 12, 1), date(2000, 12, 1))) (path / '2222').write(Version('2222', date(2000, 12, 2), date(2000, 12, 2))) (path / '3333').write(Version('3333', date(2001, 12, 1), date(2001, 12, 1))) results = list(annual_editions.last_versions(12, 1000)) self.assertEqual(results, [ annual_editions.LastVersionInYear('2222', 2001), annual_editions.LastVersionInYear('3333', 2002)])
def test_last_versions_raises_exception(): """If there are no versions available, we should receive an exception""" with pytest.raises(click.UsageError): list(annual_editions.last_versions('12', '1000'))
def test_last_versions_raises_exception(self): """If there are no versions available, we should receive an exception""" with self.cli.isolated_filesystem(): with self.assertRaises(click.UsageError): list(annual_editions.last_versions('12', '1000'))