hastexo / olx-utils

Tools facilitating the creation of Open edX courseware in the Open Learning XML (OLX) format
GNU Affero General Public License v3.0
5 stars 5 forks source link

Add tests for a full course render #27

Closed fghaas closed 5 years ago

fghaas commented 5 years ago

@arbrandes, this is the bit where I need your help. I want to add a test here for doing a full olx-new-run.

In other words, this breaks:

$ tox -e py27
GLOB sdist-make: /home/florian/git/olx-utils/setup.py
py27 create: /home/florian/git/olx-utils/.tox/py27
py27 installdeps: -rrequirements/test.txt
py27 inst: /home/florian/git/olx-utils/.tox/dist/olx-utils-0.1.1.zip
py27 installed: DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.,certifi==2018.11.29,chardet==3.0.4,coverage==4.5.2,discover==0.4.0,filelock==3.0.10,funcsigs==1.0.2,futures==3.2.0,idna==2.8,Mako==1.0.7,markdown2==2.3.7,MarkupSafe==1.1.0,mock==2.0.0,-e git+git@github.com:hastexo/olx-utils.git@a12bc85b9b3926dfed74a79082e41d60a1db221f#egg=olx_utils,pbr==5.1.2,pkg-resources==0.0.0,pluggy==0.8.1,py==1.7.0,Pygments==2.3.1,python-swiftclient==3.6.0,requests==2.21.0,six==1.12.0,toml==0.10.0,tox==3.7.0,urllib3==1.24.1,virtualenv==16.4.0
py27 runtests: PYTHONHASHSEED='1790264515'
py27 runtests: commands[0] | coverage run -m discover -s tests
...................

Traceback (most recent call last):
  File "olxutils/cli.py", line 105, in render_templates
    templates.render()
  File "olxutils/templates.py", line 85, in render
    self._render_templates(templates)
  File "olxutils/templates.py", line 107, in _render_templates
    rendered = template.render_unicode(**context)
  File "/home/florian/git/olx-utils/.tox/py27/local/lib/python2.7/site-packages/mako/template.py", line 471, in render_unicode
    as_unicode=True)
  File "/home/florian/git/olx-utils/.tox/py27/local/lib/python2.7/site-packages/mako/runtime.py", line 838, in _render
    **_kwargs_for_callable(callable_, data))
  File "/home/florian/git/olx-utils/.tox/py27/local/lib/python2.7/site-packages/mako/runtime.py", line 873, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/home/florian/git/olx-utils/.tox/py27/local/lib/python2.7/site-packages/mako/runtime.py", line 899, in _exec_template
    callable_(context, *args, **kwargs)
  File "static/presentation/index.html", line 0, in render_body

  File "static/presentation/index.html", line 1, in _mako_get_namespace
    <%namespace file='/olx_partials.xml' import='asset_url'/>\
  File "static/presentation/index.html", line 1, in _mako_generate_namespaces
    <%namespace file='/olx_partials.xml' import='asset_url'/>\
  File "/home/florian/git/olx-utils/.tox/py27/local/lib/python2.7/site-packages/mako/runtime.py", line 560, in __init__
    calling_uri)
  File "/home/florian/git/olx-utils/.tox/py27/local/lib/python2.7/site-packages/mako/runtime.py", line 804, in _lookup_template
    raise exceptions.TemplateLookupException(str(compat.exception_as()))
TemplateLookupException: Cant locate template for uri u'/olx_partials.xml'
E

Traceback (most recent call last):
  File "olxutils/cli.py", line 105, in render_templates
    templates.render()
  File "olxutils/templates.py", line 85, in render
    self._render_templates(templates)
  File "olxutils/templates.py", line 107, in _render_templates
    rendered = template.render_unicode(**context)
  File "/home/florian/git/olx-utils/.tox/py27/local/lib/python2.7/site-packages/mako/template.py", line 471, in render_unicode
    as_unicode=True)
  File "/home/florian/git/olx-utils/.tox/py27/local/lib/python2.7/site-packages/mako/runtime.py", line 838, in _render
    **_kwargs_for_callable(callable_, data))
  File "/home/florian/git/olx-utils/.tox/py27/local/lib/python2.7/site-packages/mako/runtime.py", line 873, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/home/florian/git/olx-utils/.tox/py27/local/lib/python2.7/site-packages/mako/runtime.py", line 899, in _exec_template
    callable_(context, *args, **kwargs)
  File "static/presentation/index.html", line 0, in render_body

  File "static/presentation/index.html", line 1, in _mako_get_namespace
    <%namespace file='/olx_partials.xml' import='asset_url'/>\
  File "static/presentation/index.html", line 1, in _mako_generate_namespaces
    <%namespace file='/olx_partials.xml' import='asset_url'/>\
  File "/home/florian/git/olx-utils/.tox/py27/local/lib/python2.7/site-packages/mako/runtime.py", line 560, in __init__
    calling_uri)
  File "/home/florian/git/olx-utils/.tox/py27/local/lib/python2.7/site-packages/mako/runtime.py", line 804, in _lookup_template
    raise exceptions.TemplateLookupException(str(compat.exception_as()))
TemplateLookupException: Cant locate template for uri u'/olx_partials.xml'
E
======================================================================
ERROR: test_render_course_matching (test_full_course.FullCourseTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/florian/git/olx-utils/tests/test_full_course.py", line 50, in test_render_course_matching
    self.render_course("olx-new-run foo 2019-01-01 2019-12-31")
  File "/home/florian/git/olx-utils/tests/test_full_course.py", line 47, in render_course
    cli.main(args)
  File "olxutils/cli.py", line 162, in main
    CLI().main(argv)
  File "olxutils/cli.py", line 150, in main
    self.render_templates()
  File "olxutils/cli.py", line 109, in render_templates
    sys.exit(1)
SystemExit: 1

======================================================================
ERROR: test_render_course_nonmatching (test_full_course.FullCourseTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/florian/git/olx-utils/tests/test_full_course.py", line 60, in test_render_course_nonmatching
    self.render_course("olx-new-run bar 2019-01-01 2019-12-31")
  File "/home/florian/git/olx-utils/tests/test_full_course.py", line 47, in render_course
    cli.main(args)
  File "olxutils/cli.py", line 162, in main
    CLI().main(argv)
  File "olxutils/cli.py", line 150, in main
    self.render_templates()
  File "olxutils/cli.py", line 109, in render_templates
    sys.exit(1)
SystemExit: 1

----------------------------------------------------------------------
Ran 21 tests in 0.666s

FAILED (errors=2)
ERROR: InvocationError: '/home/florian/git/olx-utils/.tox/py27/bin/coverage run -m discover -s tests'
__________________________________________________________________________________________ summary ___________________________________________________________________________________________
ERROR:   py27: commands failed

But I can do this, immediately after:

$ . .tox/py27/bin/activate
$ python --version
Python 2.7.15rc1
$ cd tests/course/source/
$ olx-new-run foo 2019-01-01 2019-12-31
All done!
$ cd ..
$ diff -r source result
$ echo $?
0

This leaves me a bit baffled. I would totally expect weird issues with unicode strings in a 2.7 environment — but I would expect them in any 2.7 environment. I wouldn't expect things to be fine when the CLI is being invoked from the command line, and broken when run from the unit test.

I'm somewhat hoping you may have seen this before, and could suggest a fix.

codecov-io commented 5 years ago

Codecov Report

Merging #27 into master will increase coverage by 16.56%. The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #27       +/-   ##
===========================================
+ Coverage   68.65%   85.21%   +16.56%     
===========================================
  Files           5        6        +1     
  Lines         252      284       +32     
===========================================
+ Hits          173      242       +69     
+ Misses         79       42       -37
Impacted Files Coverage Δ
olxutils/templates.py 100% <ø> (+59.09%) :arrow_up:
tests/test_full_course.py 100% <100%> (ø)
olxutils/helpers.py 72.97% <0%> (+2.7%) :arrow_up:
olxutils/cli.py 60.49% <0%> (+12.34%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d3594de...f490776. Read the comment docs.

arbrandes commented 5 years ago

@fghaas, I don't remember seeing this particular issue before, but my first guess is that in the test run, the paths of the template lookup directories relative to os.getcwd() are wrong. Possibly for the simple reason the current directory is not set to the root directory of the course. I would suggest a manual os.chdir() to the root of the course in the test definition.