def test_sequencer_cycle(self): seq = Sequencer() seq.add('A', 'B') seq.add('B', 'C') seq.add('C', 'D') self.assertEqual(list(seq.get_steps('D')), ['A', 'B', 'C', 'D']) seq.add('C', 'A') self.assertEqual(list(seq.get_steps('D')), ['C', 'A', 'B', 'D']) self.assertFalse(seq.is_step('E')) self.assertRaises(ValueError, seq.get_steps, 'E') seq.add_node('E') self.assertTrue(seq.is_step('E')) self.assertEqual(list(seq.get_steps('E')), ['E']) seq.remove_node('E') self.assertFalse(seq.is_step('E')) self.assertRaises(ValueError, seq.get_steps, 'E') seq.remove('C', 'A') self.assertEqual(list(seq.get_steps('D')), ['A', 'B', 'C', 'D'])
def test_sequencer_basic(self): seq = Sequencer() steps = (('check', 'sdist'), ('check', 'register'), ('check', 'sdist'), ('check', 'register'), ('register', 'upload_sdist'), ('sdist', 'upload_sdist'), ('check', 'build_clibs'), ('build_clibs', 'build_ext'), ('build_ext', 'build_py'), ('build_py', 'build_scripts'), ('build_scripts', 'build'), ('build', 'test'), ('register', 'upload_bdist'), ('build', 'upload_bdist'), ('build', 'install_headers'), ('install_headers', 'install_lib'), ('install_lib', 'install_scripts'), ('install_scripts', 'install_data'), ('install_data', 'install_distinfo'), ('install_distinfo', 'install')) for pred, succ in steps: seq.add(pred, succ) # Note: these tests are sensitive to dictionary ordering # but work under Python 2.6, 2.7, 3.2, 3.3, 3.4 and PyPy 2.5 cases = ( ('check', ['check']), ('register', ['check', 'register']), ('sdist', ['check', 'sdist']), ('build_clibs', ['check', 'build_clibs']), ('build_ext', ['check', 'build_clibs', 'build_ext']), ('build_py', ['check', 'build_clibs', 'build_ext', 'build_py']), ('build_scripts', [ 'check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts' ]), ('build', [ 'check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build' ]), ('test', [ 'check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'test' ]), ('install_headers', [ 'check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'install_headers' ]), ('install_lib', [ 'check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'install_headers', 'install_lib' ]), ('install_scripts', [ 'check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'install_headers', 'install_lib', 'install_scripts' ]), ('install_data', [ 'check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'install_headers', 'install_lib', 'install_scripts', 'install_data' ]), ('install_distinfo', [ 'check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'install_headers', 'install_lib', 'install_scripts', 'install_data', 'install_distinfo' ]), ('install', [ 'check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'install_headers', 'install_lib', 'install_scripts', 'install_data', 'install_distinfo', 'install' ]), ('upload_sdist', (['check', 'register', 'sdist', 'upload_sdist'], ['check', 'sdist', 'register', 'upload_sdist'])), ('upload_bdist', ([ 'check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'register', 'upload_bdist' ], [ 'check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'register', 'build', 'upload_bdist' ])), ) for final, expected in cases: actual = list(seq.get_steps(final)) if isinstance(expected, tuple): self.assertIn(actual, expected) else: self.assertEqual(actual, expected) dot = seq.dot expected = ''' digraph G { check -> build_clibs; install_lib -> install_scripts; register -> upload_bdist; build -> upload_bdist; build_ext -> build_py; install_scripts -> install_data; check -> sdist; check -> register; build -> install_headers; install_data -> install_distinfo; sdist -> upload_sdist; register -> upload_sdist; install_distinfo -> install; build -> test; install_headers -> install_lib; build_py -> build_scripts; build_clibs -> build_ext; build_scripts -> build; } ''' expected = textwrap.dedent(expected).strip().splitlines() actual = dot.splitlines() self.assertEqual(expected[0], actual[0]) self.assertEqual(expected[-1], actual[-1]) self.assertEqual(set(expected[1:-1]), set(actual[1:-1])) actual = seq.strong_connections expected = ( [('test', ), ('upload_bdist', ), ('install', ), ('install_distinfo', ), ('install_data', ), ('install_scripts', ), ('install_lib', ), ('install_headers', ), ('build', ), ('build_scripts', ), ('build_py', ), ('build_ext', ), ('build_clibs', ), ('upload_sdist', ), ('sdist', ), ('register', ), ('check', )], [('install', ), ('install_distinfo', ), ('install_data', ), ('install_scripts', ), ('install_lib', ), ('install_headers', ), ('test', ), ('upload_bdist', ), ('build', ), ('build_scripts', ), ('build_py', ), ('build_ext', ), ('build_clibs', ), ('upload_sdist', ), ('sdist', ), ('register', ), ('check', )], [('upload_sdist', ), ('sdist', ), ('install', ), ('install_distinfo', ), ('install_data', ), ('upload_bdist', ), ('register', ), ('install_scripts', ), ('install_lib', ), ('install_headers', ), ('test', ), ('build', ), ('build_scripts', ), ('build_py', ), ('build_ext', ), ('build_clibs', ), ('check', )], # Next case added for PyPy [('upload_sdist', ), ('sdist', ), ('upload_bdist', ), ('register', ), ('test', ), ('install', ), ('install_distinfo', ), ('install_data', ), ('install_scripts', ), ('install_lib', ), ('install_headers', ), ('build', ), ('build_scripts', ), ('build_py', ), ('build_ext', ), ('build_clibs', ), ('check', )]) self.assertIn(actual, expected)
def test_sequencer_basic(self): seq = Sequencer() steps = ( ('check', 'sdist'), ('check', 'register'), ('check', 'sdist'), ('check', 'register'), ('register', 'upload_sdist'), ('sdist', 'upload_sdist'), ('check', 'build_clibs'), ('build_clibs', 'build_ext'), ('build_ext', 'build_py'), ('build_py', 'build_scripts'), ('build_scripts', 'build'), ('build', 'test'), ('register', 'upload_bdist'), ('build', 'upload_bdist'), ('build', 'install_headers'), ('install_headers', 'install_lib'), ('install_lib', 'install_scripts'), ('install_scripts', 'install_data'), ('install_data', 'install_distinfo'), ('install_distinfo', 'install') ) for pred, succ in steps: seq.add(pred, succ) # Note: these tests are sensitive to dictionary ordering # but work under Python 2.6, 2.7, 3.2, 3.3, 3.4 cases = ( ('check', ['check']), ('register', ['check', 'register']), ('sdist', ['check', 'sdist']), ('build_clibs', ['check', 'build_clibs']), ('build_ext', ['check', 'build_clibs', 'build_ext']), ('build_py', ['check', 'build_clibs', 'build_ext', 'build_py']), ('build_scripts', ['check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts']), ('build', ['check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build']), ('test', ['check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'test']), ('install_headers', ['check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'install_headers']), ('install_lib', ['check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'install_headers', 'install_lib']), ('install_scripts', ['check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'install_headers', 'install_lib', 'install_scripts']), ('install_data', ['check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'install_headers', 'install_lib', 'install_scripts', 'install_data']), ('install_distinfo', ['check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'install_headers', 'install_lib', 'install_scripts', 'install_data', 'install_distinfo']), ('install', ['check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'install_headers', 'install_lib', 'install_scripts', 'install_data', 'install_distinfo', 'install']), ('upload_sdist', (['check', 'register', 'sdist', 'upload_sdist'], ['check', 'sdist', 'register', 'upload_sdist'])), ('upload_bdist', (['check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'build', 'register', 'upload_bdist'], ['check', 'build_clibs', 'build_ext', 'build_py', 'build_scripts', 'register', 'build', 'upload_bdist'])), ) for final, expected in cases: actual = list(seq.get_steps(final)) if isinstance(expected, tuple): self.assertIn(actual, expected) else: self.assertEqual(actual, expected) dot = seq.dot expected = ''' digraph G { check -> build_clibs; install_lib -> install_scripts; register -> upload_bdist; build -> upload_bdist; build_ext -> build_py; install_scripts -> install_data; check -> sdist; check -> register; build -> install_headers; install_data -> install_distinfo; sdist -> upload_sdist; register -> upload_sdist; install_distinfo -> install; build -> test; install_headers -> install_lib; build_py -> build_scripts; build_clibs -> build_ext; build_scripts -> build; } ''' expected = textwrap.dedent(expected).strip().splitlines() actual = dot.splitlines() self.assertEqual(expected[0], actual[0]) self.assertEqual(expected[-1], actual[-1]) self.assertEqual(set(expected[1:-1]), set(actual[1:-1])) actual = seq.strong_connections expected = [ ('test',), ('upload_bdist',), ('install',), ('install_distinfo',), ('install_data',), ('install_scripts',), ('install_lib',), ('install_headers',), ('build',), ('build_scripts',), ('build_py',), ('build_ext',), ('build_clibs',), ('upload_sdist',), ('sdist',), ('register',), ('check',)] self.assertEqual(actual, expected)