Repository: myokit/myokit (language: python)

Issue:
Test coverage _expressions.py line 204
Is sometimes hit, sometimes not.

```
    def depends_on(self, lhs, deep=False):
        """
        Returns ``True`` if this :class:`Expression` depends on the given
        :class:`LhsExpresion`.

        With ``deep=False`` (default), only dependencies appearing directly in
        the expression are checked. With ``deep=True`` the method also checks
        the right-hand side equation defined in the model for any
        :class:`Name` or :class:`Derivative` it encounters.
        """
        # Shallow check
        if not deep:
            return lhs in self._references

        # Determine if this variable has a (deep) dependency on the given lhs
        done = set()
        if isinstance(self, myokit.LhsExpression):
            done.add(self)
        todo = set(self._references)
        while todo:
            ref = todo.pop()
            done.add(ref)
            if ref == lhs:
                return True
            elif ref._has_partials or ref._has_initials:
                # Partial derivatives and initial values have no rhs
                continue
            elif not ref._proper:
                # Values that are not variables count as independent
                print('HERE')
                continue

            var = ref.var()
            if ref.is_state_value() or var.is_bound():
                # State values and bound variables have no rhs
                continue
            else:
                todo.update(var.rhs()._references - done)
        return False
```
☝🏻 The `print` statement is on the offending line.

Minimal example to reproduce:
```
#!/usr/bin/env python3
import myokit

m = myokit.Model()
v = m.add_component('x').add_variable('y')
v.set_rhs(3)
v = myokit.Name(v)

# Deep checking can handle improper names
p = myokit.Plus(v, myokit.Name('x'))
p.depends_on(v, True)
```

Example output:
```
[michael@localhost myokit]$ ./ff
HERE
[michael@localhost myokit]$ ./ff
HERE
[michael@localhost myokit]$ ./ff
[michael@localhost myokit]$ ./ff
```
Avoid random codecov fails by adding token
https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d2f7a6492..ac93c9abc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ This page lists the main changes made to Myokit in each release.
 - Deprecated
 - Removed
 - Fixed
+  - [#908](https://github.com/MichaelClerx/myokit/pull/908) Added new homebrew location used on M1 apple devices, potentially solving [#861](https://github.com/myokit/myokit/issues/861).
 
 ## [1.33.8] - 2022-10-21
 - Added


Test patch:
diff --git a/.github/workflows/coverage-test.yml b/.github/workflows/coverage-test.yml
index 13a0fda00..3c13ead8e 100644
--- a/.github/workflows/coverage-test.yml
+++ b/.github/workflows/coverage-test.yml
@@ -42,5 +42,7 @@ jobs:
 
       - name: Submit report to codecov
         if: success()
+        env:
+          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
         run: |
           codecov
diff --git a/myokit/tests/test_expressions.py b/myokit/tests/test_expressions.py
index f1d67386d..29f13be9d 100755
--- a/myokit/tests/test_expressions.py
+++ b/myokit/tests/test_expressions.py
@@ -127,9 +127,14 @@ def test_depends_on(self):
         self.assertTrue(v.depends_on(c, deep=True))
 
         # Deep checking can handle improper names
+        # Note: The order of execution is not guaranteed, so that sometimes
+        # the test will find 'c' before dealing with the improper ref. As a
+        # result, the False scenario is required for consistent coverage.
+        # https://github.com/myokit/myokit/issues/913
         p = myokit.Plus(c, myokit.Name('x'))
         self.assertTrue(p.depends_on(c, True))
         self.assertTrue(p.depends_on(myokit.Name('x'), True))
+        self.assertFalse(p.depends_on(v, True))
 
         # Deep checking can handle partial derivs and inits
         q = myokit.PartialDerivative(myokit.Name(v.var()), c)
@@ -144,12 +149,14 @@ def test_depends_on(self):
         self.assertFalse(q.depends_on(myokit.Name(v.var()), False))
 
         # Deep checking can handle partial derivs and inits & improper names
+        # See note above about issue 913
         q = myokit.Plus(p, myokit.PartialDerivative(v, myokit.Name('x')))
         self.assertTrue(q.depends_on(c, True))
         self.assertTrue(q.depends_on(myokit.Name('x'), True))
         q = myokit.Plus(p, myokit.InitialValue(myokit.Name('x')))
         self.assertTrue(q.depends_on(c, True))
         self.assertTrue(q.depends_on(myokit.Name('x'), True))
+        self.assertFalse(q.depends_on(v, True))
 
         # Test with complex web of dependencies
         m.get('ina.E').set_rhs('a + b + c + k1 + k2 + inf')