Sitelet https://web.archive.org/web/20260604072935/https://github.com/RustPython/RustPython/pull/2174
Skip to content

Update calendar.py and Add test_calendar.py from CPython 3.8.5#2174

Merged
BenLewis-Seequent merged 4 commits into
RustPython:masterfrom
clemado1:calendar
Sep 1, 2020
Merged

Update calendar.py and Add test_calendar.py from CPython 3.8.5#2174
BenLewis-Seequent merged 4 commits into
RustPython:masterfrom
clemado1:calendar

Conversation

@clemado1
Copy link
Copy Markdown
Contributor

  • Update calendar.py from CPython 3.8.5
  • Add test_calendar.py
  • Skip test_option_encoding that caused error
======================================================================
FAIL: test_option_encoding (__main__.CommandLineTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Lib/test/test_calendar.py", line 831, in test_option_encoding
    stdout = self.run_ok('--encoding', 'utf-16-le', '2004')
  File "Lib/test/test_calendar.py", line 794, in run_ok
    return assert_python_ok('-m', 'calendar', *args)[1]
  File "/home/clemado1/workspace/RustPython/vm/pylib-crate/Lib/test/support/script_helper.py", line 157, in assert_python_ok
    return _assert_python(True, *args, **env_vars)
  File "/home/clemado1/workspace/RustPython/vm/pylib-crate/Lib/test/support/script_helper.py", line 143, in _assert_python
    res.fail(cmd_line)
  File "/home/clemado1/workspace/RustPython/vm/pylib-crate/Lib/test/support/script_helper.py", line 84, in fail
    err))
AssertionError: Process return code is 1
command line: ['/home/clemado1/workspace/RustPython/target/release/rustpython', '-X', 'faulthandler', '-I', '-m', 'calendar', '--encoding', 'utf-16-le', '2004']

stdout:
---

---

stderr:
---
Traceback (most recent call last):
  File "/home/clemado1/workspace/RustPython/vm/pylib-crate/Lib/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/clemado1/workspace/RustPython/vm/pylib-crate/Lib/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/clemado1/workspace/RustPython/vm/pylib-crate/Lib/calendar.py", line 770, in <module>
    main(sys.argv)
  File "/home/clemado1/workspace/RustPython/vm/pylib-crate/Lib/calendar.py", line 764, in main
    result = result.encode(options.encoding)
  File "/home/clemado1/workspace/RustPython/vm/pylib-crate/Lib/_codecs.py", line 118, in encode
    res = codec[0](v, errors)
  File "/home/clemado1/workspace/RustPython/vm/pylib-crate/Lib/_codecs.py", line 463, in __call__
    return self._f(*args, **kwargs)
  File "/home/clemado1/workspace/RustPython/vm/pylib-crate/Lib/_codecs.py", line 421, in utf_16_le_encode
    res = bytes(res)
TypeError: Expected type 'int', not 'str'
---

@youknowone
Copy link
Copy Markdown
Member

anybody has any idea what's happened to newline here?

@coolreader18
Copy link
Copy Markdown
Member

That error should be fixable in _codecs.py, that code is from python 2 so it just needs to be converted to use ord or not use chr, or something along those lines.

@coolreader18
Copy link
Copy Markdown
Member

@youknowone what do you mean?

@youknowone
Copy link
Copy Markdown
Member

@coolreader18 See the failed test in windows CI. it seems the text is included in text file, but somehow it includes \r\n instead of \n in the test - which leads error

@coolreader18
Copy link
Copy Markdown
Member

Oh, hmm -- we might need to change stdio to use raw/binary mode instead of text mode. I think I read a blog post about someone compressing an executable on windows and windows converted a 0a byte in the machine code to 0a 0d because stdout was in "text" mode -- maybe this is something similar.

@coolreader18
Copy link
Copy Markdown
Member

https://docs.microsoft.com/en-us/cpp/c-runtime-library/text-and-binary-mode-file-i-o?view=vs-2019

Not sure if there's something to do this in Rust

@clemado1
Copy link
Copy Markdown
Contributor Author

clemado1 commented Sep 1, 2020

I marked skip as a temporary fix on all the 5 test cases that had errors in Windows.
@unittest.skipIf(sys.platform == 'win32', 'TODO: RUSTPYTHON Windows')

Copy link
Copy Markdown

@BenLewis-Seequent BenLewis-Seequent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@BenLewis-Seequent BenLewis-Seequent merged commit f98a381 into RustPython:master Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants