Dataset Viewer
Auto-converted to Parquet Duplicate
prompt
listlengths
1
1
compression_prompt
listlengths
1
1
target
stringlengths
1.01k
1.02M
[ { "content": "Return the code unaltered:\n```python\n#\n# Licensed to the Apache Software Foundation (ASF) under one or more\n# contributor license agreements. See the NOTICE file distributed with\n# this work for additional information regarding copyright ownership.\n# The ASF licenses this file to You under the Apache License, Version 2.0\n# (the \"License\"); you may not use this file except in compliance with\n# the License. You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n\n\"\"\"Unit tests for the test pipeline verifiers\"\"\"\n\n# pytype: skip-file\n\nfrom __future__ import absolute_import\n\nimport logging\nimport os\nimport tempfile\nimport unittest\nfrom builtins import range\n\nfrom hamcrest import assert_that as hc_assert_that\nfrom mock import Mock\nfrom mock import patch\n\nfrom apache_beam.io.localfilesystem import LocalFileSystem\nfrom apache_beam.runners.runner import PipelineResult\nfrom apache_beam.runners.runner import PipelineState\nfrom apache_beam.testing import pipeline_verifiers as verifiers\nfrom apache_beam.testing.test_utils import patch_retry\n\ntry:\n # pylint: disable=wrong-import-order, wrong-import-position\n # pylint: disable=ungrouped-imports\n from apitools.base.py.exceptions import HttpError\n from apache_beam.io.gcp.gcsfilesystem import GCSFileSystem\nexcept ImportError:\n HttpError = None\n GCSFileSystem = None # type: ignore\n\n\nclass PipelineVerifiersTest(unittest.TestCase):\n def setUp(self):\n self._mock_result = Mock()\n patch_retry(self, verifiers)\n\n def test_pipeline_state_matcher_success(self):\n \"\"\"Test PipelineStateMatcher successes when using default expected state\n and job actually finished in DONE\n \"\"\"\n pipeline_result = PipelineResult(PipelineState.DONE)\n hc_assert_that(pipeline_result, verifiers.PipelineStateMatcher())\n\n def test_pipeline_state_matcher_given_state(self):\n \"\"\"Test PipelineStateMatcher successes when matches given state\"\"\"\n pipeline_result = PipelineResult(PipelineState.FAILED)\n hc_assert_that(\n pipeline_result, verifiers.PipelineStateMatcher(PipelineState.FAILED))\n\n def test_pipeline_state_matcher_fails(self):\n \"\"\"Test PipelineStateMatcher fails when using default expected state\n and job actually finished in CANCELLED/DRAINED/FAILED/UNKNOWN\n \"\"\"\n failed_state = [\n PipelineState.CANCELLED,\n PipelineState.DRAINED,\n PipelineState.FAILED,\n PipelineState.UNKNOWN\n ]\n\n for state in failed_state:\n pipeline_result = PipelineResult(state)\n with self.assertRaises(AssertionError):\n hc_assert_that(pipeline_result, verifiers.PipelineStateMatcher())\n\n test_cases = [\n {\n 'content': 'Test FileChecksumMatcher with single file',\n 'num_files': 1,\n 'expected_checksum': 'ebe16840cc1d0b4fe1cf71743e9d772fa31683b8'\n },\n {\n 'content': 'Test FileChecksumMatcher with multiple files',\n 'num_files': 3,\n 'expected_checksum': '58b3d3636de3891ac61afb8ace3b5025c3c37d44'\n },\n {\n 'content': '',\n 'num_files': 1,\n 'expected_checksum': 'da39a3ee5e6b4b0d3255bfef95601890afd80709'\n },\n ]\n\n def create_temp_file(self, content, directory=None):\n with tempfile.NamedTemporaryFile(delete=False, dir=directory) as f:\n f.write(content.encode('utf-8'))\n return f.name\n\n def test_file_checksum_matcher_success(self):\n for case in self.test_cases:\n temp_dir = tempfile.mkdtemp()\n for _ in range(case['num_files']):\n self.create_temp_file(case['content'], temp_dir)\n matcher = verifiers.FileChecksumMatcher(\n os.path.join(temp_dir, '*'), case['expected_checksum'])\n hc_assert_that(self._mock_result, matcher)\n\n @patch.object(LocalFileSystem, 'match')\n def test_file_checksum_matcher_read_failed(self, mock_match):\n mock_match.side_effect = IOError('No file found.')\n matcher = verifiers.FileChecksumMatcher(\n os.path.join('dummy', 'path'), Mock())\n with self.assertRaises(IOError):\n hc_assert_that(self._mock_result, matcher)\n self.assertTrue(mock_match.called)\n self.assertEqual(verifiers.MAX_RETRIES + 1, mock_match.call_count)\n\n @patch.object(GCSFileSystem, 'match')\n @unittest.skipIf(HttpError is None, 'google-apitools is not installed')\n def test_file_checksum_matcher_service_error(self, mock_match):\n mock_match.side_effect = HttpError(\n response={'status': '404'},\n url='',\n content='Not Found',\n )\n matcher = verifiers.FileChecksumMatcher('gs://dummy/path', Mock())\n with self.assertRaises(HttpError):\n hc_assert_that(self._mock_result, matcher)\n self.assertTrue(mock_match.called)\n self.assertEqual(verifiers.MAX_RETRIES + 1, mock_match.call_count)\n\n def test_file_checksum_matchcer_invalid_sleep_time(self):\n with self.assertRaises(ValueError) as cm:\n verifiers.FileChecksumMatcher(\n 'file_path', 'expected_checksum', 'invalid_sleep_time')\n self.assertEqual(\n cm.exception.args[0],\n 'Sleep seconds, if received, must be int. '\n 'But received: \\'invalid_sleep_time\\', '\n '{}'.format(str))\n\n @patch('time.sleep', return_value=None)\n def test_file_checksum_matcher_sleep_before_verify(self, mocked_sleep):\n temp_dir = tempfile.mkdtemp()\n case = self.test_cases[0]\n self.create_temp_file(case['content'], temp_dir)\n matcher = verifiers.FileChecksumMatcher(\n os.path.join(temp_dir, '*'), case['expected_checksum'], 10)\n hc_assert_that(self._mock_result, matcher)\n self.assertTrue(mocked_sleep.called)\n\n\nif __name__ == '__main__':\n logging.getLogger().setLevel(logging.INFO)\n unittest.main()\n```\nExact characters only.", "role": "user" } ]
[ { "content": "Return the code unaltered:\n<|memory_start|>```python\n#\n# Licensed to the Apache Software Foundation (ASF) under one or more\n# contributor license agreements. See the NOTICE file distributed with\n# this work for additional information regarding copyright ownership.\n# The ASF licenses this file to You under the Apache License, Version 2.0\n# (the \"License\"); you may not use this file except in compliance with\n# the License. You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n\n\"\"\"Unit tests for the test pipeline verifiers\"\"\"\n\n# pytype: skip-file\n\nfrom __future__ import absolute_import\n\nimport logging\nimport os\nimport tempfile\nimport unittest\nfrom builtins import range\n\nfrom hamcrest import assert_that as hc_assert_that\nfrom mock import Mock\nfrom mock import patch\n\nfrom apache_beam.io.localfilesystem import LocalFileSystem\nfrom apache_beam.runners.runner import PipelineResult\nfrom apache_beam.runners.runner import PipelineState\nfrom apache_beam.testing import pipeline_verifiers as verifiers\nfrom apache_beam.testing.test_utils import patch_retry\n\ntry:\n # pylint: disable=wrong-import-order, wrong-import-position\n # pylint: disable=ungrouped-imports\n from apitools.base.py.exceptions import HttpError\n from apache_beam.io.gcp.gcsfilesystem import GCSFileSystem\nexcept ImportError:\n HttpError = None\n GCSFileSystem = None # type: ignore\n\n\nclass PipelineVerifiersTest(unittest.TestCase):\n def setUp(self):\n self._mock_result = Mock()\n patch_retry(self, verifiers)\n\n def test_pipeline_state_matcher_success(self):\n \"\"\"Test PipelineStateMatcher successes when using default expected state\n and job actually finished in DONE\n \"\"\"\n pipeline_result = PipelineResult(PipelineState.DONE)\n hc_assert_that(pipeline_result, verifiers.PipelineStateMatcher())\n\n def test_pipeline_state_matcher_given_state(self):\n \"\"\"Test PipelineStateMatcher successes when matches given state\"\"\"\n pipeline_result = PipelineResult(PipelineState.FAILED)\n hc_assert_that(\n pipeline_result, verifiers.PipelineStateMatcher(PipelineState.FAILED))\n\n def test_pipeline_state_matcher_fails(self):\n \"\"\"Test PipelineStateMatcher fails when using default expected state\n and job actually finished in CANCELLED/DRAINED/FAILED/UNKNOWN\n \"\"\"\n failed_state = [\n PipelineState.CANCELLED,\n PipelineState.DRAINED,\n PipelineState.FAILED,\n PipelineState.UNKNOWN\n ]\n\n for state in failed_state:\n pipeline_result = PipelineResult(state)\n with self.assertRaises(AssertionError):\n hc_assert_that(pipeline_result, verifiers.PipelineStateMatcher())\n\n test_cases = [\n {\n 'content': 'Test FileChecksumMatcher with single file',\n 'num_files': 1,\n 'expected_checksum': 'ebe16840cc1d0b4fe1cf71743e9d772fa31683b8'\n },\n {\n 'content': 'Test FileChecksumMatcher with multiple files',\n 'num_files': 3,\n 'expected_checksum': '58b3d3636de3891ac61afb8ace3b5025c3c37d44'\n },\n {\n 'content': '',\n 'num_files': 1,\n 'expected_checksum': 'da39a3ee5e6b4b0d3255bfef95601890afd80709'\n },\n ]\n\n def create_temp_file(self, content, directory=None):\n with tempfile.NamedTemporaryFile(delete=False, dir=directory) as f:\n f.write(content.encode('utf-8'))\n return f.name\n\n def test_file_checksum_matcher_success(self):\n for case in self.test_cases:\n temp_dir = tempfile.mkdtemp()\n for _ in range(case['num_files']):\n self.create_temp_file(case['content'], temp_dir)\n matcher = verifiers.FileChecksumMatcher(\n os.path.join(temp_dir, '*'), case['expected_checksum'])\n hc_assert_that(self._mock_result, matcher)\n\n @patch.object(LocalFileSystem, 'match')\n def test_file_checksum_matcher_read_failed(self, mock_match):\n mock_match.side_effect = IOError('No file found.')\n matcher = verifiers.FileChecksumMatcher(\n os.path.join('dummy', 'path'), Mock())\n with self.assertRaises(IOError):\n hc_assert_that(self._mock_result, matcher)\n self.assertTrue(mock_match.called)\n self.assertEqual(verifiers.MAX_RETRIES + 1, mock_match.call_count)\n\n @patch.object(GCSFileSystem, 'match')\n @unittest.skipIf(HttpError is None, 'google-apitools is not installed')\n def test_file_checksum_matcher_service_error(self, mock_match):\n mock_match.side_effect = HttpError(\n response={'status': '404'},\n url='',\n content='Not Found',\n )\n matcher = verifiers.FileChecksumMatcher('gs://dummy/path', Mock())\n with self.assertRaises(HttpError):\n hc_assert_that(self._mock_result, matcher)\n self.assertTrue(mock_match.called)\n self.assertEqual(verifiers.MAX_RETRIES + 1, mock_match.call_count)\n\n def test_file_checksum_matchcer_invalid_sleep_time(self):\n with self.assertRaises(ValueError) as cm:\n verifiers.FileChecksumMatcher(\n 'file_path', 'expected_checksum', 'invalid_sleep_time')\n self.assertEqual(\n cm.exception.args[0],\n 'Sleep seconds, if received, must be int. '\n 'But received: \\'invalid_sleep_time\\', '\n '{}'.format(str))\n\n @patch('time.sleep', return_value=None)\n def test_file_checksum_matcher_sleep_before_verify(self, mocked_sleep):\n temp_dir = tempfile.mkdtemp()\n case = self.test_cases[0]\n self.create_temp_file(case['content'], temp_dir)\n matcher = verifiers.FileChecksumMatcher(\n os.path.join(temp_dir, '*'), case['expected_checksum'], 10)\n hc_assert_that(self._mock_result, matcher)\n self.assertTrue(mocked_sleep.called)\n\n\nif __name__ == '__main__':\n logging.getLogger().setLevel(logging.INFO)\n unittest.main()\n```<|memory_end|>\nExact characters only.", "role": "user" } ]
```python # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # """Unit tests for the test pipeline verifiers""" # pytype: skip-file from __future__ import absolute_import import logging import os import tempfile import unittest from builtins import range from hamcrest import assert_that as hc_assert_that from mock import Mock from mock import patch from apache_beam.io.localfilesystem import LocalFileSystem from apache_beam.runners.runner import PipelineResult from apache_beam.runners.runner import PipelineState from apache_beam.testing import pipeline_verifiers as verifiers from apache_beam.testing.test_utils import patch_retry try: # pylint: disable=wrong-import-order, wrong-import-position # pylint: disable=ungrouped-imports from apitools.base.py.exceptions import HttpError from apache_beam.io.gcp.gcsfilesystem import GCSFileSystem except ImportError: HttpError = None GCSFileSystem = None # type: ignore class PipelineVerifiersTest(unittest.TestCase): def setUp(self): self._mock_result = Mock() patch_retry(self, verifiers) def test_pipeline_state_matcher_success(self): """Test PipelineStateMatcher successes when using default expected state and job actually finished in DONE """ pipeline_result = PipelineResult(PipelineState.DONE) hc_assert_that(pipeline_result, verifiers.PipelineStateMatcher()) def test_pipeline_state_matcher_given_state(self): """Test PipelineStateMatcher successes when matches given state""" pipeline_result = PipelineResult(PipelineState.FAILED) hc_assert_that( pipeline_result, verifiers.PipelineStateMatcher(PipelineState.FAILED)) def test_pipeline_state_matcher_fails(self): """Test PipelineStateMatcher fails when using default expected state and job actually finished in CANCELLED/DRAINED/FAILED/UNKNOWN """ failed_state = [ PipelineState.CANCELLED, PipelineState.DRAINED, PipelineState.FAILED, PipelineState.UNKNOWN ] for state in failed_state: pipeline_result = PipelineResult(state) with self.assertRaises(AssertionError): hc_assert_that(pipeline_result, verifiers.PipelineStateMatcher()) test_cases = [ { 'content': 'Test FileChecksumMatcher with single file', 'num_files': 1, 'expected_checksum': 'ebe16840cc1d0b4fe1cf71743e9d772fa31683b8' }, { 'content': 'Test FileChecksumMatcher with multiple files', 'num_files': 3, 'expected_checksum': '58b3d3636de3891ac61afb8ace3b5025c3c37d44' }, { 'content': '', 'num_files': 1, 'expected_checksum': 'da39a3ee5e6b4b0d3255bfef95601890afd80709' }, ] def create_temp_file(self, content, directory=None): with tempfile.NamedTemporaryFile(delete=False, dir=directory) as f: f.write(content.encode('utf-8')) return f.name def test_file_checksum_matcher_success(self): for case in self.test_cases: temp_dir = tempfile.mkdtemp() for _ in range(case['num_files']): self.create_temp_file(case['content'], temp_dir) matcher = verifiers.FileChecksumMatcher( os.path.join(temp_dir, '*'), case['expected_checksum']) hc_assert_that(self._mock_result, matcher) @patch.object(LocalFileSystem, 'match') def test_file_checksum_matcher_read_failed(self, mock_match): mock_match.side_effect = IOError('No file found.') matcher = verifiers.FileChecksumMatcher( os.path.join('dummy', 'path'), Mock()) with self.assertRaises(IOError): hc_assert_that(self._mock_result, matcher) self.assertTrue(mock_match.called) self.assertEqual(verifiers.MAX_RETRIES + 1, mock_match.call_count) @patch.object(GCSFileSystem, 'match') @unittest.skipIf(HttpError is None, 'google-apitools is not installed') def test_file_checksum_matcher_service_error(self, mock_match): mock_match.side_effect = HttpError( response={'status': '404'}, url='', content='Not Found', ) matcher = verifiers.FileChecksumMatcher('gs://dummy/path', Mock()) with self.assertRaises(HttpError): hc_assert_that(self._mock_result, matcher) self.assertTrue(mock_match.called) self.assertEqual(verifiers.MAX_RETRIES + 1, mock_match.call_count) def test_file_checksum_matchcer_invalid_sleep_time(self): with self.assertRaises(ValueError) as cm: verifiers.FileChecksumMatcher( 'file_path', 'expected_checksum', 'invalid_sleep_time') self.assertEqual( cm.exception.args[0], 'Sleep seconds, if received, must be int. ' 'But received: \'invalid_sleep_time\', ' '{}'.format(str)) @patch('time.sleep', return_value=None) def test_file_checksum_matcher_sleep_before_verify(self, mocked_sleep): temp_dir = tempfile.mkdtemp() case = self.test_cases[0] self.create_temp_file(case['content'], temp_dir) matcher = verifiers.FileChecksumMatcher( os.path.join(temp_dir, '*'), case['expected_checksum'], 10) hc_assert_that(self._mock_result, matcher) self.assertTrue(mocked_sleep.called) if __name__ == '__main__': logging.getLogger().setLevel(logging.INFO) unittest.main() ```
[{"content":"Repeat the code exactly:\n```python\n# Copyright (c) 2012-2015 Netforce Co. Ltd.\n# \n#(...TRUNCATED)
[{"content":"Repeat the code exactly:\n<|memory_start|>```python\n# Copyright (c) 2012-2015 Netforce(...TRUNCATED)
"```python\n# Copyright (c) 2012-2015 Netforce Co. Ltd.\n# \n# Permission is hereby granted, free of(...TRUNCATED)
[{"content":"Provide an exact copy of the source code:\n```python\n<<<<<<< HEAD\n<<<<<<< HEAD\n\"\"\(...TRUNCATED)
[{"content":"Provide an exact copy of the source code:\n<|memory_start|>```python\n<<<<<<< HEAD\n<<<(...TRUNCATED)
"```python\n<<<<<<< HEAD\n<<<<<<< HEAD\n\"\"\"Unit tests for the with statement specified in PEP 343(...TRUNCATED)
[{"content":"Replicate the code snippet exactly, without paraphrasing or reformatting:\n```python\n#(...TRUNCATED)
[{"content":"Replicate the code snippet exactly, without paraphrasing or reformatting:\n<|memory_sta(...TRUNCATED)
"```python\n# -*- coding: utf-8 -*-\n\"\"\"Script for identifying insertions using available aligner(...TRUNCATED)
[{"content":"```python\n# -*- test-case-name: twisted.test.test_strcred -*-\n#\n# Copyright (c) 2007(...TRUNCATED)
[{"content":"<|memory_start|>```python\n# -*- test-case-name: twisted.test.test_strcred -*-\n#\n# Co(...TRUNCATED)
"```python\n# -*- test-case-name: twisted.test.test_strcred -*-\n#\n# Copyright (c) 2007-2008 Twiste(...TRUNCATED)
[{"content":"Here is the code content:\n```python\n# Licensed to the Apache Software Foundation (ASF(...TRUNCATED)
[{"content":"Here is the code content:\n<|memory_start|>```python\n# Licensed to the Apache Software(...TRUNCATED)
"```python\n# Licensed to the Apache Software Foundation (ASF) under one\n# or more contributor lice(...TRUNCATED)
[{"content":"Here is the code content:\n```python\n#################################################(...TRUNCATED)
[{"content":"Here is the code content:\n<|memory_start|>```python\n#################################(...TRUNCATED)
"```python\n###############################################################################\n# This (...TRUNCATED)
[{"content":"Here is the source code:\n```python\n# coding: utf-8\nfrom __future__ import print_func(...TRUNCATED)
[{"content":"Here is the source code:\n<|memory_start|>```python\n# coding: utf-8\nfrom __future__ i(...TRUNCATED)
"```python\n# coding: utf-8\nfrom __future__ import print_function, unicode_literals\nimport os\nimp(...TRUNCATED)
[{"content":"```python\n# -*- coding: utf-8 -*-\nimport logging\n\nfrom flask import Flask, redirect(...TRUNCATED)
[{"content":"<|memory_start|>```python\n# -*- coding: utf-8 -*-\nimport logging\n\nfrom flask import(...TRUNCATED)
"```python\n# -*- coding: utf-8 -*-\nimport logging\n\nfrom flask import Flask, redirect, request, j(...TRUNCATED)
[{"content":"```python\n\"\"\"\nProvides functionality to interact with water heater devices.\n\nFor(...TRUNCATED)
[{"content":"<|memory_start|>```python\n\"\"\"\nProvides functionality to interact with water heater(...TRUNCATED)
"```python\n\"\"\"\nProvides functionality to interact with water heater devices.\n\nFor more detail(...TRUNCATED)
End of preview. Expand in Data Studio

Dataset

Each example contains prompt (chat format) and target fields.

from datasets import load_dataset
ds = load_dataset("leonli66/compression-reconstruction-data", "<config_name>")
Downloads last month
21