예제 #1
0
    def test_add_subkey(self, pkspec, skspec):
        if pkspec not in self.keys:
            pytest.skip('Keyspec {} not in keys; must not have generated'.format(pkspec))

        alg, size = skspec
        if not alg.can_gen:
            pytest.xfail('Key algorithm {} not yet supported'.format(alg.name))

        if isinstance(size, EllipticCurveOID) and ((not size.can_gen) or size.name not in _openssl_get_supported_curves()):
            pytest.xfail('Curve {} not yet supported'.format(size.name))

        key = self.keys[pkspec]
        subkey = PGPKey.new(*skspec)

        # before adding subkey to key, the key packet should be a PrivKeyV4, not a PrivSubKeyV4
        assert isinstance(subkey._key, PrivKeyV4)
        assert not isinstance(subkey._key, PrivSubKeyV4)

        key.add_subkey(subkey, usage={KeyFlags.EncryptCommunications})

        # now that we've added it, it should be a PrivSubKeyV4
        assert isinstance(subkey._key, PrivSubKeyV4)

        # self-verify
        assert key.verify(subkey)

        sv = key.verify(key)
        assert sv
        assert subkey in sv

        # try to verify with GPG
        self.gpg_verify_key(key)
예제 #2
0
    def test_logout(self):
        """Make sure after we've logged out we can't access any of the formgrader pages."""
        if self.manager.jupyterhub is None:
            pytest.skip("JupyterHub is not running")

        # logout and wait for the login page to appear
        self._get("{}/hub".format(self.manager.base_url))
        self._wait_for_element("logout")
        self._wait_for_visibility_of_element("logout")
        element = self.browser.find_element_by_id("logout")
        element.click()
        self._wait_for_element("username_input")

        # try going to a formgrader page
        self._get(self.manager.base_formgrade_url)
        self._wait_for_element("username_input")
        next_url = self.formgrade_url().replace(self.manager.base_url, "")
        self._check_url("{}/hub/login?next={}".format(self.manager.base_url, next_url))

        # this will fail if we have a cookie for another user and try to access
        # a live notebook for that user
        if isinstance(self.manager, HubAuthNotebookServerUserManager):
            pytest.xfail("https://github.com/jupyter/jupyterhub/pull/290")

        # try going to a live notebook page
        problem = self.gradebook.find_assignment("Problem Set 1").notebooks[0]
        submission = sorted(problem.submissions, key=lambda x: x.id)[0]
        url = self.notebook_url("autograded/{}/Problem Set 1/{}.ipynb".format(submission.student.id, problem.name))
        self._get(url)
        self._wait_for_element("username_input")
        next_url = quote(url.replace(self.manager.base_url, ""))
        self._check_url("{}/hub/?next={}".format(self.manager.base_url, next_url))
예제 #3
0
파일: demos.py 프로젝트: pymor/pymor
def _test_demo(demo):
    import sys

    sys._called_from_test = True

    def nop(*args, **kwargs):
        pass

    try:
        from matplotlib import pyplot

        pyplot.show = nop
    except ImportError:
        pass
    try:
        import dolfin

        dolfin.plot = nop
        dolfin.interactive = nop
    except ImportError:
        pass
    result = None
    try:
        result = demo()
    except PySideMissing:
        pytest.xfail("PySide missing")
    finally:
        stop_gui_processes()
        from pymor.parallel.default import _cleanup

        _cleanup()

    return result
예제 #4
0
    def test_revoke_subkey(self, pkspec, skspec):
        if pkspec not in self.keys:
            pytest.skip('Keyspec {} not in keys; must not have generated'.format(pkspec))

        alg, size = skspec
        if not alg.can_gen:
            pytest.xfail('Key algorithm {} not yet supported'.format(alg.name))

        if isinstance(size, EllipticCurveOID) and ((not size.can_gen) or size.name not in _openssl_get_supported_curves()):
            pytest.xfail('Curve {} not yet supported'.format(size.name))

        # revoke the subkey
        key = self.keys[pkspec]
        # pub = key.pubkey

        subkey = next(sk for si, sk in key.subkeys.items() if (sk.key_algorithm, sk.key_size) == skspec)

        with key.unlock('This Password Has Been Changed') as ukey:
            rsig = ukey.revoke(subkey, sigtype=SignatureType.SubkeyRevocation)

        assert 'ReasonForRevocation' in rsig._signature.subpackets

        subkey |= rsig

        # verify with PGPy
        assert key.verify(subkey, rsig)

        # try to verify with GPG
        self.gpg_verify_key(key)
예제 #5
0
    def test_that_user_can_purchase_an_app(self, base_url, selenium, new_user):
        if '-dev' not in base_url:
            pytest.skip("Payments can only be tested on dev.")
        else:
            pytest.xfail("Bug 1212152 - App purchases are failing on dev")

        home_page = Home(base_url, selenium)
        home_page.go_to_homepage()
        home_page.header.click_sign_in()
        home_page.login(new_user['email'], new_user['password'])
        assert home_page.is_the_current_page
        home_page.set_region('us')

        # Use the first paid app
        app = home_page.header.search(':paid').results[0]
        app_name = app.name
        details_page = app.click_name()
        assert 'free' not in details_page.price_text
        assert 'paid' in details_page.app_status

        payment = details_page.click_install_button()
        payment.create_pin(self.PIN)
        payment.wait_for_buy_app_section_displayed()
        assert app_name == payment.app_name

        payment.click_buy_button()
        # We are not able to interact with the doorhanger that appears to install the app
        # using Selenium
        # We can check for the `purchased` attribute on the price button though
        details_page.wait_for_app_purchased()
def test_win_codepage_path_disabled_shortfilename(pyi_builder, monkeypatch):
    distdir = pyi_builder._distdir
    # Create some bytes and decode with the current codepage to get a filename that
    # is guaranteed to encode with the current codepage.
    # Assumes a one-byte codepage, i.e. not cp937 (shift-JIS) which is multibyte
    cp_filename = bytes(bytearray(range(0x80, 0x86))).decode('mbcs')

    distdir = os.path.join(distdir, cp_filename)
    os.makedirs(distdir)

    # Try to remove ShortFileName from this folder using `fsutil`
    # Requires admin privileges, so `xfail` if we don't have them.
    # `8dot3name strip` only affects subfolders, so pass the folder containing
    # our codepage filename
    if is_py2:
        # Python 2 requires mbcs-encoded args to subprocess
        fsutil_distdir = pyi_builder._distdir.encode('mbcs')
    else:
        # Python 3 accepts 'unicode' type.
        fsutil_distdir = pyi_builder._distdir

    if(subprocess.call(['fsutil', '8dot3name', 'strip', fsutil_distdir])):
        pytest.xfail("Administrator privileges required to strip ShortFileName.")

    tmpdir = os.path.join(pyi_builder._tmpdir, cp_filename + "_TMP")

    # On py2, os.environ only accepts str
    if is_py2:
        tmpdir = tmpdir.encode(sys.getfilesystemencoding())

    monkeypatch.setenv('TMPDIR', tmpdir)
    monkeypatch.setenv('TMP', tmpdir)

    pyi_builder._distdir = distdir
    pyi_builder.test_script('pyi_path_encoding.py')
예제 #7
0
파일: skipping.py 프로젝트: hpk42/pytest
def check_xfail_no_run(item):
    """check xfail(run=False)"""
    if not item.config.option.runxfail:
        evalxfail = item._evalxfail
        if evalxfail.istrue():
            if not evalxfail.get('run', True):
                pytest.xfail("[NOTRUN] " + evalxfail.getexplanation())
예제 #8
0
 def test_misc(self, vector):
   table_format = vector.get_value('table_format')
   if table_format.file_format in ['hbase', 'rc', 'parquet']:
     msg = ("Failing on rc/snap/block despite resolution of IMP-624,IMP-503. "
            "Failing on parquet because tables do not exist")
     pytest.xfail(msg)
   self.run_test_case('QueryTest/misc', vector)
예제 #9
0
 def test_sort(self, vector):
   if vector.get_value('table_format').file_format == 'hbase':
     pytest.xfail(reason="IMPALA-283 - select count(*) produces inconsistent results")
   vector.get_value('exec_option')['disable_outermost_topn'] = 1
   self.run_test_case('QueryTest/sort', vector)
   # We can get the sort tests for free from the top-n file
   self.run_test_case('QueryTest/top-n', vector)
예제 #10
0
def test_k_means_fit_predict(algo, dtype, constructor, seed, max_iter, tol):
    # check that fit.predict gives same result as fit_predict
    # There's a very small chance of failure with elkan on unstructured dataset
    # because predict method uses fast euclidean distances computation which
    # may cause small numerical instabilities.
    # NB: This test is largely redundant with respect to test_predict and
    #     test_predict_equal_labels.  This test has the added effect of
    #     testing idempotence of the fittng procesdure which appears to
    #     be where it fails on some MacOS setups.
    if sys.platform == "darwin":
        pytest.xfail(
            "Known failures on MacOS, See "
            "https://github.com/scikit-learn/scikit-learn/issues/12644")
    if not (algo == 'elkan' and constructor is sp.csr_matrix):
        rng = np.random.RandomState(seed)

        X = make_blobs(n_samples=1000, n_features=10, centers=10,
                       random_state=rng)[0].astype(dtype, copy=False)
        X = constructor(X)

        kmeans = KMeans(algorithm=algo, n_clusters=10, random_state=seed,
                        tol=tol, max_iter=max_iter, n_jobs=1)

        labels_1 = kmeans.fit(X).predict(X)
        labels_2 = kmeans.fit_predict(X)

        assert_array_equal(labels_1, labels_2)
예제 #11
0
    def test_create_from_format(self):

        pytest.xfail("check static function implementation")

        output = self.run('''
            $tz = new DateTimeZone('America/New_York');
            $format = 'Y-m-d H:i:s';
            $date = DateTime::createFromFormat($format, '2009-02-15 15:16:17', $tz);
            echo $date->format('Y-m-d H:i:s');
        ''')

        assert self.space.str_w(output.pop(0)) == '2009-02-15 15:16:17'

        output = self.run('''
            $tz = new DateTimeZone('America/New_York');
            $format = 'Y-m-!d H:i:s';
            $date = DateTime::createFromFormat($format, '2009-02-15 15:16:17', $tz);
            echo $date->format('Y-m-d H:i:s');
        ''')

        assert self.space.str_w(output.pop(0)) == '1970-01-15 15:16:17'

        output = self.run('''
            $tz = new DateTimeZone('America/New_York');
            $format = '!d';
            $date = DateTime::createFromFormat($format, '15', $tz);
            echo $date->format('Y-m-d H:i:s');
        ''')

        assert self.space.str_w(output.pop(0)) == '1970-01-15 00:00:00'
def test_missing_residues_xtal_2jaj(request, mol):
    if mol == 'pdb_2jaj_roundtrip':
        pytest.xfail('Writing missing residue records is not yet supported.')
    mol = request.getfixturevalue(mol)
    missingres = mol.metadata.missing_residues
    for expected in MISSINGRES_2JAJ:
        assert missingres[expected[0]][expected[2]] == expected[1]
예제 #13
0
def test_fits_mixins_per_column(table_cls, name_col, tmpdir):
    """Test write/read one col at a time and do detailed validation"""
    filename = str(tmpdir.join('test_simple.fits'))
    name, col = name_col

    c = [1.0, 2.0]
    t = table_cls([c, col, c], names=['c1', name, 'c2'])
    t[name].info.description = 'my \n\n\n description'
    t[name].info.meta = {'list': list(range(50)), 'dict': {'a': 'b' * 200}}

    if not t.has_mixin_columns:
        pytest.skip('column is not a mixin (e.g. Quantity subclass in Table)')

    if isinstance(t[name], NdarrayMixin):
        pytest.xfail('NdarrayMixin not supported')

    t.write(filename, format="fits")
    t2 = table_cls.read(filename, format='fits', astropy_native=True)

    assert t.colnames == t2.colnames

    for colname in t.colnames:
        assert_objects_equal(t[colname], t2[colname], compare_attrs[colname])

    # Special case to make sure Column type doesn't leak into Time class data
    if name.startswith('tm'):
        assert t2[name]._time.jd1.__class__ is np.ndarray
        assert t2[name]._time.jd2.__class__ is np.ndarray
예제 #14
0
def test_rotest():
    rot = None

    def quit():
        with pytest.raises(SystemExit):
            sys.exit()

    def clicked():
        rot.insert(TKNTR.END, "\nClicked at " + time.asctime(), force=True)
        rot.see(TKNTR.END)

    # make our test window
    try:
        top = TKNTR.Tk()
    except Exception as e:
        pytest.xfail(str(e))  # Travis does not have interactive session
    f = TKNTR.Frame(top)

    sc = TKNTR.Scrollbar(f)
    sc.pack(side=TKNTR.RIGHT, fill=TKNTR.Y)
    rot = ROText(f, wrap=TKNTR.WORD, height=10, yscrollcommand=sc.set,
                 focusBackTo=top)
    rot.pack(side=TKNTR.TOP, fill=TKNTR.X, expand=True)
    sc.config(command=rot.yview)
    f.pack(side=TKNTR.TOP, fill=TKNTR.X)

    b = TKNTR.Button(top, text='Click Me', command=clicked)
    b.pack(side=TKNTR.TOP, fill=TKNTR.X, expand=1)

    q = TKNTR.Button(top, text='Quit', command=quit)
    q.pack(side=TKNTR.TOP)

    # start
    top.mainloop()
예제 #15
0
def test_pyspark_roundtrip(tempdir, scheme, row_groups, comp, sql):
    if comp in ['BROTLI', 'ZSTD', 'LZO', "LZ4"]:
        pytest.xfail("spark doesn't support compression")
    data = pd.DataFrame({'i32': np.random.randint(-2**17, 2**17, size=1001,
                                                  dtype=np.int32),
                         'i64': np.random.randint(-2**33, 2**33, size=1001,
                                                  dtype=np.int64),
                         'f': np.random.randn(1001),
                         'bhello': np.random.choice([b'hello', b'you',
                            b'people'], size=1001).astype("O"),
                         't': [datetime.datetime.now()]*1001})

    data['t'] += pd.to_timedelta('1ns')
    data['hello'] = data.bhello.str.decode('utf8')
    data.loc[100, 'f'] = np.nan
    data['bcat'] = data.bhello.astype('category')
    data['cat'] = data.hello.astype('category')

    fname = os.path.join(tempdir, 'test.parquet')
    write(fname, data, file_scheme=scheme, row_group_offsets=row_groups,
          compression=comp, times='int96', write_index=True)

    df = sql.read.parquet(fname)
    ddf = df.sort('index').toPandas()
    for col in data:
        if data[col].dtype.kind == "M":
            # pyspark auto-converts timezones
            offset = round((datetime.datetime.utcnow() -
                            datetime.datetime.now()).seconds / 3600)
            ddf[col] + datetime.timedelta(hours=offset) == data[col]
        else:
            assert (ddf[col] == data[col])[~ddf[col].isnull()].all()
예제 #16
0
 def test_model_summary_with_fva(self, model, opt_solver, fraction):
     if opt_solver == "optlang-gurobi":
         pytest.xfail("FVA currently buggy")
     # test non-fva version (these should be fixed for textbook model
     expected_entries = [
         'idFluxRangeidFluxRangeBiomass_Ecol...0.874',
         'o2_e       21.8   [19.9, 23.7]'
         'h2o_e       29.2  [25, 30.7]',
         'glc__D_e   10     [9.52, 10]'
         'co2_e       22.8  [18.9, 24.7]',
         'nh4_e       4.77  [4.53, 5.16]'
         'h_e         17.5  [16.7, 22.4]',
         'pi_e        3.21  [3.05, 3.21]'
         'for_e        0    [0, 5.72]',
         'ac_e         0    [0, 1.91]',
         'pyr_e        0    [0, 1.27]',
         'lac__D_e     0    [0, 1.07]',
         'succ_e       0    [0, 0.837]',
         'glu__L_e     0    [0, 0.636]',
         'akg_e        0    [0, 0.715]',
         'etoh_e       0    [0, 1.11]',
         'acald_e      0    [0, 1.27]',
     ]
     # Need to use a different method here because
     # there are multiple entries per line.
     model.solver = opt_solver
     solution = model.optimize()
     with captured_output() as (out, err):
         model.summary(solution, fva=fraction)
     self.check_in_line(out.getvalue(), expected_entries)
예제 #17
0
def test_ecsv_mixins_per_column(table_cls, name_col):
    """Test write/read one col at a time and do detailed validation"""
    name, col = name_col

    c = [1.0, 2.0]
    t = table_cls([c, col, c], names=['c1', name, 'c2'])
    t[name].info.description = 'description'

    if not t.has_mixin_columns:
        pytest.skip('column is not a mixin (e.g. Quantity subclass in Table)')

    if isinstance(t[name], NdarrayMixin):
        pytest.xfail('NdarrayMixin not supported')

    out = StringIO()
    t.write(out, format="ascii.ecsv")
    t2 = table_cls.read(out.getvalue(), format='ascii.ecsv')

    assert t.colnames == t2.colnames

    for colname in t.colnames:
        assert_objects_equal(t[colname], t2[colname], compare_attrs[colname])

    # Special case to make sure Column type doesn't leak into Time class data
    if name.startswith('tm'):
        assert t2[name]._time.jd1.__class__ is np.ndarray
        assert t2[name]._time.jd2.__class__ is np.ndarray
예제 #18
0
def test_py2_unicode(testdir, pyfile_with_warnings):
    if getattr(sys, "pypy_version_info", ())[:2] == (5, 9) and sys.platform.startswith(
        "win"
    ):
        pytest.xfail("fails with unicode error on PyPy2 5.9 and Windows (#2905)")
    testdir.makepyfile(
        """
        # -*- coding: utf8 -*-
        import warnings
        import pytest


        @pytest.fixture
        def fix():
            warnings.warn(u"测试")
            yield

        @pytest.mark.filterwarnings('always')
        def test_func(fix):
            pass
    """
    )
    result = testdir.runpytest()
    result.stdout.fnmatch_lines(
        [
            "*== %s ==*" % WARNINGS_SUMMARY_HEADER,
            "*test_py2_unicode.py:8: UserWarning: \\u6d4b\\u8bd5",
            '*warnings.warn(u"\u6d4b\u8bd5")',
            "*warnings.py:*: UnicodeWarning: Warning is using unicode non*",
            "* 1 passed, 2 warnings*",
        ]
    )
예제 #19
0
def test_user_fonts():
    if not os.environ.get('APPVEYOR', False):
        pytest.xfail('This test does only work on appveyor since user fonts '
                     'are Windows specific and the developer\'s font '
                     'directory should remain unchanged')

    font_test_file = 'mpltest.ttf'

    # Precondition: the test font should not be available
    fonts = findSystemFonts()
    assert not any(font_test_file in font for font in fonts)

    user_fonts_dir = MSUserFontDirectories[0]

    # Make sure that the user font directory exists (this is probably not the
    # case on Windows versions < 1809)
    os.makedirs(user_fonts_dir)

    # Copy the test font to the user font directory
    shutil.copyfile(os.path.join(os.path.dirname(__file__), font_test_file),
                    os.path.join(user_fonts_dir, font_test_file))

    # Now, the font should be available
    fonts = findSystemFonts()
    assert any(font_test_file in font for font in fonts)
예제 #20
0
파일: Qe_class.py 프로젝트: encukou/pki
    def qerun(self, command, stdin_text=None, exp_returncode=0, exp_output=None):
        """
        qerun :: <command> [stdin_text=<string to pass as stdin>] 
            [exp_returncode=<retcode>]
            [<exp_output=<string to check from output>]
        - function to run a command and check return code and output

	:param str command: Command 
	:param str stdin_text: Stdin
	:param int exp_returncode: Return code (default 0)
	:param str exp_output: Check the expected output
        """
        cmd = self.run_command(command, stdin_text, raiseonerr=False)
        if cmd.returncode != exp_returncode:
            pytest.xfail("returncode mismatch.")
            print("GOT: ", cmd.returncode)
            print("EXPECTED: ", exp_returncode)

        if exp_output == None:
            print("Not checking expected output")

        elif cmd.stdout_text.find(exp_output) == 0:
            pytest.xfail("expected output not found")
            print("GOT: ", cmd.stdout_text)
            print("EXPECTED: ", exp_output)

        print("COMMAND SUCCEEDED!")
예제 #21
0
def test_insert_mode(file_name, elem_id, source, input_text, auto_insert, quteproc, request):
    url_path = "data/insert_mode_settings/html/{}".format(file_name)
    quteproc.open_path(url_path)

    quteproc.set_setting("input", "auto-insert-mode", auto_insert)
    quteproc.send_cmd(":click-element id {}".format(elem_id))
    quteproc.wait_for(message="Clicked editable element!")
    quteproc.send_cmd(":debug-set-fake-clipboard")

    if source == "keypress":
        quteproc.press_keys(input_text)
    elif source == "clipboard":
        if request.config.webengine:
            pytest.xfail(reason="QtWebEngine TODO: caret mode is not " "implemented")
            # Note we actually run the keypress tests with QtWebEngine, as for
            # some reason it selects all the text when clicking the field the
            # second time.
        quteproc.send_cmd(':debug-set-fake-clipboard "{}"'.format(input_text))
        quteproc.send_cmd(":insert-text {clipboard}")

    quteproc.send_cmd(":leave-mode")
    quteproc.send_cmd(":hint all")
    quteproc.wait_for(message="hints: *")
    quteproc.send_cmd(":follow-hint a")
    quteproc.wait_for(message="Clicked editable element!")
    quteproc.send_cmd(":enter-mode caret")
    quteproc.send_cmd(":toggle-selection")
    quteproc.send_cmd(":move-to-prev-word")
    quteproc.send_cmd(":yank selection")

    expected_message = "{} chars yanked to clipboard".format(len(input_text))
    quteproc.mark_expected(category="message", loglevel=logging.INFO, message=expected_message)
    quteproc.wait_for(message="Setting fake clipboard: {}".format(json.dumps(input_text)))
예제 #22
0
def test_record_to_file(camera, previewing, resolution, filenames_format_options):
    filename1, filename2, format, options = filenames_format_options
    if resolution == (2592, 1944) and 'resize' not in options:
        pytest.xfail('Cannot encode video at max resolution')
    if resolution == (1920, 1080) and format == 'mjpeg':
        pytest.xfail('Locks up camera')
    camera.start_recording(filename1, **options)
    try:
        camera.wait_recording(1)
        verify2 = (
                format != 'h264' or (
                    options.get('inline_headers', True) and
                    options.get('bitrate', 1)
                    )
                )
        if verify2:
            camera.split_recording(filename2)
            camera.wait_recording(1)
        else:
            with pytest.raises(picamera.PiCameraRuntimeError):
                camera.split_recording(filename2)
    finally:
        camera.stop_recording()
    if 'resize' in options:
        resolution = options['resize']
    verify_video(filename1, format, resolution)
    if verify2:
        verify_video(filename2, format, resolution)
예제 #23
0
def test_record_to_stream(camera, previewing, resolution, format_options):
    format, options = format_options
    if resolution == (2592, 1944) and 'resize' not in options:
        pytest.xfail('Cannot encode video at max resolution')
    if resolution == (1920, 1080) and format == 'mjpeg':
        pytest.xfail('Locks up camera')
    stream1 = tempfile.SpooledTemporaryFile()
    stream2 = tempfile.SpooledTemporaryFile()
    camera.start_recording(stream1, format, **options)
    try:
        camera.wait_recording(1)
        verify2 = (
                format != 'h264' or (
                    options.get('inline_headers', True) and
                    options.get('bitrate', 1)
                    )
                )
        if verify2:
            camera.split_recording(stream2)
            camera.wait_recording(1)
        else:
            with pytest.raises(picamera.PiCameraRuntimeError):
                camera.split_recording(stream2)
    finally:
        camera.stop_recording()
    stream1.seek(0)
    if 'resize' in options:
        resolution = options['resize']
    verify_video(stream1, format, resolution)
    if verify2:
        stream2.seek(0)
        verify_video(stream2, format, resolution)
예제 #24
0
    def test_masked_masked(self, operation_table_type):
        self._setup(operation_table_type)
        """Two masked tables"""
        if operation_table_type is QTable:
            pytest.xfail('Quantity columns do not support masking.')
        t1 = self.t1
        t1m = operation_table_type(self.t1, masked=True)
        t2 = self.t2
        t2m = operation_table_type(self.t2, masked=True)

        # Result should be masked even though not req'd by inner join
        t1m2m = table.join(t1m, t2m, join_type='inner')
        assert t1m2m.masked is True

        # Result should match non-masked result
        t12 = table.join(t1, t2)
        assert np.all(t12.as_array() == np.array(t1m2m))

        # Mask out some values in both tables and make sure they propagate
        t1m['b'].mask[1] = True
        t1m['c'].mask[2] = True
        t2m['d'].mask[2] = True
        t1m2m = table.join(t1m, t2m, join_type='inner', keys='a')
        assert sort_eq(t1m2m.pformat(), [' a  b_1  c  b_2  d ',
                                         '--- --- --- --- ---',
                                         '  1  --  L2 foo  R1',
                                         '  1  --  L2 foo  R2',
                                         '  1 bar  -- foo  R1',
                                         '  1 bar  -- foo  R2',
                                         '  2 bar  L4 bar  --'])
예제 #25
0
def _test_tiff_srs(sr, expect_fail):
    """
    This is not a test by itself; it gets called by the tests below.
    """
    ds = gdal.GetDriverByName('GTiff').Create('/vsimem/TestTiffSRS.tif', 1, 1)
    ds.SetProjection(sr.ExportToWkt())
    ds = None

    ds = gdal.Open('/vsimem/TestTiffSRS.tif')
    wkt = ds.GetProjectionRef()
    sr2 = osr.SpatialReference()
    sr2.SetFromUserInput(wkt)
    ds = None

    gdal.Unlink('/vsimem/TestTiffSRS.tif')

    if sr.IsSame(sr2) != 1:
        if expect_fail:
            pytest.xfail('did not get expected SRS. known to be broken currently. FIXME!')

        print(sr)
        print(sr2)
        assert False, 'did not get expected SRS'
    else:
        if expect_fail:
            print('Succeeded but expected fail...')
예제 #26
0
def check_open_tabs(quteproc, request, tabs):
    """Check the list of open tabs in the session.

    This is a lightweight alternative for "The session should look like: ...".

    It expects a list of URLs, with an optional "(active)" suffix.
    """
    if request.config.getoption('--qute-bdd-webengine'):
        pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented")
    session = quteproc.get_session()
    active_suffix = ' (active)'
    tabs = tabs.splitlines()
    assert len(session['windows']) == 1
    assert len(session['windows'][0]['tabs']) == len(tabs)

    for i, line in enumerate(tabs):
        line = line.strip()
        assert line.startswith('- ')
        line = line[2:]  # remove "- " prefix
        if line.endswith(active_suffix):
            path = line[:-len(active_suffix)]
            active = True
        else:
            path = line
            active = False

        session_tab = session['windows'][0]['tabs'][i]
        assert session_tab['history'][-1]['url'] == quteproc.path_to_url(path)
        if active:
            assert session_tab['active']
        else:
            assert 'active' not in session_tab
예제 #27
0
def test_aggregate_normal(resample_method):
    """Check TimeGrouper's aggregation is identical as normal groupby."""

    if resample_method == 'ohlc':
        pytest.xfail(reason='DataError: No numeric types to aggregate')

    data = np.random.randn(20, 4)
    normal_df = DataFrame(data, columns=['A', 'B', 'C', 'D'])
    normal_df['key'] = [1, 2, 3, 4, 5] * 4

    dt_df = DataFrame(data, columns=['A', 'B', 'C', 'D'])
    dt_df['key'] = [datetime(2013, 1, 1), datetime(2013, 1, 2),
                    datetime(2013, 1, 3), datetime(2013, 1, 4),
                    datetime(2013, 1, 5)] * 4

    normal_grouped = normal_df.groupby('key')
    dt_grouped = dt_df.groupby(TimeGrouper(key='key', freq='D'))

    expected = getattr(normal_grouped, resample_method)()
    dt_result = getattr(dt_grouped, resample_method)()
    expected.index = date_range(start='2013-01-01', freq='D',
                                periods=5, name='key')
    tm.assert_equal(expected, dt_result)

    # if TimeGrouper is used included, 'nth' doesn't work yet

    """
예제 #28
0
def test_circular_record(camera, previewing, resolution):
    if resolution == (2592, 1944):
        pytest.xfail('Cannot encode video at max resolution')
    stream = picamera.PiCameraCircularIO(camera, seconds=4)
    camera.start_recording(stream, format='h264')
    try:
        # Keep recording until the stream is definitely full and starts
        # removing earlier bits, or until 20 seconds
        start = time.time()
        while stream._length < stream._size and time.time() - start < 20:
            camera.wait_recording(1)
        # Record one more second, then test the result
        camera.wait_recording(1)
    finally:
        camera.stop_recording()
    temp = tempfile.SpooledTemporaryFile()
    for frame in stream.frames:
        if frame.header:
            stream.seek(frame.position)
            break
    while True:
        buf = stream.read1()
        if not buf:
            break
        temp.write(buf)
    temp.seek(0)
    verify_video(temp, 'h264', resolution)
예제 #29
0
    def test_include_na(self, sparse, dtype):
        if sparse:
            pytest.xfail(reason='nan in index is problematic (GH 16894)')

        s = ['a', 'b', np.nan]
        res = get_dummies(s, sparse=sparse, dtype=dtype)
        exp = DataFrame({'a': [1, 0, 0],
                         'b': [0, 1, 0]},
                        dtype=self.effective_dtype(dtype))
        assert_frame_equal(res, exp)

        # Sparse dataframes do not allow nan labelled columns, see #GH8822
        res_na = get_dummies(s, dummy_na=True, sparse=sparse, dtype=dtype)
        exp_na = DataFrame({nan: [0, 0, 1],
                            'a': [1, 0, 0],
                            'b': [0, 1, 0]},
                           dtype=self.effective_dtype(dtype))
        exp_na = exp_na.reindex(['a', 'b', nan], axis=1)
        # hack (NaN handling in assert_index_equal)
        exp_na.columns = res_na.columns
        assert_frame_equal(res_na, exp_na)

        res_just_na = get_dummies([nan], dummy_na=True,
                                  sparse=sparse, dtype=dtype)
        exp_just_na = DataFrame(Series(1, index=[0]), columns=[nan],
                                dtype=self.effective_dtype(dtype))
        tm.assert_numpy_array_equal(res_just_na.values, exp_just_na.values)
예제 #30
0
 def test_cancel_insert(self, vector):
   self.execute_cancel_test(vector)
   metric_verifier = MetricVerifier(self.impalad_test_service)
   try:
     metric_verifier.verify_no_open_files(timeout=10)
   except AssertionError:
     pytest.xfail("IMPALA-551: File handle leak for INSERT")
예제 #31
0
 def test_write(self, io_trial):
     name, _, test_model, reread_model = io_trial
     if name in ['fbc1']:
         pytest.xfail('not supported')
     self.compare_models(name, test_model, reread_model)
     self.extra_comparisons(name, test_model, reread_model)
예제 #32
0
 def test_eth_replaceTransaction_gas_price_defaulting_strategy_lower(
         self, web3, unlocked_account):
     pytest.xfail('Needs ability to efficiently control mining')
     super(
     ).test_eth_replaceTransaction_gas_price_defaulting_strategy_lower(
         web3, unlocked_account)
예제 #33
0
 def test_eth_replaceTransaction_incorrect_nonce(self, web3,
                                                 unlocked_account):
     pytest.xfail('Needs ability to efficiently control mining')
     super().test_eth_replaceTransaction_incorrect_nonce(
         web3, unlocked_account)
예제 #34
0
def test_json_test_data_coverage(cirq_obj_name: str, cls: Optional[type]):
    if cirq_obj_name in NOT_YET_SERIALIZABLE:
        return pytest.xfail(reason="Not serializable (yet)")

    json_path = TEST_DATA_PATH / f'{cirq_obj_name}.json'
    json_path2 = TEST_DATA_PATH / f'{cirq_obj_name}.json_inward'

    if not json_path.exists() and not json_path2.exists():
        # coverage: ignore
        raise NotImplementedError(
            textwrap.fill(
                f"Hello intrepid developer. There is a new public or "
                f"serializable object named '{cirq_obj_name}' that does not "
                f"have associated test data.\n"
                f"\n"
                f"You must create the file\n"
                f"    cirq/protocols/json_test_data/{cirq_obj_name}.json\n"
                f"and the file\n"
                f"    cirq/protocols/json_test_data/{cirq_obj_name}.repr\n"
                f"in order to guarantee this public object is, and will "
                f"remain, serializable.\n"
                f"\n"
                f"The content of the .repr file should be the string returned "
                f"by `repr(obj)` where `obj` is a test {cirq_obj_name} value "
                f"or list of such values. To get this to work you may need to "
                f"implement a __repr__ method for {cirq_obj_name}. The repr "
                f"must be a parsable python expression that evaluates to "
                f"something equal to `obj`."
                f"\n"
                f"The content of the .json file should be the string returned "
                f"by `cirq.to_json(obj)` where `obj` is the same object or "
                f"list of test objects.\n"
                f"To get this to work you likely need "
                f"to add {cirq_obj_name} to the "
                f"`cirq_class_resolver_dictionary` method in "
                f"the cirq/protocols/json_serialization.py source file. "
                f"You may also need to add a _json_dict_ method to "
                f"{cirq_obj_name}. In some cases you will also need to add a "
                f"_from_json_dict_ method to {cirq_obj_name}."
                f"\n"
                f"For more information on JSON serialization, please read the "
                f"docstring for protocols.SupportsJSON. If this object or "
                f"class is not appropriate for serialization, add its name to "
                f"the SHOULDNT_BE_SERIALIZED list in the "
                f"cirq/protocols/json_serialization_test.py source file."
            )
        )

    repr_file = TEST_DATA_PATH / f'{cirq_obj_name}.repr'
    if repr_file.exists() and cls is not None:
        objs = _eval_repr_data_file(repr_file)
        if not isinstance(objs, list):
            objs = [objs]

        for obj in objs:
            assert type(obj) == cls, (
                f"Value in {TEST_DATA_REL}/{cirq_obj_name}.repr must be of "
                f"exact type {cls}, or a list of instances of that type. But "
                f"the value (or one of the list entries) had type "
                f"{type(obj)}.\n"
                f"\n"
                f"If using a value of the wrong type is intended, move the "
                f"value to {TEST_DATA_REL}/{cirq_obj_name}.repr_inward\n"
                f"\n"
                f"Value with wrong type:\n{obj!r}."
            )
예제 #35
0
def test_json_test_data_coverage(mod_spec: ModuleJsonTestSpec,
                                 cirq_obj_name: str, cls):
    if cirq_obj_name == "SerializableByKey":
        pytest.skip(
            "SerializableByKey does not follow common serialization rules. "
            "It is tested separately in test_context_serialization.")

    if cirq_obj_name in mod_spec.not_yet_serializable:
        return pytest.xfail(reason="Not serializable (yet)")

    test_data_path = mod_spec.test_data_path
    rel_path = test_data_path.relative_to(REPO_ROOT)
    mod_path = mod_spec.name.replace(".", "/")
    rel_resolver_cache_path = f"{mod_path}/json_resolver_cache.py"
    json_path = test_data_path / f'{cirq_obj_name}.json'
    json_path2 = test_data_path / f'{cirq_obj_name}.json_inward'
    deprecation_deadline = mod_spec.deprecated.get(cirq_obj_name)

    if not json_path.exists() and not json_path2.exists():
        # coverage: ignore
        pytest.fail(
            f"Hello intrepid developer. There is a new public or "
            f"serializable object named '{cirq_obj_name}' in the module '{mod_spec.name}' "
            f"that does not have associated test data.\n"
            f"\n"
            f"You must create the file\n"
            f"    {rel_path}/{cirq_obj_name}.json\n"
            f"and the file\n"
            f"    {rel_path}/{cirq_obj_name}.repr\n"
            f"in order to guarantee this public object is, and will "
            f"remain, serializable.\n"
            f"\n"
            f"The content of the .repr file should be the string returned "
            f"by `repr(obj)` where `obj` is a test {cirq_obj_name} value "
            f"or list of such values. To get this to work you may need to "
            f"implement a __repr__ method for {cirq_obj_name}. The repr "
            f"must be a parsable python expression that evaluates to "
            f"something equal to `obj`."
            f"\n"
            f"The content of the .json file should be the string returned "
            f"by `cirq.to_json(obj)` where `obj` is the same object or "
            f"list of test objects.\n"
            f"To get this to work you likely need "
            f"to add {cirq_obj_name} to the "
            f"`_class_resolver_dictionary` method in "
            f"the {rel_resolver_cache_path} source file. "
            f"You may also need to add a _json_dict_ method to "
            f"{cirq_obj_name}. In some cases you will also need to add a "
            f"_from_json_dict_ class method to the {cirq_obj_name} class."
            f"\n"
            f"For more information on JSON serialization, please read the "
            f"docstring for cirq.protocols.SupportsJSON. If this object or "
            f"class is not appropriate for serialization, add its name to "
            f"the `should_not_be_serialized` list in the TestSpec defined in the "
            f"{rel_path}/spec.py source file.")

    repr_file = test_data_path / f'{cirq_obj_name}.repr'
    if repr_file.exists() and cls is not None:
        objs = _eval_repr_data_file(repr_file,
                                    deprecation_deadline=deprecation_deadline)
        if not isinstance(objs, list):
            objs = [objs]

        for obj in objs:
            assert type(obj) == cls, (
                f"Value in {test_data_path}/{cirq_obj_name}.repr must be of "
                f"exact type {cls}, or a list of instances of that type. But "
                f"the value (or one of the list entries) had type "
                f"{type(obj)}.\n"
                f"\n"
                f"If using a value of the wrong type is intended, move the "
                f"value to {test_data_path}/{cirq_obj_name}.repr_inward\n"
                f"\n"
                f"Value with wrong type:\n{obj!r}.")
def test_cont_basic(distname, arg):
    # this test skips slow distributions

    if distname == 'truncnorm':
        pytest.xfail(reason=distname)

    try:
        distfn = getattr(stats, distname)
    except TypeError:
        distfn = distname
        distname = 'rv_histogram_instance'
    np.random.seed(765456)
    sn = 500
    with npt.suppress_warnings() as sup:
        # frechet_l and frechet_r are deprecated, so all their
        # methods generate DeprecationWarnings.
        sup.filter(category=DeprecationWarning, message=".*frechet_")
        rvs = distfn.rvs(size=sn, *arg)
        sm = rvs.mean()
        sv = rvs.var()
        m, v = distfn.stats(*arg)

        check_sample_meanvar_(distfn, arg, m, v, sm, sv, sn, distname + 'sample mean test')
        check_cdf_ppf(distfn, arg, distname)
        check_sf_isf(distfn, arg, distname)
        check_pdf(distfn, arg, distname)
        check_pdf_logpdf(distfn, arg, distname)
        check_pdf_logpdf_at_endpoints(distfn, arg, distname)
        check_cdf_logcdf(distfn, arg, distname)
        check_sf_logsf(distfn, arg, distname)
        check_ppf_broadcast(distfn, arg, distname)

        alpha = 0.01
        if distname == 'rv_histogram_instance':
            check_distribution_rvs(distfn.cdf, arg, alpha, rvs)
        elif distname != 'geninvgauss':
            # skip kstest for geninvgauss since cdf is too slow; see test for
            # rv generation in TestGenInvGauss in test_distributions.py
            check_distribution_rvs(distname, arg, alpha, rvs)

        locscale_defaults = (0, 1)
        meths = [distfn.pdf, distfn.logpdf, distfn.cdf, distfn.logcdf,
                 distfn.logsf]
        # make sure arguments are within support
        spec_x = {'frechet_l': -0.5, 'weibull_max': -0.5, 'levy_l': -0.5,
                  'pareto': 1.5, 'tukeylambda': 0.3,
                  'rv_histogram_instance': 5.0}
        x = spec_x.get(distname, 0.5)
        if distname == 'invweibull':
            arg = (1,)
        elif distname == 'ksone':
            arg = (3,)
        check_named_args(distfn, x, arg, locscale_defaults, meths)
        check_random_state_property(distfn, arg)
        check_pickling(distfn, arg)
        check_freezing(distfn, arg)

        # Entropy
        if distname not in ['kstwobign']:
            check_entropy(distfn, arg, distname)

        if distfn.numargs == 0:
            check_vecentropy(distfn, arg)

        if (distfn.__class__._entropy != stats.rv_continuous._entropy
                and distname != 'vonmises'):
            check_private_entropy(distfn, arg, stats.rv_continuous)

        with npt.suppress_warnings() as sup:
            sup.filter(IntegrationWarning, "The occurrence of roundoff error")
            sup.filter(IntegrationWarning, "Extremely bad integrand")
            sup.filter(RuntimeWarning, "invalid value")
            check_entropy_vect_scale(distfn, arg)

        check_retrieving_support(distfn, arg)
        check_edge_support(distfn, arg)

        check_meth_dtype(distfn, arg, meths)
        check_ppf_dtype(distfn, arg)

        if distname not in fails_cmplx:
            check_cmplx_deriv(distfn, arg)

        if distname != 'truncnorm':
            check_ppf_private(distfn, arg, distname)

        if distname not in skip_fit_test:
            check_fit_args(distfn, arg, rvs[0:200])

        if distname not in skip_fit_fix_test:
            check_fit_args_fix(distfn, arg, rvs[0:200])
예제 #37
0
    def test_compare_numdiff(self, use_sqrt, reml, profile_fe):

        n_grp = 200
        grpsize = 5
        k_fe = 3
        k_re = 2

        np.random.seed(3558)
        exog_fe = np.random.normal(size=(n_grp * grpsize, k_fe))
        exog_re = np.random.normal(size=(n_grp * grpsize, k_re))
        exog_re[:, 0] = 1
        exog_vc = np.random.normal(size=(n_grp * grpsize, 3))
        slopes = np.random.normal(size=(n_grp, k_re))
        slopes[:, -1] *= 2
        slopes = np.kron(slopes, np.ones((grpsize, 1)))
        slopes_vc = np.random.normal(size=(n_grp, 3))
        slopes_vc = np.kron(slopes_vc, np.ones((grpsize, 1)))
        slopes_vc[:, -1] *= 2
        re_values = (slopes * exog_re).sum(1)
        vc_values = (slopes_vc * exog_vc).sum(1)
        err = np.random.normal(size=n_grp * grpsize)
        endog = exog_fe.sum(1) + re_values + vc_values + err
        groups = np.kron(range(n_grp), np.ones(grpsize))

        vc = {"a": {}, "b": {}}
        for i in range(n_grp):
            ix = np.flatnonzero(groups == i)
            vc["a"][i] = exog_vc[ix, 0:2]
            vc["b"][i] = exog_vc[ix, 2:3]

        model = MixedLM(endog,
                        exog_fe,
                        groups,
                        exog_re,
                        exog_vc=vc,
                        use_sqrt=use_sqrt)
        rslt = model.fit(reml=reml)

        loglike = loglike_function(model,
                                   profile_fe=profile_fe,
                                   has_fe=not profile_fe)

        try:
            # Test the score at several points.
            for kr in range(5):
                fe_params = np.random.normal(size=k_fe)
                cov_re = np.random.normal(size=(k_re, k_re))
                cov_re = np.dot(cov_re.T, cov_re)
                vcomp = np.random.normal(size=2)**2
                params = MixedLMParams.from_components(fe_params,
                                                       cov_re=cov_re,
                                                       vcomp=vcomp)
                params_vec = params.get_packed(has_fe=not profile_fe,
                                               use_sqrt=use_sqrt)

                # Check scores
                gr = -model.score(params, profile_fe=profile_fe)
                ngr = nd.approx_fprime(params_vec, loglike)
                assert_allclose(gr, ngr, rtol=1e-3)

            # Check Hessian matrices at the MLE (we do not have
            # the profile Hessian matrix and we do not care
            # about the Hessian for the square root
            # transformed parameter).
            if (profile_fe is False) and (use_sqrt is False):
                hess = -model.hessian(rslt.params_object)
                params_vec = rslt.params_object.get_packed(use_sqrt=False,
                                                           has_fe=True)
                loglike_h = loglike_function(model,
                                             profile_fe=False,
                                             has_fe=True)
                nhess = nd.approx_hess(params_vec, loglike_h)
                assert_allclose(hess, nhess, rtol=1e-3)
        except AssertionError:
            # See GH#5628; because this test fails unpredictably but only on
            #  OSX, we only xfail it there.
            if PLATFORM_OSX:
                pytest.xfail("fails on OSX due to unresolved "
                             "numerical differences")
            else:
                raise
def test_fit_docstring_attributes(name, Estimator):
    pytest.importorskip('numpydoc')
    from numpydoc import docscrape

    doc = docscrape.ClassDoc(Estimator)
    attributes = doc['Attributes']

    IGNORED = {
        'ClassifierChain', 'ColumnTransformer', 'CountVectorizer',
        'DictVectorizer', 'FeatureUnion', 'GaussianRandomProjection',
        'GridSearchCV', 'MultiOutputClassifier', 'MultiOutputRegressor',
        'NoSampleWeightWrapper', 'OneVsOneClassifier', 'OutputCodeClassifier',
        'Pipeline', 'RFE', 'RFECV', 'RandomizedSearchCV', 'RegressorChain',
        'SelectFromModel', 'SparseCoder', 'SparseRandomProjection',
        'SpectralBiclustering', 'StackingClassifier', 'StackingRegressor',
        'TfidfVectorizer', 'VotingClassifier', 'VotingRegressor'
    }
    if Estimator.__name__ in IGNORED or Estimator.__name__.startswith('_'):
        pytest.skip("Estimator cannot be fit easily to test fit attributes")

    est = _construct_instance(Estimator)

    if Estimator.__name__ == 'SelectKBest':
        est.k = 2

    if Estimator.__name__ == 'DummyClassifier':
        est.strategy = "stratified"

    # TO BE REMOVED for v0.25 (avoid FutureWarning)
    if Estimator.__name__ == 'AffinityPropagation':
        est.random_state = 63

    X, y = make_classification(n_samples=20,
                               n_features=3,
                               n_redundant=0,
                               n_classes=2,
                               random_state=2)

    y = _enforce_estimator_tags_y(est, y)
    X = _enforce_estimator_tags_x(est, X)

    if '1dlabels' in est._get_tags()['X_types']:
        est.fit(y)
    elif '2dlabels' in est._get_tags()['X_types']:
        est.fit(np.c_[y, y])
    else:
        est.fit(X, y)

    skipped_attributes = {'n_features_in_'}

    for attr in attributes:
        if attr.name in skipped_attributes:
            continue
        desc = ' '.join(attr.desc).lower()
        # As certain attributes are present "only" if a certain parameter is
        # provided, this checks if the word "only" is present in the attribute
        # description, and if not the attribute is required to be present.
        if 'only ' in desc:
            continue
        # ignore deprecation warnings
        with ignore_warnings(category=FutureWarning):
            assert hasattr(est, attr.name)

    IGNORED = {
        'BayesianRidge', 'Birch', 'CCA', 'LarsCV', 'Lasso', 'LassoLarsIC',
        'OrthogonalMatchingPursuit', 'PLSCanonical', 'PLSSVD'
    }

    if Estimator.__name__ in IGNORED:
        pytest.xfail(reason="Estimator has too many undocumented attributes.")

    fit_attr = [
        k for k in est.__dict__.keys()
        if k.endswith('_') and not k.startswith('_')
    ]
    fit_attr_names = [attr.name for attr in attributes]
    undocumented_attrs = set(fit_attr).difference(fit_attr_names)
    undocumented_attrs = set(undocumented_attrs).difference(skipped_attributes)
    assert not undocumented_attrs,\
        "Undocumented attributes: {}".format(undocumented_attrs)
예제 #39
0
def test_vs_bitcoind(match_key, check_against_bitcoind, bitcoind, start_sign,
                     end_sign, we_finalize, num_dests):

    wallet_xfp = match_key()

    bal = bitcoind.getbalance()
    assert bal > 0, "need some play money; drink from a faucet"

    amt = round((bal / 4) / num_dests, 6)

    args = {}

    for no in range(num_dests):
        dest = bitcoind.getrawchangeaddress()
        assert dest[0] in '2mn' or dest.startswith('tb1'), dest

        args[dest] = amt

    if 0:
        # old approach: fundraw + convert to psbt

        # working with hex strings here
        txn = bitcoind.createrawtransaction([], args)
        assert txn[0:2] == '02'
        #print(txn)

        resp = bitcoind.fundrawtransaction(txn)
        txn2 = resp['hex']
        fee = resp['fee']
        chg_pos = resp['changepos']
        #print(txn2)

        print("Sending %.8f XTN to %s (Change back in position: %d)" %
              (amt, dest, chg_pos))

        psbt = b64decode(bitcoind.converttopsbt(txn2, True))

    # use walletcreatefundedpsbt
    # - updated/validated against 0.17.1
    resp = bitcoind.walletcreatefundedpsbt(
        [], args, 0, {
            'subtractFeeFromOutputs': list(range(num_dests)),
            'feeRate': 0.00001500
        }, True)

    if 0:
        # OMFG all this to reconstruct the rpc command!
        import json, decimal

        def EncodeDecimal(o):
            if isinstance(o, decimal.Decimal):
                return float(round(o, 8))
            raise TypeError

        print('walletcreatefundedpsbt "[]" "[%s]" 0 {} true' %
              json.dumps(args, default=EncodeDecimal).replace('"', '\\"'))

    psbt = b64decode(resp['psbt'])
    fee = resp['fee']
    chg_pos = resp['changepos']

    open('debug/vs.psbt', 'wb').write(psbt)

    # check some basics
    mine = BasicPSBT().parse(psbt)
    for i in mine.inputs:
        got_xfp, = struct.unpack_from('I', list(i.bip32_paths.values())[0])
        #assert hex(got_xfp) == hex(wallet_xfp), "wrong HD master key fingerprint"

        # see <https://github.com/bitcoin/bitcoin/issues/15884>
        if hex(got_xfp) != hex(wallet_xfp):
            raise pytest.xfail("wrong HD master key fingerprint")

    # pull out included txn
    txn2 = B2A(mine.txn)

    start_sign(psbt, finalize=we_finalize)

    # verify against how bitcoind reads it
    check_against_bitcoind(txn2, fee)

    signed = end_sign(accept=True)
    open('debug/vs-signed.psbt', 'wb').write(signed)

    if not we_finalize:
        b4 = BasicPSBT().parse(psbt)
        aft = BasicPSBT().parse(signed)
        assert b4 != aft, "signing didn't change anything?"

        open('debug/signed.psbt', 'wb').write(signed)
        resp = bitcoind.finalizepsbt(str(b64encode(signed), 'ascii'), True)

        #combined_psbt = b64decode(resp['psbt'])
        #open('debug/combined.psbt', 'wb').write(combined_psbt)

        assert resp['complete'] == True, "bitcoind wasn't able to finalize it"

        network = a2b_hex(resp['hex'])

        # assert resp['complete']
        print("Final txn: %r" % network)
        open('debug/finalized-by-btcd.txn', 'wb').write(network)

        # try to send it
        txed = bitcoind.sendrawtransaction(B2A(network))
        print("Final txn hash: %r" % txed)

    else:
        assert signed[0:4] != b'psbt', "expecting raw bitcoin txn"
        #print("Final txn: %s" % B2A(signed))
        open('debug/finalized-by-cc.txn', 'wb').write(signed)

        txed = bitcoind.sendrawtransaction(B2A(signed))
        print("Final txn hash: %r" % txed)
예제 #40
0
 def test_read(self, io_trial):
     name, reference_model, test_model, _ = io_trial
     if name in ['fbc1']:
         pytest.xfail('not supported')
     self.compare_models(name, reference_model, test_model)
     self.extra_comparisons(name, reference_model, test_model)
예제 #41
0
 def test_snr_half_cpu(self, preds, target, sk_metric, zero_mean):
     pytest.xfail("SNR metric does not support cpu + half precision")
예제 #42
0
def test_finalization_vs_bitcoind(match_key, check_against_bitcoind, bitcoind,
                                  start_sign, end_sign, num_dests):
    # Compare how we finalize vs bitcoind ... should be exactly the same txn

    wallet_xfp = match_key()

    bal = bitcoind.getbalance()
    assert bal > 0, "need some play money; drink from a faucet"

    amt = round((bal / 4) / num_dests, 6)

    args = {}

    for no in range(num_dests):
        dest = bitcoind.getrawchangeaddress()
        assert dest[0] in '2mn' or dest.startswith('tb1'), dest

        args[dest] = amt

    # use walletcreatefundedpsbt
    # - updated/validated against 0.17.1
    resp = bitcoind.walletcreatefundedpsbt(
        [], args, 0, {
            'subtractFeeFromOutputs': list(range(num_dests)),
            'feeRate': 0.00001500
        }, True)

    psbt = b64decode(resp['psbt'])
    fee = resp['fee']
    chg_pos = resp['changepos']

    open('debug/vs.psbt', 'wb').write(psbt)

    # check some basics
    mine = BasicPSBT().parse(psbt)
    for i in mine.inputs:
        got_xfp, = struct.unpack_from('I', list(i.bip32_paths.values())[0])
        #assert hex(got_xfp) == hex(wallet_xfp), "wrong HD master key fingerprint"

        # see <https://github.com/bitcoin/bitcoin/issues/15884>
        if hex(got_xfp) != hex(wallet_xfp):
            raise pytest.xfail("wrong HD master key fingerprint")

    # pull out included txn
    txn2 = B2A(mine.txn)

    start_sign(psbt, finalize=True)

    # verify against how bitcoind reads it
    check_against_bitcoind(txn2, fee)

    signed_final = end_sign(accept=True)
    assert signed_final[0:4] != b'psbt', "expecting raw bitcoin txn"
    open('debug/finalized-by-ckcc.txn', 'wt').write(B2A(signed_final))

    # Sign again, but don't finalize it.
    start_sign(psbt, finalize=False)
    signed = end_sign(accept=True)

    open('debug/vs-signed-unfin.psbt', 'wb').write(signed)

    # Use bitcoind to finalize it this time.
    resp = bitcoind.finalizepsbt(str(b64encode(signed), 'ascii'), True)
    assert resp['complete'] == True, "bitcoind wasn't able to finalize it"

    network = a2b_hex(resp['hex'])

    # assert resp['complete']
    #print("Final txn: %r" % network)
    open('debug/finalized-by-btcd.txn', 'wt').write(B2A(network))

    assert network == signed_final, "Finalized differently"

    # try to send it
    txed = bitcoind.sendrawtransaction(B2A(network))
    print("Final txn hash: %r" % txed)
예제 #43
0
    def check(self, data=None, dtype=None, dtypes=None):
        """Check the special function against the data."""

        if self.knownfailure:
            import pytest
            pytest.xfail(reason=self.knownfailure)

        if data is None:
            data = self.data

        if dtype is None:
            dtype = data.dtype
        else:
            data = data.astype(dtype)

        rtol, atol = self.get_tolerances(dtype)

        # Apply given filter functions
        if self.param_filter:
            param_mask = np.ones((data.shape[0], ), np.bool_)
            for j, filter in zip(self.param_columns, self.param_filter):
                if filter:
                    param_mask &= list(filter(data[:, j]))
            data = data[param_mask]

        # Pick parameters from the correct columns
        params = []
        for idx, j in enumerate(self.param_columns):
            if np.iscomplexobj(j):
                j = int(j.imag)
                params.append(data[:, j].astype(complex))
            elif dtypes and idx < len(dtypes):
                params.append(data[:, j].astype(dtypes[idx]))
            else:
                params.append(data[:, j])

        # Helper for evaluating results
        def eval_func_at_params(func, skip_mask=None):
            if self.vectorized:
                got = func(*params)
            else:
                got = []
                for j in range(len(params[0])):
                    if skip_mask is not None and skip_mask[j]:
                        got.append(np.nan)
                        continue
                    got.append(
                        func(*tuple([params[i][j]
                                     for i in range(len(params))])))
                got = np.asarray(got)
            if not isinstance(got, tuple):
                got = (got, )
            return got

        # Evaluate function to be tested
        got = eval_func_at_params(self.func)

        # Grab the correct results
        if self.result_columns is not None:
            # Correct results passed in with the data
            wanted = tuple([data[:, icol] for icol in self.result_columns])
        else:
            # Function producing correct results passed in
            skip_mask = None
            if self.nan_ok and len(got) == 1:
                # Don't spend time evaluating what doesn't need to be evaluated
                skip_mask = np.isnan(got[0])
            wanted = eval_func_at_params(self.result_func, skip_mask=skip_mask)

        # Check the validity of each output returned
        assert_(len(got) == len(wanted))

        for output_num, (x, y) in enumerate(zip(got, wanted)):
            if np.issubdtype(x.dtype,
                             np.complexfloating) or self.ignore_inf_sign:
                pinf_x = np.isinf(x)
                pinf_y = np.isinf(y)
                minf_x = np.isinf(x)
                minf_y = np.isinf(y)
            else:
                pinf_x = np.isposinf(x)
                pinf_y = np.isposinf(y)
                minf_x = np.isneginf(x)
                minf_y = np.isneginf(y)
            nan_x = np.isnan(x)
            nan_y = np.isnan(y)

            olderr = np.seterr(all='ignore')
            try:
                abs_y = np.absolute(y)
                abs_y[~np.isfinite(abs_y)] = 0
                diff = np.absolute(x - y)
                diff[~np.isfinite(diff)] = 0

                rdiff = diff / np.absolute(y)
                rdiff[~np.isfinite(rdiff)] = 0
            finally:
                np.seterr(**olderr)

            tol_mask = (diff <= atol + rtol * abs_y)
            pinf_mask = (pinf_x == pinf_y)
            minf_mask = (minf_x == minf_y)

            nan_mask = (nan_x == nan_y)

            bad_j = ~(tol_mask & pinf_mask & minf_mask & nan_mask)

            point_count = bad_j.size
            if self.nan_ok:
                bad_j &= ~nan_x
                bad_j &= ~nan_y
                point_count -= (nan_x | nan_y).sum()

            if not self.distinguish_nan_and_inf and not self.nan_ok:
                # If nan's are okay we've already covered all these cases
                inf_x = np.isinf(x)
                inf_y = np.isinf(y)
                both_nonfinite = (inf_x & nan_y) | (nan_x & inf_y)
                bad_j &= ~both_nonfinite
                point_count -= both_nonfinite.sum()

            if np.any(bad_j):
                # Some bad results: inform what, where, and how bad
                msg = [""]
                msg.append("Max |adiff|: %g" % diff.max())
                msg.append("Max |rdiff|: %g" % rdiff.max())
                msg.append(
                    "Bad results (%d out of %d) for the following points (in output %d):"
                    % (
                        np.sum(bad_j),
                        point_count,
                        output_num,
                    ))
                for j in np.nonzero(bad_j)[0]:
                    j = int(j)
                    fmt = lambda x: "%30s" % np.array2string(x[j],
                                                             precision=18)
                    a = "  ".join(map(fmt, params))
                    b = "  ".join(map(fmt, got))
                    c = "  ".join(map(fmt, wanted))
                    d = fmt(rdiff)
                    msg.append("%s => %s != %s  (rdiff %s)" % (a, b, c, d))
                assert_(False, "\n".join(msg))
예제 #44
0
def pytest_runtest_setup(item):
    if "incremental" in item.keywords:
        previousfailed = getattr(item.parent, "_previousfailed", None)
        if previousfailed is not None:
            pytest.xfail("previous test failed (%s)" % previousfailed.name)
예제 #45
0
def skip_fsspec_s3fs(fs):
    if fs.type_name == "py::fsspec+s3":
        pytest.xfail(reason="Not working with fsspec's s3fs")
 def test_eth_getStorageAt(self, web3, emitter_contract_address):
     pytest.xfail('json-rpc method is not implemented on eth-tester')
     super().test_eth_getStorageAt(web3, emitter_contract_address)
def test_modules_regen_metadata(tmpdir, modules_label, tools_label, command, scenario):
    modules = ProjectFactory.get_precook(modules_label)
    if modules.skip:
        pytest.skip("{} cannot be built on this kernel".format(modules.label))
    tools = ProjectFactory.get_precook(tools_label)
    babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)

    nb_events = 10

    with Run.get_runtime(str(tmpdir)) as runtime:
        runtime.add_project(modules)
        runtime.add_project(tools)
        runtime.add_project(babeltrace)

        trace_path = os.path.join(runtime.lttng_home, 'trace')
        babeltrace_cmd = 'babeltrace {}'.format(trace_path)

        sessiond = sessiond_spawn(runtime)
        runtime.load_test_module()

        runtime.run("lttng create trace -o {}".format(trace_path))
        runtime.run("lttng enable-event -k lttng_test_filter_event")
        runtime.run("lttng start")
        with open(Settings.lttng_test_procfile, 'w') as procfile:
            procfile.write("{}".format(nb_events))

        runtime.run("lttng stop")

        # Validate that we have all event base on the current metadata
        cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd)
        assert line_count(cp_out) == nb_events

        # Empty the metadata file
        open(get_metadata_file_path(trace_path), 'w').close()

        # Babeltrace should never be able to parse the trace
        with pytest.raises(subprocess.CalledProcessError):
            runtime.run(babeltrace_cmd)

        runtime.run("lttng start")

        # TODO: rework this a bit to differentiate each errors and rework how
        # the condition are meet
        if scenario == "Unsupported by tools" or scenario == "Unsupported by modules":
            if modules_label == "lttng-modules-2.7" and scenario == "Unsupported by modules":
                # Error from lttng-modules-2.7 is not reported correctly by
                # sessiond. But it is reported on the sessiond side.
                # For now, run the command, validate that the error exist on
                # sessiond side and mark as xfail.
                runtime.run("lttng {}".format(command))
            else:
                with pytest.raises(subprocess.CalledProcessError):
                    runtime.run("lttng {}".format(command))

            # Make sure everything looks good on this side
            runtime.run("lttng stop")
            runtime.run("lttng destroy -a")
            stderr_path = runtime.get_subprocess_stderr_path(sessiond)
            sessiond = runtime.subprocess_terminate(sessiond)
            if scenario == "Unsupported by modules":
                error_msg = "Error: Failed to regenerate the kernel metadata"
                assert file_contains(stderr_path, [error_msg]), "Error message missing"
            if modules_label == "lttng-modules-2.7" and scenario == "Unsupported by modules":
                pytest.xfail("Lttng-tools does not bubble up error from unsupported metadata regeneration")

            return

        runtime.run("lttng {}".format(command))
        runtime.run("lttng stop")
        runtime.run("lttng destroy -a")

        sessiond = runtime.subprocess_terminate(sessiond)
        if sessiond.returncode != 0:
            pytest.fail("Return value of sessiond is not zero")

        cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd)
        assert line_count(cp_out) == nb_events
예제 #48
0
def test_filehosts(fh):
    b = pylibgen.Book(id=1421206, md5="1af2c71c1342e850e1e47013b06f9eb9")
    try:
        check_url(b.get_url(fh))
    except requests.exceptions.ReadTimeout as e:
        pytest.xfail(f"Attempt to reach filehost {fh} timed out.")
예제 #49
0
    def testCSVExport(self):
        # TODO: When Hytra is supported on Windows, we shouldn't skip the test and throw an assert instead
        try:
            import hytra
        except ImportError as e:
            pytest.xfail("Hytra tracking pipeline couldn't be imported: " + str(e))

        # Skip test because there are missing files
        if (
            not os.path.isfile(self.PROJECT_FILE)
            or not os.path.isfile(self.RAW_DATA_FILE)
            or not os.path.isfile(self.BINARY_SEGMENTATION_FILE)
        ):
            logger.info("Test files not found.")

        args = " --project=" + self.PROJECT_FILE
        args += " --headless"

        args += " --export_source=Plugin"
        args += " --export_plugin=CSV-Table"
        args += " --raw_data " + self.RAW_DATA_FILE  # + '/data'
        args += " --binary_image " + self.BINARY_SEGMENTATION_FILE + "/exported_data"

        sys.argv = ["ilastik.py"]  # Clear the existing commandline args so it looks like we're starting fresh.
        sys.argv += args.split()

        # Start up the ilastik.py entry script as if we had launched it from the command line
        if SOLVER is None:
            logger.info("Could not find any ILP solver - unable to run learning tests!")
        else:
            self.ilastik_startup.main()

            # Load csv file
            data = np.genfromtxt(self.EXPECTED_CSV_FILE, dtype=float, delimiter=",", names=True)

            # Check for expected number of lines
            logger.info("Number of rows in the csv file: {}".format(data.shape[0]))
            print("Number of rows in the csv file: {}".format(data.shape[0]))
            assert (
                data.shape[0] == self.EXPECTED_NUM_LINES_TRACKING
            ), "Number of rows in the csv file differs from expected"

            # Check that the csv file contains the default fields.
            assert "frame" in data.dtype.names, "'frame' not found in the csv file!"
            assert "labelimageId" in data.dtype.names, "'labelimageId' not found in the csv file!"
            assert "lineageId" in data.dtype.names, "'lineageId' not found in the csv file!"
            assert "trackId" in data.dtype.names, "'trackId' not found in the csv file!"
            assert "parentTrackId" in data.dtype.names, "'parentTrackId' not found in the csv file!"
            assert "mergerLabelId" in data.dtype.names, "'mergerLabelId' not found in the csv file!"
            assert "Terminal_2_0" in data.dtype.names, "'Terminal_2_0' not found in the csv file!"
            assert "Terminal_2_1" in data.dtype.names, "'Terminal_2_1' not found in the csv file!"
            assert "Diameter_0" in data.dtype.names, "'Diameter_0' not found in the csv file!"
            assert "Bounding_Box_Minimum_0" in data.dtype.names, "'Bounding_Box_Minimum_0' not found in the csv file!"
            assert "Bounding_Box_Minimum_1" in data.dtype.names, "'Bounding_Box_Minimum_1' not found in the csv file!"
            assert "Center_of_the_object_0" in data.dtype.names, "'Center_of_the_object_0' not found in the csv file!"
            assert "Center_of_the_object_1" in data.dtype.names, "'Center_of_the_object_1' not found in the csv file!"
            assert "Bounding_Box_Maximum_0" in data.dtype.names, "'Bounding_Box_Maximum_0' not found in the csv file!"
            assert "Bounding_Box_Maximum_1" in data.dtype.names, "'Bounding_Box_Maximum_1' not found in the csv file!"

            # Check for expected number of mergers
            merger_count = 0
            previous = 0
            for id in data["mergerLabelId"]:
                if previous == 0 and not id == 0:
                    merger_count += 1
                previous = id
            logger.info("Number of mergers in the csv file: {}".format(merger_count))
            assert (
                merger_count == self.EXPECTED_MERGER_NUM
            ), "Number of mergers {} in the csv file differs from expected {}.".format(
                merger_count, self.EXPECTED_MERGER_NUM
            )

            # Check for expected number of false detections
            false_detection_count = 0
            for id in data["lineageId"]:
                if id == -1:
                    false_detection_count += 1
            logger.info("Number of false detections in the csv file: {}".format(false_detection_count))
            assert (
                false_detection_count == self.EXPECTED_FALSE_DETECTIONS_NUM
            ), "Number of false detections {} in the csv file differs from expected {}.".format(
                false_detection_count, self.EXPECTED_FALSE_DETECTIONS_NUM
            )

            # Check for expected number of divisions
            division_count = 0
            for id in data["parentTrackId"]:
                if not id == 0:
                    division_count += 1
            division_count /= 2
            logger.info("Number of divisions in the csv file: {}".format(division_count))
            assert (
                division_count == self.EXPECTED_NUM_DIVISIONS
            ), "Number of divisions {} in the csv file differs from expected {}.".format(
                division_count, self.EXPECTED_NUM_DIVISIONS
            )
예제 #50
0
 def test_argsort_warning(self, masked, scale):
     if scale == 'utc':
         pytest.xfail()
     with warnings.catch_warnings(record=True) as wlist:
         Time([1, 2, 3], format='jd', scale=scale).argsort()
     assert len(wlist) == 0
예제 #51
0
 def test_eth_modifyTransaction(self, web3, unlocked_account):
     pytest.xfail('Needs ability to efficiently control mining')
     super().test_eth_modifyTransaction(web3, unlocked_account)
예제 #52
0
def test_render_sprites_overlap(device, show_plots):
    if device == "gpu" and visible_gpu():
        pytest.xfail("no gpu is visible")
    run(device, show_plots)
예제 #53
0
def test_J3_propagation_Earth(test_params):
    # Nai-ming Qi, Qilong Sun, Yong Yang, (2018) "Effect of J3 perturbation on satellite position in LEO",
    # Aircraft Engineering and  Aerospace Technology, Vol. 90 Issue: 1,
    # pp.74-86, https://doi.org/10.1108/AEAT-03-2015-0092
    a_ini = 8970.667 * u.km
    ecc_ini = 0.25 * u.one
    raan_ini = 1.047 * u.rad
    nu_ini = 0.0 * u.rad
    argp_ini = 1.0 * u.rad
    inc_ini = test_params["inc"]

    k = Earth.k.to(u.km**3 / u.s**2).value

    orbit = Orbit.from_classical(
        attractor=Earth,
        a=a_ini,
        ecc=ecc_ini,
        inc=inc_ini,
        raan=raan_ini,
        argp=argp_ini,
        nu=nu_ini,
    )

    def f(t0, u_, k):
        du_kep = func_twobody(t0, u_, k)
        ax, ay, az = J2_perturbation(t0,
                                     u_,
                                     k,
                                     J2=Earth.J2.value,
                                     R=Earth.R.to(u.km).value)
        du_ad = np.array([0, 0, 0, ax, ay, az])
        return du_kep + du_ad

    tofs = np.linspace(0, 10.0 * u.day, 1000)
    r_J2, v_J2 = cowell(
        Earth.k,
        orbit.r,
        orbit.v,
        tofs,
        rtol=1e-8,
        f=f,
    )

    def f_combined(t0, u_, k):
        du_kep = func_twobody(t0, u_, k)
        ax, ay, az = J2_perturbation(
            t0, u_, k, J2=Earth.J2.value, R=Earth.R.to_value(
                u.km)) + J3_perturbation(
                    t0, u_, k, J3=Earth.J3.value, R=Earth.R.to_value(u.km))
        du_ad = np.array([0, 0, 0, ax, ay, az])
        return du_kep + du_ad

    r_J3, v_J3 = cowell(Earth.k,
                        orbit.r,
                        orbit.v,
                        tofs,
                        rtol=1e-8,
                        f=f_combined)

    a_values_J2 = np.array([
        rv2coe(k, ri, vi)[0] / (1.0 - rv2coe(k, ri, vi)[1]**2)
        for ri, vi in zip(r_J2.to(u.km).value,
                          v_J2.to(u.km / u.s).value)
    ])
    a_values_J3 = np.array([
        rv2coe(k, ri, vi)[0] / (1.0 - rv2coe(k, ri, vi)[1]**2)
        for ri, vi in zip(r_J3.to(u.km).value,
                          v_J3.to(u.km / u.s).value)
    ])
    da_max = np.max(np.abs(a_values_J2 - a_values_J3))

    ecc_values_J2 = np.array([
        rv2coe(k, ri, vi)[1]
        for ri, vi in zip(r_J2.to(u.km).value,
                          v_J2.to(u.km / u.s).value)
    ])
    ecc_values_J3 = np.array([
        rv2coe(k, ri, vi)[1]
        for ri, vi in zip(r_J3.to(u.km).value,
                          v_J3.to(u.km / u.s).value)
    ])
    decc_max = np.max(np.abs(ecc_values_J2 - ecc_values_J3))

    inc_values_J2 = np.array([
        rv2coe(k, ri, vi)[2]
        for ri, vi in zip(r_J2.to(u.km).value,
                          v_J2.to(u.km / u.s).value)
    ])
    inc_values_J3 = np.array([
        rv2coe(k, ri, vi)[2]
        for ri, vi in zip(r_J3.to(u.km).value,
                          v_J3.to(u.km / u.s).value)
    ])
    dinc_max = np.max(np.abs(inc_values_J2 - inc_values_J3))

    assert_quantity_allclose(dinc_max,
                             test_params["dinc_max"],
                             rtol=1e-1,
                             atol=1e-7)
    assert_quantity_allclose(decc_max,
                             test_params["decc_max"],
                             rtol=1e-1,
                             atol=1e-7)
    try:
        assert_quantity_allclose(da_max * u.km, test_params["da_max"])
    except AssertionError:
        pytest.xfail("this assertion disagrees with the paper")
예제 #54
0
 def test_eth_estimateGas_with_block(self, web3,
                                     unlocked_account_dual_type):
     pytest.xfail('Block identifier has not been implemented in geth')
     super().test_eth_estimateGas_with_block(web3,
                                             unlocked_account_dual_type)
예제 #55
0
def bash(request) -> pexpect.spawn:

    logfile = None
    if os.environ.get("BASHCOMP_TEST_LOGFILE"):
        logfile = open(os.environ["BASHCOMP_TEST_LOGFILE"], "w")
    testdir = os.path.abspath(
        os.path.join(os.path.dirname(__file__), os.pardir))
    env = os.environ.copy()
    env.update(
        dict(
            SRCDIR=testdir,  # TODO needed at least by bashrc
            SRCDIRABS=testdir,  # TODO needed?
            PS1=PS1,
            INPUTRC="%s/config/inputrc" % testdir,
            TERM="dumb",
            LC_COLLATE="C",  # to match Python's default locale unaware sort
        ))

    fixturesdir = os.path.join(testdir, "fixtures")
    os.chdir(fixturesdir)

    # Start bash
    bash = pexpect.spawn(
        "%s --norc" % os.environ.get("BASHCOMP_TEST_BASH", "bash"),
        maxread=os.environ.get("BASHCOMP_TEST_PEXPECT_MAXREAD", 20000),
        logfile=logfile,
        cwd=fixturesdir,
        env=env,
        encoding="utf-8",  # TODO? or native or...?
        # FIXME: Tests shouldn't depend on dimensions, but it's difficult to
        # expect robustly enough for Bash to wrap lines anywhere (e.g. inside
        # MAGIC_MARK).  Increase window width to reduce wrapping.
        dimensions=(24, 160),
        # TODO? codec_errors="replace",
    )
    bash.expect_exact(PS1)

    # Load bashrc and bash_completion
    assert_bash_exec(bash, "source '%s/config/bashrc'" % testdir)
    assert_bash_exec(bash, "source '%s/../bash_completion'" % testdir)

    # Use command name from marker if set, or grab from test filename
    cmd = None  # type: Optional[str]
    cmd_found = False
    marker = request.node.get_closest_marker("bashcomp")
    if marker:
        cmd = marker.kwargs.get("cmd")
        cmd_found = "cmd" in marker.kwargs
        # Run pre-test commands, early so they're usable in skipif
        for pre_cmd in marker.kwargs.get("pre_cmds", []):
            assert_bash_exec(bash, pre_cmd)
        # Process skip and xfail conditions
        skipif = marker.kwargs.get("skipif")
        if skipif:
            try:
                assert_bash_exec(bash, skipif)
            except AssertionError:
                pass
            else:
                bash.close()
                pytest.skip(skipif)
        xfail = marker.kwargs.get("xfail")
        if xfail:
            try:
                assert_bash_exec(bash, xfail)
            except AssertionError:
                pass
            else:
                pytest.xfail(xfail)
    if not cmd_found:
        match = re.search(r"^test_(.+)\.py$",
                          os.path.basename(str(request.fspath)))
        if match:
            cmd = match.group(1)

    request.cls.cmd = cmd

    if (cmd_found and cmd is None) or is_testable(bash, cmd):
        before_env = get_env(bash)
        yield bash
        # Not exactly sure why, but some errors leave bash in state where
        # getting the env here would fail and trash our test output. So
        # reset to a good state first (Ctrl+C, expect prompt).
        bash.sendintr()
        bash.expect_exact(PS1)
        diff_env(
            before_env,
            get_env(bash),
            marker.kwargs.get("ignore_env") if marker else "",
        )

    if marker:
        for post_cmd in marker.kwargs.get("post_cmds", []):
            assert_bash_exec(bash, post_cmd)

    # Clean up
    bash.close()
    if logfile:
        logfile.close()
예제 #56
0
 def test_tell_active_method(self, tmp_path, port):
     with Aria2Server(tmp_path, port, session="big-download.txt") as server:
         time.sleep(0.1)
         if server.api.get_download("0000000000000001").has_failed:
             pytest.xfail("Failed to establish connection (sporadic error)")
         assert len(server.client.tell_active(keys=["gid"])) > 0
예제 #57
0
def test_timedelta_index_repr(index, expected_repr):
    if not PANDAS_GE_110:
        pytest.xfail(reason="pandas >= 1.1 requried")
    actual_repr = index.__repr__()

    assert actual_repr.split() == expected_repr.split()
예제 #58
0
def assert_complete(bash: pexpect.spawn, cmd: str,
                    **kwargs) -> CompletionResult:
    skipif = kwargs.get("skipif")
    if skipif:
        try:
            assert_bash_exec(bash, skipif)
        except AssertionError:
            pass
        else:
            pytest.skip(skipif)
    xfail = kwargs.get("xfail")
    if xfail:
        try:
            assert_bash_exec(bash, xfail)
        except AssertionError:
            pass
        else:
            pytest.xfail(xfail)
    cwd = kwargs.get("cwd")
    if cwd:
        assert_bash_exec(bash, "cd '%s'" % cwd)
    env_prefix = "_BASHCOMP_TEST_"
    env = kwargs.get("env", {})
    if env:
        # Back up environment and apply new one
        assert_bash_exec(
            bash,
            " ".join('%s%s="$%s"' % (env_prefix, k, k) for k in env.keys()),
        )
        assert_bash_exec(
            bash,
            "export %s" % " ".join("%s=%s" % (k, v) for k, v in env.items()),
        )
    bash.send(cmd + "\t")
    bash.expect_exact(cmd)
    bash.send(MAGIC_MARK)
    got = bash.expect([
        # 0: multiple lines, result in .before
        r"\r\n" + re.escape(PS1 + cmd) + ".*" + MAGIC_MARK,
        # 1: no completion
        r"^" + MAGIC_MARK,
        # 2: on same line, result in .match
        r"^([^\r]+)%s$" % MAGIC_MARK,
        pexpect.EOF,
        pexpect.TIMEOUT,
    ])
    if got == 0:
        output = bash.before
        if output.endswith(MAGIC_MARK):
            output = bash.before[:-len(MAGIC_MARK)]
        result = CompletionResult(output)
    elif got == 2:
        output = bash.match.group(1)
        result = CompletionResult(output, [shlex.split(cmd + output)[-1]])
    else:
        # TODO: warn about EOF/TIMEOUT?
        result = CompletionResult("", [])
    bash.sendintr()
    bash.expect_exact(PS1)
    if env:
        # Restore environment, and clean up backup
        # TODO: Test with declare -p if a var was set, backup only if yes, and
        #       similarly restore only backed up vars. Should remove some need
        #       for ignore_env.
        assert_bash_exec(
            bash,
            "export %s" % " ".join('%s="$%s%s"' % (k, env_prefix, k)
                                   for k in env.keys()),
        )
        assert_bash_exec(
            bash,
            "unset -v %s" % " ".join("%s%s" % (env_prefix, k)
                                     for k in env.keys()),
        )
    if cwd:
        assert_bash_exec(bash, "cd - >/dev/null")
    return result
예제 #59
0
 def test_svd_LM_zeros_matrix(self):
     message = ("PROPACK does not return orthonormal singular vectors "
                "associated with zero singular values.")
     pytest.xfail(message)
예제 #60
0
def browser(appliance):
    from cfme.utils.appliance import DummyAppliance
    if isinstance(appliance, DummyAppliance):
        pytest.xfail("browser not supported with DummyAppliance")
    return browser_module.browser