def test_search(self): """ Requirementz.search() finds existing requirements """ reqs = Requirementz.from_lines(TEST_LINES) for i, knownline in enumerate(TEST_LINES): if 'docopt' in knownline: known_index = i break else: self.fail('Bad test, failed to find known test requirement.') found = tuple(reqs.search('docopt')) self.assertTrue(len(found) == 1, msg='Failed to find requirement.') self.assertEqual(reqs[known_index], found[0], msg='Failed to find correct requirement.') found = tuple(reqs.search('DoCoPt', ignorecase=True)) self.assertTrue(len(found) == 1, msg='Failed to find case-insensitive requirement.') self.assertEqual( reqs[known_index], found[0], msg='Failed to find correct case-insensitive requirement.') found = tuple(reqs.search('0.6.2')) self.assertTrue(len(found) == 1, msg='Failed to find requirement by version.') self.assertEqual(reqs[known_index], found[0], msg='Failed to find correct requirement by version.') found = tuple(reqs.search('>= 0.6.2')) self.assertTrue(len(found) == 1, msg='Failed to find requirement.') self.assertEqual(reqs[known_index], found[0], msg='Failed to find requirement by spec.') notfound = tuple(reqs.search('THIS_DOES_NOT_EXIST')) self.assertTrue(len(notfound) == 0, msg='Returned false requirement.')
def test_add_new(self): """ Requirementz.add_line() works for new entries """ reqs = Requirementz.from_lines(TEST_LINES) reqs.add_line('six >= 0.0.1') self.assertTrue(len(reqs) == len(TEST_LINES) + 1, msg='New requirement not added.') self.assertIn('six', reqs.names(), msg='New requirement not added.')
def test_add_replace(self): """ Requirementz.add_line() works for existing entries """ reqs = Requirementz.from_lines(TEST_LINES) reqs.add_line('docopt >= 0.6.1') self.assertTrue(len(reqs) == len(TEST_LINES), msg='Existing requirement not replaced.') r = reqs.get_byname('docopt') self.assertIn(('>=', '0.6.1'), r.specs, msg='Existing requirement not replaced.')
def test_duplicates(self): """ Requirementz.duplicates() catches duplicate entries """ dupereqs = ( RequirementPlus.parse_line('docopt >= 0.6.2'), RequirementPlus.parse_line('docopt <= 7.0.0'), RequirementPlus.parse_line('six > 0'), RequirementPlus.parse_line('six >= 1.0.0'), RequirementPlus.parse_line('six >= 5.1.6'), # Not returned at all, no dupes. RequirementPlus.parse_line('lone == 1.0.0'), ) reqs = Requirementz.from_lines(str(r) for r in dupereqs) dupesbyname = {r.name: num for r, num in reqs.duplicates().items()} self.assertDictEqual(dupesbyname, {'docopt': 1, 'six': 2})
def test_StatusLine(self): """ init() from requirement works """ reqs = Requirementz.from_lines(TEST_LINES) [StatusLine(r) for r in reqs]
def test_write(self): """ Requirementz.write() to file works """ reqs = Requirementz.from_lines(TEST_LINES) reqs.write(filename=TEST_FILE)
def test_init_lines(self): """ Requirementz.init() from lines works """ Requirementz.from_lines(TEST_LINES)
def test_init(self): """ Requirementz.init() from file works """ reqs = Requirementz.from_lines(TEST_LINES) reqs.write(TEST_FILE) Requirementz.from_file(TEST_FILE)