markfink / metrics

produces metrics for Python, C, C++, Go and Javascript programs (plugins for pylint, pytest-cov, and git available)
MIT License
16 stars 8 forks source link

test/resources/.metrics is missing from repository #10

Open mcallaghan-bsm opened 5 years ago

mcallaghan-bsm commented 5 years ago

Out of interest in the project in making some improvements, I was attempting to baseline myself with the code base, environment dependencies, and ability to run UTs.

Forked into: https://github.com/mcallaghan-bsm/metrics/tree/wip_poc_pipenv_and_pytest_run_v0.3.3

Which has the new pipenv Pipfile bits for easier environment setup, enabling magic:

$ pipenv shell
Launching subshell in virtual environment…
 . /home/<SNIP_USER>/.local/share/virtualenvs/metrics-aBM-sXCA/bin/activate
<SNIP_USER>@<SNIP_HOST>:~/projects/bsm/metrics$  . /home/<SNIP_USER>/.local/share/virtualenvs/metrics-aBM-sXCA/bin/activate

$ pipenv install --dev
Pipfile.lock (7281fb) out of date, updating to (ae4472)…
Locking [dev-packages] dependencies…
✔ Success! 
Locking [packages] dependencies…
✔ Success! 
Updated Pipfile.lock (7281fb)!
Installing dependencies from Pipfile.lock (7281fb)…
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 28/28 — 00:00:10

Then in theory we're setup and ready to go. Let's try to run the tests off the latest version forked on August 9th 2019 (v0.3.3)

$ pipenv run python3 -m pytest tests
========================================================================= test session starts ==========================================================================
platform linux -- Python 3.5.2, pytest-5.0.1, py-1.8.0, pluggy-0.12.0
rootdir: /home/<SNIP_USER>/projects/bsm/metrics
plugins: cov-2.7.1
collected 28 items                                                                                                                                                     

tests/test_code_samples.py ...                                                                                                                                   [ 10%]
tests/test_lexer_cpp.py .                                                                                                                                        [ 14%]
tests/test_lexer_go.py .                                                                                                                                         [ 17%]
tests/test_lexer_javascript.py .                                                                                                                                 [ 21%]
tests/test_lexer_python.py ...                                                                                                                                   [ 32%]
tests/test_metrics_utils.py ......E.                                                                                                                             [ 60%]
tests/test_output_format.py ....                                                                                                                                 [ 75%]
tests/test_positions_cpp.py .                                                                                                                                    [ 78%]
tests/test_positions_go.py .                                                                                                                                     [ 82%]
tests/test_positions_javascript.py .                                                                                                                             [ 85%]
tests/test_positions_python.py ...                                                                                                                               [ 96%]
tests/test_sloc_python.py .                                                                                                                                      [100%]

================================================================================ ERRORS ================================================================================
____________________________________________________________ ERROR at setup of test_load_metrics_from_file _____________________________________________________________

tempfolder = None

    @pytest.fixture
    def metrics_info(tempfolder):
        """copy .metrics file to tempfolder."""
        copyfile(here('resources/' + METRICS_FILENAME),
>                METRICS_FILENAME)

/home/<SNIP_USER>/projects/bsm/metrics/tests/test_metrics_utils.py:84: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

src = '/home/<SNIP_USER>/projects/bsm/metrics/tests/resources/.metrics', dst = '.metrics'

    def copyfile(src, dst, *, follow_symlinks=True):
        """Copy data from src to dst.

        If follow_symlinks is not set and src is a symbolic link, a new
        symlink will be created instead of copying the file it points to.

        """
        if _samefile(src, dst):
            raise SameFileError("{!r} and {!r} are the same file".format(src, dst))

        for fn in [src, dst]:
            try:
                st = os.stat(fn)
            except OSError:
                # File most likely does not exist
                pass
            else:
                # XXX What about other special files? (sockets, devices...)
                if stat.S_ISFIFO(st.st_mode):
                    raise SpecialFileError("`%s` is a named pipe" % fn)

        if not follow_symlinks and os.path.islink(src):
            os.symlink(os.readlink(src), dst)
        else:
>           with open(src, 'rb') as fsrc:
E           FileNotFoundError: [Errno 2] No such file or directory: '/home/<SNIP_USER>/projects/bsm/metrics/tests/resources/.metrics'

/home/<SNIP_USER>/.local/share/virtualenvs/metrics-aBM-sXCA/lib/python3.5/shutil.py:114: FileNotFoundError
================================================================== 27 passed, 1 error in 2.64 seconds ==================================================================

Darn, so there is supposed to be a .metrics file kicking around in test resources? (indeed not there find tests/resources/| grep metric is empty)

Which test does it come from?

https://github.com/finklabs/metrics/blob/master/tests/test_metrics_utils.py#L87

def test_load_metrics_from_file(metrics_info):
  data = load_metrics_from_file(METRICS_FILENAME)
  (snip)
...

METRICS_FILENAME is set

$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import metrics
>>> metrics.METRICS_FILENAME
'.metrics'

hm... I know that a .metrics temp file is generated after running metrics on a project code base ... but the tests seem to rely upon this dependency?