Python pytest.deprecated_call() Examples

The following are 30 code examples for showing how to use pytest.deprecated_call(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module pytest , or try the search function .

Example 1
Project: OpenFermion-Cirq   Author: quantumlib   File: _compat_test.py    License: Apache License 2.0 6 votes vote down vote up
def deprecated_test(test: Callable) -> Callable:
    """Marks a test as using deprecated functionality.

    Ensures the test is executed within the `pytest.deprecated_call()` context.

    Args:
        test: The test.

    Returns:
        The decorated test.
    """

    @functools.wraps(test)
    def decorated_test(*args, **kwargs) -> Any:
        with pytest.deprecated_call():
            test(*args, **kwargs)

    return decorated_test 
Example 2
Project: python-firestore   Author: googleapis   File: test_cross_language.py    License: Apache License 2.0 6 votes vote down vote up
def _make_client_document(firestore_api, testcase):
    from google.cloud.firestore_v1beta1 import Client
    from google.cloud.firestore_v1beta1.client import DEFAULT_DATABASE
    import google.auth.credentials

    _, project, _, database, _, doc_path = testcase.doc_ref_path.split("/", 5)
    assert database == DEFAULT_DATABASE

    # Attach the fake GAPIC to a real client.
    credentials = mock.Mock(spec=google.auth.credentials.Credentials)

    with pytest.deprecated_call():
        client = Client(project=project, credentials=credentials)

    client._firestore_api_internal = firestore_api
    return client, client.document(doc_path) 
Example 3
Project: python-firestore   Author: googleapis   File: test_client.py    License: Apache License 2.0 6 votes vote down vote up
def test___database_string_property(self):
        credentials = _make_credentials()
        database = "cheeeeez"

        with pytest.deprecated_call():
            client = self._make_one(
                project=self.PROJECT, credentials=credentials, database=database
            )

        self.assertIsNone(client._database_string_internal)
        database_string = client._database_string
        expected = "projects/{}/databases/{}".format(client.project, client._database)
        self.assertEqual(database_string, expected)
        self.assertIs(database_string, client._database_string_internal)

        # Swap it out with a unique value to verify it is cached.
        client._database_string_internal = mock.sentinel.cached
        self.assertIs(client._database_string, mock.sentinel.cached) 
Example 4
Project: python-firestore   Author: googleapis   File: test_client.py    License: Apache License 2.0 6 votes vote down vote up
def test_collection_factory_nested(self):
        from google.cloud.firestore_v1beta1.collection import CollectionReference

        with pytest.deprecated_call():
            client = self._make_default_one()

        parts = ("users", "alovelace", "beep")
        collection_path = "/".join(parts)
        collection1 = client.collection(collection_path)

        self.assertEqual(collection1._path, parts)
        self.assertIs(collection1._client, client)
        self.assertIsInstance(collection1, CollectionReference)

        # Make sure using segments gives the same result.
        collection2 = client.collection(*parts)
        self.assertEqual(collection2._path, parts)
        self.assertIs(collection2._client, client)
        self.assertIsInstance(collection2, CollectionReference) 
Example 5
Project: python-firestore   Author: googleapis   File: test_client.py    License: Apache License 2.0 6 votes vote down vote up
def test_document_factory(self):
        from google.cloud.firestore_v1beta1.document import DocumentReference

        parts = ("rooms", "roomA")

        with pytest.deprecated_call():
            client = self._make_default_one()

        doc_path = "/".join(parts)
        document1 = client.document(doc_path)

        self.assertEqual(document1._path, parts)
        self.assertIs(document1._client, client)
        self.assertIsInstance(document1, DocumentReference)

        # Make sure using segments gives the same result.
        document2 = client.document(*parts)
        self.assertEqual(document2._path, parts)
        self.assertIs(document2._client, client)
        self.assertIsInstance(document2, DocumentReference) 
Example 6
Project: python-firestore   Author: googleapis   File: test_client.py    License: Apache License 2.0 6 votes vote down vote up
def test_document_factory_nested(self):
        from google.cloud.firestore_v1beta1.document import DocumentReference

        with pytest.deprecated_call():
            client = self._make_default_one()

        parts = ("rooms", "roomA", "shoes", "dressy")
        doc_path = "/".join(parts)
        document1 = client.document(doc_path)

        self.assertEqual(document1._path, parts)
        self.assertIs(document1._client, client)
        self.assertIsInstance(document1, DocumentReference)

        # Make sure using segments gives the same result.
        document2 = client.document(*parts)
        self.assertEqual(document2._path, parts)
        self.assertIs(document2._client, client)
        self.assertIsInstance(document2, DocumentReference) 
Example 7
Project: signac   Author: glotzerlab   File: test_shell.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_index(self):
        self.call('python -m signac init my_project'.split())
        self.call('python -m signac project --access'.split())
        project = signac.Project()
        project.open_job({'a': 0}).init()
        assert len(project) == 1
        with pytest.deprecated_call():
            assert len(list(project.index())) == 1
            assert len(list(signac.index())) == 1
        doc = json.loads(self.call('python -m signac index'.split()))
        assert 'statepoint' in doc
        assert doc['statepoint'] == {'a': 0}
        doc = json.loads(self.call('python -m signac project --index'.split()))
        assert 'statepoint' in doc
        assert doc['statepoint'] == {'a': 0}
        project.open_job({'a': 0}).document['b'] = 0
        doc = json.loads(self.call('python -m signac index'.split()))
        assert 'statepoint' in doc
        assert doc['statepoint'] == {'a': 0}
        assert 'b' in doc
        assert doc['b'] == 0 
Example 8
Project: signac   Author: glotzerlab   File: test_indexing.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_regex_file_crawler_pre_compiled(self):
        self.setup_project()

        class Crawler(indexing.RegexFileCrawler):
            pass

        regex = re.compile(r".*a_(?P<a>\d)\.txt")
        with pytest.deprecated_call():
            Crawler.define(regex, TestFormat)
        crawler = Crawler(root=self._tmp_dir.name)
        no_find = True
        with pytest.deprecated_call():
            for doc in crawler.crawl():
                no_find = False
                ffn = os.path.join(doc['root'], doc['filename'])
                m = regex.match(ffn)
                assert m is not None
                assert os.path.isfile(ffn)
                with open(ffn) as file:
                    doc2 = json.load(file)
                    assert doc2['a'] == doc['a']
        assert not no_find 
Example 9
Project: signac   Author: glotzerlab   File: test_indexing.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_master_crawler(self):
        self.setup_project()
        crawler = indexing.MasterCrawler(root=self._tmp_dir.name)
        crawler.tags = {'test1'}
        no_find = True
        with pytest.deprecated_call():
            for doc in crawler.crawl():
                no_find = False
                ffn = os.path.join(doc['root'], doc['filename'])
                assert os.path.isfile(ffn)
                with open(ffn) as file:
                    doc2 = json.load(file)
                    assert doc2['a'] == doc['a']
                with signac.fetch(doc) as file:
                    pass
        assert not no_find 
Example 10
Project: signac   Author: glotzerlab   File: test_indexing.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_index(self):
        self.setup_project()
        root = self._tmp_dir.name
        with pytest.deprecated_call():
            assert len(list(signac.index(root=root))) == 0
            index = signac.index(root=self._tmp_dir.name, tags={'test1'})
        no_find = True
        for doc in index:
            no_find = False
            ffn = os.path.join(doc['root'], doc['filename'])
            assert os.path.isfile(ffn)
            with open(ffn) as file:
                doc2 = json.load(file)
                assert doc2['a'] == doc['a']
            with pytest.deprecated_call():
                with signac.fetch(doc) as file:
                    pass
        assert not no_find 
Example 11
Project: signac   Author: glotzerlab   File: test_indexing.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_fetch(self):
        with pytest.deprecated_call():
            with pytest.raises(ValueError):
                signac.fetch(None)
            with pytest.raises(errors.FetchError):
                signac.fetch(dict())
        self.setup_project()
        crawler = indexing.MasterCrawler(root=self._tmp_dir.name)
        crawler.tags = {'test1'}
        with pytest.deprecated_call():
            docs = list(crawler.crawl())
        assert len(docs) == 2
        for doc in docs:
            with pytest.deprecated_call():
                with signac.fetch(doc) as file:
                    pass
        with pytest.deprecated_call():
            for doc, file in indexing.fetched(docs):
                doc2 = json.load(file)
                assert doc['a'] == doc2['a']
                file.close() 
Example 12
Project: signac   Author: glotzerlab   File: test_indexing.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_export_to_mirror(self):
        self.setup_project()
        crawler = indexing.MasterCrawler(root=self._tmp_dir.name)
        crawler.tags = {'test1'}
        index = self.get_index_collection()
        mirror = _TestFS()
        with pytest.deprecated_call():
            for doc in crawler.crawl():
                assert 'file_id' in doc
                doc.pop('file_id')
                with pytest.raises(errors.ExportError):
                    signac.export_to_mirror(doc, mirror)
                break
            for doc in crawler.crawl():
                assert 'file_id' in doc
                signac.export_one(doc, index)

                signac.export_to_mirror(doc, mirror)
            assert index.replace_one.called
            for doc in crawler.crawl():
                assert index.find_one({'_id': doc['_id']}) is not None
                with mirror.get(doc['file_id']):
                    pass 
Example 13
Project: signac   Author: glotzerlab   File: test_indexing.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_master_crawler_tags(self):
        self.setup_project()
        crawler = indexing.MasterCrawler(root=self._tmp_dir.name)
        with pytest.deprecated_call():
            assert 0 == len(list(crawler.crawl()))
            crawler.tags = None
            assert 0 == len(list(crawler.crawl()))
            crawler.tags = {}
            assert 0 == len(list(crawler.crawl()))
            crawler.tags = {'nomatch'}
            assert 0 == len(list(crawler.crawl()))
            crawler.tags = {'test1'}
            assert 2 == len(list(crawler.crawl()))
            crawler.tags = {'test2'}
            assert 2 == len(list(crawler.crawl()))
            crawler.tags = {'test1', 'test2'}
            assert 2 == len(list(crawler.crawl()))
            crawler.tags = {'test1', 'non-existent-key'}
            assert 2 == len(list(crawler.crawl()))
            crawler.tags = {'test2', 'non-existent-key'}
            assert 2 == len(list(crawler.crawl()))
            crawler.tags = {'test1', 'test2', 'non-existent-key'}
            assert 2 == len(list(crawler.crawl())) 
Example 14
Project: signac   Author: glotzerlab   File: test_project.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_export_custom_path_function(self):
        prefix_data = os.path.join(self._tmp_dir.name, 'data')
        for i in range(10):
            self.project.open_job(dict(a=i)).init()
        with pytest.deprecated_call():
            ids_before_export = list(sorted(self.project.find_job_ids()))

        with pytest.raises(RuntimeError):
            self.project.export_to(target=prefix_data, path=lambda job: 'non_unique')

        self.project.export_to(
            target=prefix_data, path=lambda job: os.path.join('my_a', str(job.sp.a)))

        assert len(self.project) == 10
        assert len(os.listdir(prefix_data)) == 1
        assert len(os.listdir(os.path.join(prefix_data, 'my_a'))) == 10
        for i in range(10):
            assert os.path.isdir(os.path.join(prefix_data, 'my_a', str(i)))
        with pytest.deprecated_call():
            assert ids_before_export == list(sorted(self.project.find_job_ids())) 
Example 15
Project: signac   Author: glotzerlab   File: test_project.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_export_import_tarfile(self):
        target = os.path.join(self._tmp_dir.name, 'data.tar')
        for i in range(10):
            self.project.open_job(dict(a=i)).init()
        with pytest.deprecated_call():
            ids_before_export = list(sorted(self.project.find_job_ids()))
        self.project.export_to(target=target)
        assert len(self.project) == 10
        with TarFile(name=target) as tarfile:
            for i in range(10):
                assert 'a/{}'.format(i) in tarfile.getnames()
        os.replace(self.project.workspace(), self.project.workspace() + '~')
        assert len(self.project) == 0
        self.project.import_from(origin=target)
        assert len(self.project) == 10
        with pytest.deprecated_call():
            assert ids_before_export == list(sorted(self.project.find_job_ids())) 
Example 16
Project: signac   Author: glotzerlab   File: test_project.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_export_import_tarfile_zipped(self):
        target = os.path.join(self._tmp_dir.name, 'data.tar.gz')
        for i in range(10):
            with self.project.open_job(dict(a=i)) as job:
                os.makedirs(job.fn('sub-dir'))
                with open(job.fn(os.path.join('sub-dir', 'signac_statepoint.json')), 'w') as file:
                    file.write(json.dumps({"foo": 0}))
        with pytest.deprecated_call():
            ids_before_export = list(sorted(self.project.find_job_ids()))
        self.project.export_to(target=target)
        assert len(self.project) == 10
        with TarFile.open(name=target, mode='r:gz') as tarfile:
            for i in range(10):
                assert 'a/{}'.format(i) in tarfile.getnames()
                assert 'a/{}/sub-dir/signac_statepoint.json'.format(i) in tarfile.getnames()
        os.replace(self.project.workspace(), self.project.workspace() + '~')
        assert len(self.project) == 0
        self.project.import_from(origin=target)
        assert len(self.project) == 10
        with pytest.deprecated_call():
            assert ids_before_export == list(sorted(self.project.find_job_ids()))
        for job in self.project:
            assert job.isfile(os.path.join('sub-dir', 'signac_statepoint.json')) 
Example 17
Project: signac   Author: glotzerlab   File: test_project.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_export_import_zipfile(self):
        target = os.path.join(self._tmp_dir.name, 'data.zip')
        for i in range(10):
            with self.project.open_job(dict(a=i)) as job:
                os.makedirs(job.fn('sub-dir'))
                with open(job.fn(os.path.join('sub-dir', 'signac_statepoint.json')), 'w') as file:
                    file.write(json.dumps({"foo": 0}))
        with pytest.deprecated_call():
            ids_before_export = list(sorted(self.project.find_job_ids()))
        self.project.export_to(target=target)
        assert len(self.project) == 10
        with ZipFile(target) as zipfile:
            for i in range(10):
                assert 'a/{}/signac_statepoint.json'.format(i) in zipfile.namelist()
                assert 'a/{}/sub-dir/signac_statepoint.json'.format(i) in zipfile.namelist()
        os.replace(self.project.workspace(), self.project.workspace() + '~')
        assert len(self.project) == 0
        self.project.import_from(origin=target)
        assert len(self.project) == 10
        with pytest.deprecated_call():
            assert ids_before_export == list(sorted(self.project.find_job_ids()))
        for job in self.project:
            assert job.isfile(os.path.join('sub-dir', 'signac_statepoint.json')) 
Example 18
Project: signac   Author: glotzerlab   File: test_project.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_export_import_conflict_synced(self):
        prefix_data = os.path.join(self._tmp_dir.name, 'data')
        for i in range(10):
            self.project.open_job(dict(a=i)).init()
        with pytest.deprecated_call():
            ids_before_export = list(sorted(self.project.find_job_ids()))
        self.project.export_to(target=prefix_data)
        with pytest.raises(DestinationExistsError):
            assert len(self.project.import_from(prefix_data)) == 10
        with self.project.temporary_project() as tmp_project:
            assert len(tmp_project.import_from(prefix_data)) == 10
            assert len(tmp_project) == 10
            self.project.sync(tmp_project)
        with pytest.deprecated_call():
            assert ids_before_export == list(sorted(self.project.find_job_ids()))
        assert len(self.project.import_from(prefix_data, sync=True)) == 10
        with pytest.deprecated_call():
            assert ids_before_export == list(sorted(self.project.find_job_ids())) 
Example 19
Project: signac   Author: glotzerlab   File: test_project.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_export_import_conflict_synced_with_args(self):
        prefix_data = os.path.join(self._tmp_dir.name, 'data')
        for i in range(10):
            self.project.open_job(dict(a=i)).init()
        with pytest.deprecated_call():
            ids_before_export = list(sorted(self.project.find_job_ids()))
        self.project.export_to(target=prefix_data)
        with pytest.raises(DestinationExistsError):
            assert len(self.project.import_from(prefix_data)) == 10

        selection = list(self.project.find_jobs(dict(a=0)))
        os.replace(self.project.workspace(), self.project.workspace() + '~')
        assert len(self.project) == 0
        assert len(self.project.import_from(prefix_data,
                                            sync=dict(selection=selection))) == 10
        assert len(self.project) == 1
        assert len(self.project.find_jobs(dict(a=0))) == 1
        with pytest.deprecated_call():
            assert list(self.project.find_job_ids())[0] in ids_before_export 
Example 20
Project: signac   Author: glotzerlab   File: test_project.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_export_import_schema_callable(self):

        def my_schema(path):
            re_sep = re.escape(os.path.sep)
            m = re.match(r'.*' + re_sep + 'a' + re_sep + r'(?P<a>\d+)$', path)
            if m:
                return dict(a=int(m.groupdict()['a']))

        prefix_data = os.path.join(self._tmp_dir.name, 'data')
        for i in range(10):
            self.project.open_job(dict(a=i)).init()
        with pytest.deprecated_call():
            ids_before_export = list(sorted(self.project.find_job_ids()))
        self.project.export_to(target=prefix_data, copytree=os.replace)
        assert len(self.project.import_from(prefix_data, schema=my_schema)) == 10
        with pytest.deprecated_call():
            assert ids_before_export == list(sorted(self.project.find_job_ids())) 
Example 21
Project: signac   Author: glotzerlab   File: test_project.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_export_import_simple_path(self):
        prefix_data = os.path.join(self._tmp_dir.name, 'data')
        for i in range(10):
            self.project.open_job(dict(a=i)).init()
        with pytest.deprecated_call():
            ids_before_export = list(sorted(self.project.find_job_ids()))
        self.project.export_to(target=prefix_data, copytree=os.replace)
        assert len(self.project) == 0
        assert len(os.listdir(prefix_data)) == 1
        assert len(os.listdir(os.path.join(prefix_data, 'a'))) == 10
        for i in range(10):
            assert os.path.isdir(os.path.join(prefix_data, 'a', str(i)))
        with pytest.raises(StatepointParsingError):
            self.project.import_from(origin=prefix_data, schema='a/{b:int}')
        assert len(self.project.import_from(prefix_data)) == 10
        assert len(self.project) == 10
        with pytest.deprecated_call():
            assert ids_before_export == list(sorted(self.project.find_job_ids())) 
Example 22
Project: signac   Author: glotzerlab   File: test_project.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_export_import_simple_path_with_float(self):
        prefix_data = os.path.join(self._tmp_dir.name, 'data')
        for i in range(10):
            self.project.open_job(dict(a=float(i))).init()
        with pytest.deprecated_call():
            ids_before_export = list(sorted(self.project.find_job_ids()))
        self.project.export_to(target=prefix_data, copytree=os.replace)
        assert len(self.project) == 0
        assert len(os.listdir(prefix_data)) == 1
        assert len(os.listdir(os.path.join(prefix_data, 'a'))) == 10
        for i in range(10):
            assert os.path.isdir(os.path.join(prefix_data, 'a', str(float(i))))
        assert len(self.project.import_from(prefix_data)) == 10
        assert len(self.project) == 10
        with pytest.deprecated_call():
            assert ids_before_export == list(sorted(self.project.find_job_ids())) 
Example 23
Project: signac   Author: glotzerlab   File: test_project.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_export_import_complex_path(self):
        prefix_data = os.path.join(self._tmp_dir.name, 'data')
        sp_0 = [{'a': i, 'b': i % 3} for i in range(5)]
        sp_1 = [{'a': i, 'b': i % 3, 'c': {'a': i, 'b': 0}} for i in range(5)]
        sp_2 = [{'a': i, 'b': i % 3, 'c': {'a': i, 'b': 0, 'c': {'a': i, 'b': 0}}}
                for i in range(5)]
        statepoints = sp_0 + sp_1 + sp_2
        for sp in statepoints:
            self.project.open_job(sp).init()
        with pytest.deprecated_call():
            ids_before_export = list(sorted(self.project.find_job_ids()))
        self.project.export_to(target=prefix_data, copytree=os.replace)
        assert len(self.project) == 0
        self.project.import_from(prefix_data)
        assert len(self.project) == len(statepoints)
        with pytest.deprecated_call():
            assert ids_before_export == list(sorted(self.project.find_job_ids())) 
Example 24
Project: signac   Author: glotzerlab   File: test_project.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_export_import_simple_path_schema_from_path(self):
        prefix_data = os.path.join(self._tmp_dir.name, 'data')
        for i in range(10):
            self.project.open_job(dict(a=i)).init()
        with pytest.deprecated_call():
            ids_before_export = list(sorted(self.project.find_job_ids()))
        self.project.export_to(target=prefix_data, copytree=os.replace)
        assert len(self.project) == 0
        assert len(os.listdir(prefix_data)) == 1
        assert len(os.listdir(os.path.join(prefix_data, 'a'))) == 10
        for i in range(10):
            assert os.path.isdir(os.path.join(prefix_data, 'a', str(i)))
        ret = self.project.import_from(origin=prefix_data, schema='a/{a:int}')
        assert len(ret) == 10
        with pytest.deprecated_call():
            assert ids_before_export == list(sorted(self.project.find_job_ids())) 
Example 25
Project: signac   Author: glotzerlab   File: test_project.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_export_import_simple_path_schema_from_path_float(self):
        prefix_data = os.path.join(self._tmp_dir.name, 'data')
        for i in range(10):
            self.project.open_job(dict(a=float(i))).init()
        with pytest.deprecated_call():
            ids_before_export = list(sorted(self.project.find_job_ids()))
        self.project.export_to(target=prefix_data, copytree=os.replace)
        assert len(self.project) == 0
        assert len(os.listdir(prefix_data)) == 1
        assert len(os.listdir(os.path.join(prefix_data, 'a'))) == 10
        for i in range(10):
            assert os.path.isdir(os.path.join(prefix_data, 'a', str(float(i))))
        ret = self.project.import_from(origin=prefix_data, schema='a/{a:int}')
        assert len(ret) == 0  # should not match
        ret = self.project.import_from(origin=prefix_data, schema='a/{a:float}')
        assert len(ret) == 10
        with pytest.deprecated_call():
            assert ids_before_export == list(sorted(self.project.find_job_ids())) 
Example 26
Project: signac   Author: glotzerlab   File: test_job.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_reset_statepoint_project(self):
        key = 'move_job'
        d = testdata()
        src = test_token
        dst = dict(test_token)
        dst['dst'] = True
        src_job = self.open_job(src)
        with self.open_data(src_job):
            src_job.data[key] = d
            assert key in src_job.data
            assert len(src_job.data) == 1
        with pytest.deprecated_call():
            self.project.reset_statepoint(src_job, dst)
        src_job = self.open_job(src)
        dst_job = self.open_job(dst)
        with self.open_data(dst_job):
            assert key in dst_job.data
            assert len(dst_job.data) == 1
        with self.open_data(src_job):
            assert key not in src_job.data
        with pytest.deprecated_call():
            with pytest.raises(RuntimeError):
                self.project.reset_statepoint(src_job, dst)
            with pytest.raises(DestinationExistsError):
                self.project.reset_statepoint(src_job, dst) 
Example 27
Project: OpenFermion-Cirq   Author: quantumlib   File: _compat_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_wrap_module():
    ofc.deprecated_attribute = None
    wrapped_ofc = wrap_module(ofc, {'deprecated_attribute': ('', '')})
    with pytest.deprecated_call():
        _ = wrapped_ofc.deprecated_attribute 
Example 28
Project: eth-account   Author: ethereum   File: test_accounts.py    License: MIT License 5 votes vote down vote up
def test_sign_message_against_sign_hash_as_text(keyed_acct, message_text):
    # sign via hash
    msg_hash = defunct_hash_message(text=message_text)
    with pytest.deprecated_call():
        signed_via_hash = keyed_acct.signHash(msg_hash)

    # sign via message
    signable_message = encode_defunct(text=message_text)
    signed_via_message = keyed_acct.sign_message(signable_message)
    assert signed_via_hash == signed_via_message 
Example 29
Project: eth-account   Author: ethereum   File: test_accounts.py    License: MIT License 5 votes vote down vote up
def test_sign_message_against_sign_hash_as_bytes(keyed_acct, message_bytes):
    # sign via hash
    msg_hash = defunct_hash_message(message_bytes)
    with pytest.deprecated_call():
        signed_via_hash = keyed_acct.signHash(msg_hash)

    # sign via message
    signable_message = encode_defunct(message_bytes)
    signed_via_message = keyed_acct.sign_message(signable_message)

    assert signed_via_hash == signed_via_message 
Example 30
Project: eth-account   Author: ethereum   File: test_accounts.py    License: MIT License 5 votes vote down vote up
def test_sign_message_against_sign_hash_as_hex(keyed_acct, message_bytes):
    message_hex = to_hex(message_bytes)

    # sign via hash
    msg_hash_hex = defunct_hash_message(hexstr=message_hex)
    with pytest.deprecated_call():
        signed_via_hash_hex = keyed_acct.signHash(msg_hash_hex)

    # sign via message
    signable_message_hex = encode_defunct(hexstr=message_hex)
    signed_via_message_hex = keyed_acct.sign_message(signable_message_hex)

    assert signed_via_hash_hex == signed_via_message_hex