def test_generate_random_string(self): # run each test multiple times to confirm random generator # doesn't generate a matching pattern by chance for i in range(1, 32): sequence = RandomString._sequences[self.seq] r = RandomString._generate_random_string(sequence, self.length) self.assertThat(r, HasLength(self.length)) regex = '%s{%s}' % (self.pattern, self.length) self.assertThat(r, MatchesRegex(regex))