def test_revision_url_to_parts(self): rcache = revision_cache.RevisionCache(self.get_test_dir(), 'hg.mozilla.org') repo, rev = rcache.revision_url_to_parts( "http://hg.mozilla.org/releases/mozilla-release/rev/e55e45536133") self.assertEquals(repo, "releases/mozilla-release") self.assertEquals(rev, "e55e45536133")
def test_get_revision(self): rcache = revision_cache.RevisionCache(self.get_test_dir(), 'hg.mozilla.org') # Check one that's pre-cached: pc_repo = 'releases/mozilla-release' pc_rev = '0488055e9f9f' ref = self.check_one(pc_repo, pc_rev, rcache) self.assertNotIn(pc_repo, rcache._repos) revision = rcache.get_revision(pc_repo, pc_rev) self.assertEqual(revision, ref) self.assertIn(pc_repo, rcache._repos) self.assertIn(pc_rev, rcache._repos[pc_repo]) # This time it should be cached: revision = rcache.get_revision(pc_repo, pc_rev) self.assertEqual(revision, ref) # Fetch another one that's not cached nc_repo = 'releases/mozilla-beta' nc_rev = '53c447ff5fd3' self.assertNotIn(nc_repo, rcache._repos) revision = rcache.get_revision(nc_repo, nc_rev) self.assertIn("A11Y_INSTANTIATED_FLAG", revision) self.assertIn(nc_repo, rcache._repos) self.assertIn(nc_rev, rcache._repos[nc_repo])
def main(argv=None): parser = argparse.ArgumentParser(description="Convert Telemetry data") parser.add_argument("-c", "--config-file", help="Read configuration from this file", default="./telemetry_server_config.json") parser.add_argument("-d", "--date", help="Use specified date for dimensions") args = parser.parse_args() try: server_config = open(args.config_file, "r") config = json.load(server_config) server_config.close() except IOError: config = {} cache_dir = config.get("revision_cache_path", "./histogram_cache") server = config.get("revision_cache_server", "hg.mozilla.org") schema_filename = config.get("schema_filename", "./telemetry_schema.json") schema_data = open(schema_filename) schema = TelemetrySchema(json.load(schema_data)) schema_data.close() cache = revision_cache.RevisionCache(cache_dir, server) converter = Converter(cache, schema) process(converter, args.date)
def check_one_url(self, url, cache=None): #print "checking url", url if cache is None: dummy = revision_cache.RevisionCache(self.get_test_dir(), 'hg.mozilla.org') else: dummy = cache repo, rev = dummy.revision_url_to_parts(url) return self.check_one(repo, rev, cache)
def check_one(repo, rev): rcache = revision_cache.RevisionCache(cache_dir, 'hg.mozilla.org') filename = "%s/%s/%s/Histograms.json" % (cache_dir, repo, rev) assert not os.path.exists(filename) bad = rcache.fetch_disk(repo, rev) assert bad is None remote = rcache.fetch_server(repo, rev) assert "A11Y_INSTANTIATED_FLAG" in remote good = rcache.fetch_disk(repo, rev) assert "A11Y_INSTANTIATED_FLAG" in good assert os.path.exists(filename)
def setUpClass(cls): cls.cache_dir = "/tmp/histogram_revision_cache" cls.schema_filename = "./telemetry/telemetry_schema.json" assert not os.path.exists(cls.cache_dir) schema_file = open(cls.schema_filename, "r") cls.schema = TelemetrySchema(json.load(schema_file)) schema_file.close() cls.cache = revision_cache.RevisionCache(cls.cache_dir, 'hg.mozilla.org') cls.converter = Converter(cls.cache, cls.schema)
def test_get_revision_noparse(self): rcache = revision_cache.RevisionCache(self.get_test_dir(), 'hg.mozilla.org') # Fetch one that's not cached repo = 'releases/mozilla-beta' rev = '53c447ff5fd3' self.assertNotIn(repo, rcache._repos) revision = rcache.get_revision(repo, rev, parse=False) self.assertIn("A11Y_INSTANTIATED_FLAG", revision) self.assertIn(repo, rcache._repos) self.assertIn(rev, rcache._repos[repo]) # parse=False should give us a raw string. Parse it as json and then # make sure the same key is present. parsed = json.loads(revision) self.assertIn("A11Y_INSTANTIATED_FLAG", parsed)
def check_one(self, repo, rev, cache=None): #print "checking repo:", repo, "rev:", rev if cache is None: rcache = revision_cache.RevisionCache(self.get_test_dir(), 'hg.mozilla.org') else: rcache = cache filename = "%s/%s/%s/Histograms.json" % (self.get_test_dir(), repo, rev) self.assertFalse(os.path.exists(filename)) bad = rcache.fetch_disk(repo, rev) self.assertIs(bad, None) remote = rcache.fetch_server(repo, rev) self.assertIn("A11Y_INSTANTIATED_FLAG", remote) good = rcache.fetch_disk(repo, rev) self.assertIn("A11Y_INSTANTIATED_FLAG", good) self.assertTrue(os.path.exists(filename)) return good
def test_bad_revision_url_to_parts(self): rcache = revision_cache.RevisionCache(self.get_test_dir(), 'hg.mozilla.org') with self.assertRaises(ValueError): repo, rev = rcache.revision_url_to_parts("arglebargle")