Exemple #1
0
    def test_same_function_twice_parallel(self):
        analysis = Analysis(self.stage1, cache_dir=TEST_CACHE)
        noop = analysis.then(self.stage_noop)
        noop.then(self.stage2)
        noop.then(self.stage2)

        analysis.run()

        self.assertEqual(self.executed_stage1, 1)
        self.assertEqual(self.executed_stage2, 2)
Exemple #2
0
    def test_data_flow(self):
        analysis = Analysis(self.stage1, cache_dir=TEST_CACHE)
        analysis.then(self.stage2)

        data = {}

        analysis.run(data)

        self.assertEqual(data, {})
        self.assertEqual(self.data_before_stage1, {})
        self.assertEqual(self.data_after_stage1, { 'stage1': 5 })
        self.assertEqual(self.data_before_stage2, { 'stage1' : 5 })
        self.assertEqual(self.data_after_stage2, { 'stage1': 5, 'stage2': 25 })
Exemple #3
0
    def test_cache_reused(self):
        analysis = Analysis(self.stage1, cache_dir=TEST_CACHE)
        analysis.then(self.stage2)

        analysis.run()

        self.assertEqual(self.executed_stage1, 1)
        self.assertEqual(self.executed_stage2, 1)

        analysis2 = Analysis(self.stage1, cache_dir=TEST_CACHE)
        analysis2.then(self.stage2)

        analysis2.run()

        self.assertEqual(self.executed_stage1, 1)
        self.assertEqual(self.executed_stage2, 1)
Exemple #4
0
    def test_cleanup(self):
        self.assertFalse(os.path.exists(TEST_CACHE))

        analysis = Analysis(self.stage1, cache_dir=TEST_CACHE)
        analysis.then(self.stage2)

        data = {}

        # Initial run, creates two cache files
        analysis.run(data)

        cache_files = glob(os.path.join(TEST_CACHE, '*.cache'))
        self.assertEqual(len(cache_files), 2)

        # Create false third cache file
        open(os.path.join(TEST_CACHE, 'foo.cache'), 'a').close()

        cache_files2 = glob(os.path.join(TEST_CACHE, '*.cache'))
        self.assertEqual(len(cache_files2), 3)

        # Second run, removes false cache file
        analysis.run(data)

        cache_files3 = glob(os.path.join(TEST_CACHE, '*.cache'))
        self.assertEqual(len(cache_files3), 2)
        self.assertSequenceEqual(cache_files, cache_files3)
Exemple #5
0
    def test_ancestor_changed(self):
        analysis = Analysis(self.stage1, cache_dir=TEST_CACHE)
        noop = analysis.then(self.stage_noop)
        noop.then(self.stage2)

        analysis.run()

        self.assertEqual(self.executed_stage1, 1)
        self.assertEqual(self.executed_stage2, 1)

        analysis2 = Analysis(self.stage1, cache_dir=TEST_CACHE)
        analysis2.then(self.stage2)

        analysis2.run()

        self.assertEqual(self.executed_stage1, 1)
        self.assertEqual(self.executed_stage2, 2)
Exemple #6
0
    def test_ancestor_fingerprint_deleted(self):
        analysis = Analysis(self.stage1, cache_dir=TEST_CACHE)
        analysis.then(self.stage2)

        analysis.run()

        self.assertEqual(self.executed_stage1, 1)
        self.assertEqual(self.executed_stage2, 1)

        os.remove(analysis._cache_path())

        analysis.run()

        self.assertEqual(self.executed_stage1, 2)
        self.assertEqual(self.executed_stage2, 2)
Exemple #7
0
    def test_descendent_fingerprint_deleted(self):
        analysis = Analysis(self.stage1, cache_dir=TEST_CACHE)
        stage2_analysis = analysis.then(self.stage2)

        analysis.run()

        self.assertEqual(self.executed_stage1, 1)
        self.assertEqual(self.executed_stage2, 1)

        os.remove(stage2_analysis._cache_path)

        analysis.run()

        self.assertEqual(self.executed_stage1, 1)
        self.assertEqual(self.executed_stage2, 2)