Ejemplo n.º 1
0
 def get(self, ds_name, default=None):
     if self.reference_name is None:
         return default
     if ds_name in self.cache:
         return self.cache[ds_name]
     url = _url_path.format(self.reference_name, ds_name)
     try:
         resp = urllib.request.urlopen(url)
     except urllib.error.HTTPError:
         raise YTNoOldAnswer(url)
     else:
         for _ in range(3):
             try:
                 data = resp.read()
             except Exception:
                 time.sleep(0.01)
             else:
                 # We were succesful
                 break
         else:
             # Raise error if all tries were unsuccessful
             raise YTCloudError(url)
         # This is dangerous, but we have a controlled S3 environment
         rv = pickle.loads(data)
     self.cache[ds_name] = rv
     return rv
Ejemplo n.º 2
0
 def __call__(self):
     nv = self.run()
     if self.reference_storage.reference_name is not None:
         dd = self.reference_storage.get(self.storage_name)
         if dd is None or self.description not in dd:
             raise YTNoOldAnswer("%s : %s" %
                                 (self.storage_name, self.description))
         ov = dd[self.description]
         self.compare(nv, ov)
     else:
         ov = None
     self.result_storage[self.storage_name][self.description] = nv
Ejemplo n.º 3
0
    def __call__(self):
        if AnswerTestingTest.result_storage is None:
            return
        nv = self.run()

        # Test answer name should be provided either as command line parameters
        # or by setting AnswerTestingTest.answer_name
        if self.options.answer_name is None and self.answer_name is None:
            raise YTNoAnswerNameSpecified()

        # This is for running answer test when `--answer-name` is not set in
        # nosetests command line arguments. In this case, set the answer_name
        # from the `answer_name` keyword in the test case
        if self.options.answer_name is None:
            pyver = "py{}{}".format(sys.version_info.major,
                                    sys.version_info.minor)
            self.answer_name = "{}_{}".format(pyver, self.answer_name)

            answer_store_dir = os.path.realpath(self.options.output_dir)
            ref_name = os.path.join(answer_store_dir, self.answer_name,
                                    self.answer_name)
            self.reference_storage.reference_name = ref_name
            self.reference_storage.answer_name = ref_name

            # If we are generating golden answers (passed --answer-store arg):
            # - create the answer directory for this test
            # - self.reference_storage.answer_name will be path to answer files
            if self.options.store_results:
                answer_test_dir = os.path.join(answer_store_dir,
                                               self.answer_name)
                if not os.path.isdir(answer_test_dir):
                    os.makedirs(answer_test_dir)
                self.reference_storage.reference_name = None

        if self.reference_storage.reference_name is not None:
            # Compare test generated values against the golden answer
            dd = self.reference_storage.get(self.storage_name)
            if dd is None or self.description not in dd:
                raise YTNoOldAnswer(
                    "%s : %s" % (self.storage_name, self.description))
            ov = dd[self.description]
            self.compare(nv, ov)
        else:
            # Store results, hence do nothing (in case of --answer-store arg)
            ov = None
        self.result_storage[self.storage_name][self.description] = nv