internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: google/openhtf

Issue:
Station API client throwing exceptions.
This seems to happen on every test run...

Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in **bootstrap_inner
    self.run()
  File "openhtf/output/web_gui/__init**.py", line 117, in run
    self._test.wait_for_update(timeout_s=self._wait_timeout_s))
  File "openhtf/core/station_api.py", line 286, in wait_for_update
    self.test_uid, summary_dict, timeout_s)
  File "openhtf/util/xmlrpcutil.py", line 85, in _wrapper
    return method(*args)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1233, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1587, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1273, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1306, in single_request
    return self.parse_response(response)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1482, in parse_response
    return u.close()
  File "/usr/lib/python2.7/xmlrpclib.py", line 794, in close
    raise Fault(**self._stack[0])
Fault: <Fault 1: "<type 'exceptions.TypeError'>:_summary_for_state_dict() takes exactly 2 arguments (1 given)">



Discussion:

Resolving patch:
diff --git a/openhtf/core/station_api.py b/openhtf/core/station_api.py
--- a/openhtf/core/station_api.py
+++ b/openhtf/core/station_api.py
@@ -633,7 +633,7 @@ def wait_for_plug(self, test_id, plug_type_name, current_state, timeout_s):
         plug_type_name, current_state, timeout_s)
 
   @staticmethod
-  def _summary_for_state_dict(cls, state_dict):
+  def _summary_for_state_dict(state_dict):
     """Return a dict for state with counts swapped in for phase/log records."""
     state_dict_summary = {
         k: v for k, v in state_dict.iteritems() if k != 'plugs'}


Test patch:
Repository: google/openhtf

Issue:
Update documentation and examples/measurement.py
Ran into some issues on a fresh install from the documentation. I needed to add the package libprotobuf-dev to the apt-get install line in CONTRIBUTING.md to get protobufs to build and got an error when trying to run the example measurements.py that units could not be found, resolved by importing openhtf.utils.units


Discussion:
Also ran into a problem cloning the git repo, had to use git clone https://github.com/google/openhtf
Oops! Thanks for filing this!
Can you elaborate on the cloning issue, though?
using "git clone git@github.com:google/openhtf.git" errored out with:

git clone git@github.com:google/openhtf.git
Cloning into 'openhtf'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I _think_ that's an issue with _your_ ssh keys rather than an issue with our repository specifically. Are you able to clone other repo's using ssh? It may just be a matter of generating an ssh key and adding it to your GitHub profile if you haven't yet:

https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
Fair enough, I'm more of a hardware guy than software guy so not surprised I'm the problem haha

Resolving patch:
diff --git a/examples/measurements.py b/examples/measurements.py
--- a/examples/measurements.py
+++ b/examples/measurements.py
@@ -93,7 +93,7 @@ def lots_of_measurements(test):
 # describing the measurement.  Validators can get quite complex, for more
 # details, see the validators.py example.
 @htf.measures(htf.Measurement('validated_measurement').in_range(0, 10).doc(
-    'This measurement is validated.').with_units(units.SECOND))
+    'This measurement is validated.').with_units(htf.units.SECOND))
 def measure_seconds(test):
   # The 'outcome' of this measurement in the test_record result will be a PASS
   # because its value passes the validator specified (0 <= 5 <= 10).
@@ -106,7 +106,7 @@ def measure_seconds(test):
 # must be a string containing the measurement name).  If you want to specify
 # multiple measurements this way, you can stack multiple decorators.
 @htf.measures('inline_kwargs', docstring='This measurement is declared inline!',
-              units=units.HERTZ, validators=[validators.in_range(0, 10)])
+              units=htf.units.HERTZ, validators=[validators.in_range(0, 10)])
 @htf.measures('another_inline', docstring='Because why not?')
 def inline_phase(test):
   # This measurement will have an outcome of FAIL, because the set value of 15


Test patch:
Repository: google/openhtf

Issue:
Include plug init tracebacks in test record
When tester fails for equipment due to equipment not being present I'm not seeing the stack trace available in the log:

Phase trigger_phase at 08:43:14.548 for 1 minute 3.299 seconds
08:44:18.130	Finishing test with outcome ABORTED.

And finishes with status ERROR.


Discussion:

Resolving patch:
diff --git a/openhtf/core/station_api.py b/openhtf/core/station_api.py
--- a/openhtf/core/station_api.py
+++ b/openhtf/core/station_api.py
@@ -852,8 +852,8 @@ def start_server():
 def stop_server():
   global API_SERVER
   if API_SERVER is not None:
-     _LOG.debug('Stopping Station API server.')
-     API_SERVER.stop()
+    _LOG.debug('Stopping Station API server.')
+    API_SERVER.stop()
     _LOG.debug('Stopped Station API server.')
-     API_SERVER = None
+    API_SERVER = None
 
diff --git a/openhtf/plugs/__init__.py b/openhtf/plugs/__init__.py
--- a/openhtf/plugs/__init__.py
+++ b/openhtf/plugs/__init__.py
@@ -482,7 +482,7 @@ def initialize_plugs(self, plug_types=None):
           # Now the instance has its own copy of the test logger.
           plug_instance.logger = self._logger
       except Exception:  # pylint: disable=broad-except
-        _LOG.error('Exception instantiating plug type %s', plug_type)
+        self._logger.exception('Exception instantiating plug type %s', plug_type)
         self.tear_down_plugs()
         raise
       self.update_plug(plug_type, plug_instance)


Test patch:
diff --git a/test/plugs_test.py b/test/plugs_test.py
--- a/test/plugs_test.py
+++ b/test/plugs_test.py
@@ -15,6 +15,7 @@
 import threading
 import time
 
+import mock
 import openhtf
 
 from openhtf import plugs
@@ -62,7 +63,7 @@ def tearDown(self):
 class PlugsTest(test.TestCase):
 
   def setUp(self):
-    self.logger = object()
+    self.logger = mock.MagicMock()
     self.plug_manager = plugs.PlugManager({AdderPlug}, self.logger)
     AdderPlug.INSTANCE_COUNT = 0
Repository: google/openhtf

Issue:
Plug tearDown functions have no timeout
The plug tearDown functions have no timeout, which means they can hang the execution after the test has normally completed.


Discussion:

Resolving patch:
diff --git a/openhtf/plugs/__init__.py b/openhtf/plugs/__init__.py
--- a/openhtf/plugs/__init__.py
+++ b/openhtf/plugs/__init__.py
@@ -110,12 +110,18 @@ def __init__(self, my_config_key)
 from openhtf.util import classproperty
 from openhtf.util import conf
 from openhtf.util import logs
-from openhtf.util import timeouts
+from openhtf.util import threads
 from openhtf.util import xmlrpcutil
 
 
 _LOG = logging.getLogger(__name__)
 
+
+conf.declare('plug_teardown_timeout_s', default_value=0, description=
+             'Timeout (in seconds) for each plug tearDown function if > 0; '
+             'otherwise, will wait an unlimited time.')
+
+
 PlugDescriptor = collections.namedtuple('PlugDescriptor', ['mro'])  # pylint: disable=invalid-name
 
 # Placeholder for a specific plug to be provided before test execution.
@@ -245,6 +251,23 @@ def result(func):
   return result
 
 
+class _PlugTearDownThread(threads.KillableThread):
+  """Killable thread that runs a plug's tearDown function."""
+
+  def __init__(self, a_plug, *args, **kwargs):
+    super(_PlugTearDownThread, self).__init__(*args, **kwargs)
+    self._plug = a_plug
+
+  def _thread_proc(self):
+    try:
+      self._plug.tearDown()
+    except Exception:  # pylint: disable=broad-except
+      # Including the stack trace from ThreadTerminationErrors received when
+      # killed.
+      _LOG.warning('Exception calling tearDown on %s:',
+                   self._plug, exc_info=True)
+
+
 class PlugManager(object):
   """Class to manage the lifetimes of plugs.
 
@@ -456,10 +479,15 @@ def tear_down_plugs(self):
 
     _LOG.debug('Tearing down all plugs.')
     for a_plug in self._plugs_by_type.itervalues():
-      try:
-        a_plug.tearDown()
-      except Exception:  # pylint: disable=broad-except
-        _LOG.warning('Exception calling tearDown on %s:', a_plug, exc_info=True)
+      thread = _PlugTearDownThread(a_plug)
+      thread.start()
+      timeout_s = (conf.plug_teardown_timeout_s
+                   if conf.plug_teardown_timeout_s
+                   else None)
+      thread.join(timeout_s)
+      if thread.is_alive():
+        thread.kill()
+        _LOG.warning('Killed tearDown for plug %s after timeout.', a_plug)
     self._plugs_by_type.clear()
     self._plugs_by_name.clear()
 


Test patch:
diff --git a/test/util/conf_test.py b/test/util/conf_test.py
--- a/test/util/conf_test.py
+++ b/test/util/conf_test.py
@@ -116,6 +116,7 @@ def test_as_dict(self):
         'station_api_bind_address': '0.0.0.0',
         'station_id': 'station_id',
         'other_flag': 'other_value',
+        'plug_teardown_timeout_s': 0,
         'string_default': 'default',
         'none_default': None,
         'teardown_timeout_s': 30,
Repository: google/openhtf

Issue:
pypi release 1.2.0 is missing built proto files in openhtf/output/proto
pypi release 1.2.0 is missing built proto files in openhtf/output/proto.  They are present in release 1.1.0.   This is observed by downloading the tarball from pypi.  Can this be corrected?  Thanks


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -126,7 +126,6 @@ def run(self):
 
 INSTALL_REQUIRES = [
     'contextlib2>=0.5.1,<1.0',
-    'enum34>=1.1.2,<2.0;python_version<"3.4"',
     'future>=0.16.0',
     'mutablerecords>=0.4.1,<2.0',
     'oauth2client>=1.5.2,<2.0',
@@ -136,6 +135,11 @@ def run(self):
     'sockjs-tornado>=1.0.3,<2.0',
     'tornado>=4.3,<5.0',
 ]
+# Not all versions of setuptools support semicolon syntax for specifying
+# platform-specific dependencies, so we do it the old school way.
+if sys.version_info < (3,4):
+  INSTALL_REQUIRES.append('enum34>=1.1.2,<2.0')
+
 
 
 class PyTestCommand(test):
@@ -174,7 +178,7 @@ def run_tests(self):
 
 setup(
     name='openhtf',
-    version='1.2.0',
+    version='1.2.1',
     description='OpenHTF, the open hardware testing framework.',
     author='John Hawley',
     author_email='madsci@google.com',


Test patch:
Repository: google/openhtf

Issue:
'module' object has no attribute 'MIMETYPE_MAP' - station_server.py
I have openHTF installed in two locations but I only get this error on one of them (The newer one I installed today. I installed from source). I try running `frontend_example.py`, and this is the error I get:
```
Traceback (most recent call last):
  File "frontend_example.py", line 21, in <module>
    from openhtf.output.servers import station_server
  File "/home/lab_machine_2/anaconda2/lib/python2.7/site-packages/openhtf-1.3.0-py2.7.egg/openhtf/output/servers/station_server.py", line 36, in <module>
    v: k for k, v in six.iteritems(mfg_inspector.MIMETYPE_MAP)
AttributeError: 'module' object has no attribute 'MIMETYPE_MAP'
```
I am working on a project that also crashes on the new installation but works on a previously installed version.
'module' object has no attribute 'MIMETYPE_MAP' - station_server.py
I have openHTF installed in two locations but I only get this error on one of them (The newer one I installed today. I installed from source). I try running `frontend_example.py`, and this is the error I get:
```
Traceback (most recent call last):
  File "frontend_example.py", line 21, in <module>
    from openhtf.output.servers import station_server
  File "/home/lab_machine_2/anaconda2/lib/python2.7/site-packages/openhtf-1.3.0-py2.7.egg/openhtf/output/servers/station_server.py", line 36, in <module>
    v: k for k, v in six.iteritems(mfg_inspector.MIMETYPE_MAP)
AttributeError: 'module' object has no attribute 'MIMETYPE_MAP'
```
I am working on a project that also crashes on the new installation but works on a previously installed version.


Discussion:
This looks to be related to the changes introduced in PR #848 

I am personally working off of the prior commit in master (4f7621c287e5902ba95ecd2cc919a90832e183b4) due to this.
Any news on this? @arsharma1 
This looks to be related to the changes introduced in PR #848 

I am personally working off of the prior commit in master (4f7621c287e5902ba95ecd2cc919a90832e183b4) due to this.
Any news on this? @arsharma1 

Resolving patch:
diff --git a/openhtf/output/servers/station_server.py b/openhtf/output/servers/station_server.py
--- a/openhtf/output/servers/station_server.py
+++ b/openhtf/output/servers/station_server.py
@@ -32,9 +32,6 @@
 
 STATION_SERVER_TYPE = 'station'
 
-MIMETYPE_REVERSE_MAP = {
-    v: k for k, v in six.iteritems(mfg_inspector.MIMETYPE_MAP)
-}
 MULTICAST_QUERY = 'OPENHTF_DISCOVERY'
 TEST_STATUS_COMPLETED = 'COMPLETED'
 


Test patch:
Repository: google/openhtf

Issue:
Unused `six` import in monitor code
In `openhtf/core/monitors.py`, it looks like there is an unused import of the `six` module:
https://github.com/google/openhtf/blob/c85fb069a1ce407e82bb47a8fb1b64220e974c5f/openhtf/core/monitors.py#L58

If the aforementioned import is in fact not needed, then it should be deleted.


Discussion:

Resolving patch:
diff --git a/openhtf/core/monitors.py b/openhtf/core/monitors.py
--- a/openhtf/core/monitors.py
+++ b/openhtf/core/monitors.py
@@ -55,7 +55,6 @@ def MyPhase(test):
 from openhtf.core import test_state as core_test_state
 from openhtf.util import threads
 from openhtf.util import units as uom
-import six
 
 
 class _MonitorThread(threads.KillableThread):


Test patch:
Repository: microsoft/qlib

Issue:
Missing `f` prefix on f-strings
Some strings looks like they're meant to be f-strings but are missing the `f` prefix meaning variable interpolation won't happen.

https://github.com/microsoft/qlib/blob/caea495f4087cabb15914123deca8acf94bbf4c6/qlib/contrib/eva/alpha.py#L126

I found this issue automatically. I'm a bot. Beep Boop 🦊. See other issues I found in your repo [here](https://codereview.doctor/microsoft/qlib)


Discussion:

Resolving patch:
diff --git a/qlib/contrib/eva/alpha.py b/qlib/contrib/eva/alpha.py
--- a/qlib/contrib/eva/alpha.py
+++ b/qlib/contrib/eva/alpha.py
@@ -123,7 +123,7 @@ def pred_autocorr(pred: pd.Series, lag=1, inst_col="instrument", date_col="datet
     """
     if isinstance(pred, pd.DataFrame):
         pred = pred.iloc[:, 0]
-        get_module_logger("pred_autocorr").warning("Only the first column in {pred.columns} of `pred` is kept")
+        get_module_logger("pred_autocorr").warning(f"Only the first column in {pred.columns} of `pred` is kept")
     pred_ustk = pred.sort_index().unstack(inst_col)
     corr_s = {}
     for (idx, cur), (_, prev) in zip(pred_ustk.iterrows(), pred_ustk.shift(lag).iterrows()):


Test patch:
Repository: microsoft/qlib

Issue:
Misleading Error "Please install necessary libs for CatBoostModel."
## 🐛 Bug Description

Qlib does not require the installation of packages like `CatBoostModel`

But the output looks a little misleading.


## To Reproduce
Run `examples/workflow_by_code.ipynb` in jupyter notebook.

## Expected Behavior

Successfully run the script without installing CatBoostModel and warning.

## Screenshot
![image](https://user-images.githubusercontent.com/465606/177905185-57a43596-b180-4c52-8df9-0e88b95640b4.png)

<!-- A screenshot of the error message or anything shouldn't appear-->



Discussion:
Maybe we could do something like:
```python
class CatBoostModel:
    def __init__(self):
        try:
            from catboost import ***
        except ModuleNotFoundError:
            print("Warning.")
```
But I feel like this is not elegant enough and may be regarded as invalid in some format style like PEP8.
Here could be an alternative:
<img width="907" alt="image" src="https://user-images.githubusercontent.com/26081991/178068920-53b72697-beb5-41d1-be7f-a97c9583b8c7.png">
 
I've debugged the code , it is triggered if catboost is not installed. We can modify the warning to be similar to all other warnings (like when LGBModel or double_ensemble are not available)

I am still new to the library , so any advice would be appreciated.

 Edit : path to the screen shot https://github.com/microsoft/qlib/blob/main/qlib/contrib/model/__init__.py
![error_location](https://user-images.githubusercontent.com/72355098/180658434-6df96f03-5753-45cc-ab4e-93ee61f19915.PNG)


Resolving patch:
diff --git a/qlib/contrib/model/__init__.py b/qlib/contrib/model/__init__.py
--- a/qlib/contrib/model/__init__.py
+++ b/qlib/contrib/model/__init__.py
@@ -4,7 +4,7 @@
     from .catboost_model import CatBoostModel
 except ModuleNotFoundError:
     CatBoostModel = None
-    print("Please install necessary libs for CatBoostModel.")
+    print("ModuleNotFoundError. CatBoostModel are skipped. (optional: maybe installing CatBoostModel can fix it.)")
 try:
     from .double_ensemble import DEnsembleModel
     from .gbdt import LGBModel


Test patch:
Repository: shuup/shuup

Issue:
Pages availability is confusing and missing date pickers
I created a page and set it `Visible in menu`. The "from" and "to" fields don't have date pickers and I thought they would be optional anyway, seems logical to me as saving works without filling them.

My page didn't appear in shop side. I then went back and manually typed a date "2014-01-01", saved, and pages menu appeared.

So, imho `from` and `to` should be optional constraints and they should definitely have date pickers.

![selection_085](https://cloud.githubusercontent.com/assets/1174866/8476154/269eb5c0-20c7-11e5-87ed-c564c8cd0194.png)



Discussion:
Leaving the availability fields both empty means "this page is not published at all", which, I guess, should be documented :)

And as for date pickers, [if we only had viable native support...](http://caniuse.com/#feat=input-datetime)

> Leaving the availability fields both empty means "this page is not published at all", which, I guess, should be documented :)

Well, the UX is confusing, I don't think documentation helps there. What is the reason for even having "visible in menu" if it doesn't do anything without also filling "available from"? Maybe just remove the checkbox and just use the date, if that is required anyway?

If the checkbox just means "visible in menu" as it says, but "available from" controls whether the page works - then there is probably a bug since I could access the page even without setting any dates by guessing the url :)

Any plans on datepickers? ;) Feels like quite an important usability thing.

Also, hint on valid format might be good in error message as there is no date pickers yet:
![selection_159](https://cloud.githubusercontent.com/assets/1174866/10265202/f53ccb78-6a2e-11e5-843f-ff50502062d0.png)

Date pickers are being tracked as SHOOP-1612, being put into place by @juhakujala as we speak.


Resolving patch:
diff --git a/shoop/admin/templatetags/shoop_admin.py b/shoop/admin/templatetags/shoop_admin.py
--- a/shoop/admin/templatetags/shoop_admin.py
+++ b/shoop/admin/templatetags/shoop_admin.py
@@ -23,6 +23,11 @@ def field(self, field, **kwargs):
     def form(self, form, **kwargs):
         return mark_safe(FormRenderer(form, **kwargs).render())
 
+    def datetime_field(self, field, **kwargs):
+        kwargs.setdefault("widget_class", "datetime")
+        kwargs.setdefault("addon_after", "<span class='fa fa-calendar'></span>")
+        return self.field(field, **kwargs)
+
 
 library.global_function(name="shoop_admin", fn=shoop_admin_template_helpers)
 library.global_function(name="bs3", fn=Bootstrap3Namespace())


Test patch:
Repository: shuup/shuup

Issue:
Admin: Search doesn't work well with categories
Admin > Search > Search for a category
Why does it say "Products" when it's clearly showing categories?
Deleted categories are also visible in search. 

![screenshot from 2018-09-28 22-12-03](https://user-images.githubusercontent.com/40273438/46231259-8aa84280-c36b-11e8-9211-f8e3b0e55697.png)



Discussion:

Resolving patch:
diff --git a/shuup/admin/modules/categories/__init__.py b/shuup/admin/modules/categories/__init__.py
--- a/shuup/admin/modules/categories/__init__.py
+++ b/shuup/admin/modules/categories/__init__.py
@@ -12,6 +12,7 @@
 
 from shuup.admin.base import AdminModule, MenuEntry, SearchResult
 from shuup.admin.menu import PRODUCTS_MENU_CATEGORY
+from shuup.admin.shop_provider import get_shop
 from shuup.admin.utils.permissions import get_default_model_permissions
 from shuup.admin.utils.urls import (
     admin_url, derive_model_url, get_edit_and_list_urls, get_model_url
@@ -22,7 +23,7 @@
 
 class CategoryModule(AdminModule):
     name = _("Categories")
-    category = _("Products")
+    category = _("Categories")
     breadcrumbs_menu_entry = MenuEntry(text=name, url="shuup_admin:category.list", category=PRODUCTS_MENU_CATEGORY)
 
     def get_urls(self):
@@ -56,8 +57,10 @@ def get_menu_entries(self, request):
 
     def get_search_results(self, request, query):
         minimum_query_length = 3
+
         if len(query) >= minimum_query_length:
-            categories = Category.objects.filter(
+            shop = get_shop(request)
+            categories = Category.objects.all_except_deleted(shop=shop).filter(
                 Q(translations__name__icontains=query) |
                 Q(identifier__icontains=query)
             ).distinct().order_by("tree_id", "lft")


Test patch:
diff --git a/shuup_tests/admin/test_category_module.py b/shuup_tests/admin/test_category_module.py
--- a/shuup_tests/admin/test_category_module.py
+++ b/shuup_tests/admin/test_category_module.py
@@ -30,10 +30,11 @@
 
 
 @pytest.mark.django_db
-def test_category_module_search(rf):
+def test_category_module_search(rf, admin_user):
     cm = CategoryModule()
     category = CategoryFactory()
-    request = rf.get("/")
+    shop = get_default_shop()
+    request = apply_request_middleware(rf.get("/"), user=admin_user, shop=shop)
     assert not empty_iterable(cm.get_search_results(request, query=category.identifier))
     assert empty_iterable(cm.get_search_results(request, query="k"))
Repository: shuup/shuup

Issue:
Improve the way permissionas are managed in admin
Currently, use has to use a select2 component with a lot of options and this is super boring, tedious and time consuming. Can we use a list of check boxes instead?


Discussion:

Resolving patch:
diff --git a/shuup/admin/modules/permission_groups/views/edit.py b/shuup/admin/modules/permission_groups/views/edit.py
--- a/shuup/admin/modules/permission_groups/views/edit.py
+++ b/shuup/admin/modules/permission_groups/views/edit.py
@@ -36,7 +36,8 @@ def __init__(self, *args, **kwargs):
             help_text=_(
                 "Select the modules that should be accessible by this permission group. "
                 "Modules with the same permissions as selected modules will be added automatically."
-            )
+            ),
+            widget=forms.CheckboxSelectMultiple
         )
         initial_members = self._get_initial_members()
         members_field = Select2MultipleField(


Test patch: