Esempio n. 1
0
    def test_crc_is_stored_properly(self):
        self._add_to_db('o1', 'i2', compute_crc=True)

        self._change_mtime('i2')
        self._change_size('o1')
        actual = self._changed_files('o1', 'i2', compute_crc=True)
        expected = set(['o1'])
        self.assertEqual(expected, actual)
        filemod_db.set_up_to_date('o1')

        # Even though we changed mtime, we're ok because the crc is stored.
        self._change_mtime('o1')
        actual = self._changed_files('o1', 'i2', compute_crc=True)
        self.assertEqual(set(), actual)

        # This is true even if we get rid of caches, and fall back on the db.
        filemod_db.reset_for_tests()
        actual = self._changed_files('o1', 'i2', compute_crc=True)
        self.assertEqual(set(), actual)

        # Again, if we don't include compute_crc, the test fails.
        filemod_db.reset_for_tests()
        actual = self._changed_files('o1', 'i2')
        expected = set(['o1'])
        self.assertEqual(expected, actual)
Esempio n. 2
0
    def setUp(self):
        super(KakeTestBase, self).setUp()

        self.create_tmpdir()  # sets self.tmpdir and self.real_project_root
        os.mkdir(os.path.join(self.tmpdir, 'genfiles'))

        # We need a fake app.yaml because the handlebars babel-extract
        # calls route-map which reads app.yaml.
        with open(self._abspath('app.yaml'), 'w') as f:
            f.write("""\
application: khan-academy
runtime: python27
api_version: 1
threadsafe: no
handlers:
- url: .*
  script: ping.application
""")

        filemod_db.reset_for_tests()  # ensure the old _DB isn't lying around
        compile_rule.reset_for_tests()
        compile_util.reset_for_tests()

        # Make sure we reset the compile-rules after each test.
        self.mock_value(
            'kake.compile_rule._COMPILE_RULES',
            {k: v.copy()
             for (k, v) in compile_rule._COMPILE_RULES.items()})
        self.mock_value('kake.compile_rule._COMPILE_RULE_LABELS',
                        compile_rule._COMPILE_RULE_LABELS.copy())

        # Useful for, e.g. test_starstar().
        open(self._abspath('package.json'), 'w').close()
Esempio n. 3
0
 def _add_to_db(self, outfile_name, *infile_names, **kwargs):
     """Adds info about outfile_name and infile_names to filemod-db."""
     _ = self._changed_files(outfile_name, *infile_names, **kwargs)
     self._create_files([outfile_name])     # because it's 'changed'!
     filemod_db.set_up_to_date(outfile_name)
     # Now we'll simulate restarting the server, so all state in
     # filemod_db gets erased.
     filemod_db.sync()
     filemod_db.reset_for_tests()
Esempio n. 4
0
    def test_crc_trumps_mtime(self):
        self._add_to_db('o1', 'i2', compute_crc=True)

        self._change_mtime('i2')
        actual = self._changed_files('o1', 'i2', compute_crc=True)
        self.assertEqual(set(), actual)

        # This works even if we clear the caches first.
        filemod_db.reset_for_tests()
        actual = self._changed_files('o1', 'i2', compute_crc=True)
        self.assertEqual(set(), actual)

        # But if you don't include compute_crc the second time, we'll
        # fail because the mtimes differ.  (We need to clear caches
        # for this to work, since crcs are in the cache.)
        filemod_db.reset_for_tests()
        actual = self._changed_files('o1', 'i2')
        expected = set(['i2'])
        self.assertEqual(expected, actual)