mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 11:48:13 +01:00
[test] Convert unittests runner nose => pytest
Per the official docs, nose is in maintenance mode. Attempts to import `Callable` from `collections` fails in Python 3.10. Convert nose-specific assert statements to bare asserts supported by pytest. * https://nose.readthedocs.io/en/latest/#note-to-users * https://github.com/pytest-dev/nose2pytest
This commit is contained in:
2
Makefile
2
Makefile
@@ -6,7 +6,7 @@ test: test.unit test.integration
|
|||||||
|
|
||||||
.PHONY: test.unit
|
.PHONY: test.unit
|
||||||
test.unit:
|
test.unit:
|
||||||
nosetests
|
pytest
|
||||||
|
|
||||||
.PHONY: test.integration
|
.PHONY: test.integration
|
||||||
test.integration:
|
test.integration:
|
||||||
|
|||||||
@@ -3,22 +3,23 @@ import tempfile
|
|||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
import asciinema.config as cfg
|
import asciinema.config as cfg
|
||||||
from nose.tools import assert_equal, assert_raises
|
|
||||||
|
|
||||||
|
|
||||||
def create_config(content=None, env={}):
|
def create_config(content=None, env={}):
|
||||||
dir = tempfile.mkdtemp()
|
# avoid redefining `dir` builtin
|
||||||
|
dir_ = tempfile.mkdtemp()
|
||||||
|
|
||||||
if content:
|
if content:
|
||||||
path = dir + '/config'
|
# avoid redefining `os.path`
|
||||||
with open(path, 'w') as f:
|
path_ = f"{dir_}/config"
|
||||||
|
with open(path_, "wt", encoding="utf_8") as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
return cfg.Config(dir, env)
|
return cfg.Config(dir_, env)
|
||||||
|
|
||||||
|
|
||||||
def read_install_id(install_id_path):
|
def read_install_id(install_id_path):
|
||||||
with open(install_id_path, 'r') as f:
|
with open(install_id_path, "rt", encoding="utf_8") as f:
|
||||||
return f.read().strip()
|
return f.read().strip()
|
||||||
|
|
||||||
|
|
||||||
@@ -27,180 +28,187 @@ def test_upgrade_no_config_file():
|
|||||||
config.upgrade()
|
config.upgrade()
|
||||||
install_id = read_install_id(config.install_id_path)
|
install_id = read_install_id(config.install_id_path)
|
||||||
|
|
||||||
assert re.match('^\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}', install_id)
|
assert re.match("^\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}", install_id)
|
||||||
assert_equal(install_id, config.install_id)
|
assert install_id == config.install_id
|
||||||
assert not path.exists(config.config_file_path)
|
assert not path.exists(config.config_file_path)
|
||||||
|
|
||||||
# it must not change after another upgrade
|
# it must not change after another upgrade
|
||||||
|
|
||||||
config.upgrade()
|
config.upgrade()
|
||||||
|
|
||||||
assert_equal(read_install_id(config.install_id_path), install_id)
|
assert read_install_id(config.install_id_path) == install_id
|
||||||
|
|
||||||
|
|
||||||
def test_upgrade_config_file_with_api_token():
|
def test_upgrade_config_file_with_api_token():
|
||||||
config = create_config("[api]\ntoken = foo-bar-baz")
|
config = create_config("[api]\ntoken = foo-bar-baz")
|
||||||
config.upgrade()
|
config.upgrade()
|
||||||
|
|
||||||
assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')
|
assert read_install_id(config.install_id_path) == "foo-bar-baz"
|
||||||
assert_equal(config.install_id, 'foo-bar-baz')
|
assert config.install_id == "foo-bar-baz"
|
||||||
assert not path.exists(config.config_file_path)
|
assert not path.exists(config.config_file_path)
|
||||||
|
|
||||||
config.upgrade()
|
config.upgrade()
|
||||||
|
|
||||||
assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')
|
assert read_install_id(config.install_id_path) == "foo-bar-baz"
|
||||||
|
|
||||||
|
|
||||||
def test_upgrade_config_file_with_api_token_and_more():
|
def test_upgrade_config_file_with_api_token_and_more():
|
||||||
config = create_config("[api]\ntoken = foo-bar-baz\nurl = http://example.com")
|
config = create_config(
|
||||||
|
"[api]\ntoken = foo-bar-baz\nurl = http://example.com"
|
||||||
|
)
|
||||||
config.upgrade()
|
config.upgrade()
|
||||||
|
|
||||||
assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')
|
assert read_install_id(config.install_id_path) == "foo-bar-baz"
|
||||||
assert_equal(config.install_id, 'foo-bar-baz')
|
assert config.install_id == "foo-bar-baz"
|
||||||
assert_equal(config.api_url, 'http://example.com')
|
assert config.api_url == "http://example.com"
|
||||||
assert path.exists(config.config_file_path)
|
assert path.exists(config.config_file_path)
|
||||||
|
|
||||||
config.upgrade()
|
config.upgrade()
|
||||||
|
|
||||||
assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')
|
assert read_install_id(config.install_id_path) == "foo-bar-baz"
|
||||||
|
|
||||||
|
|
||||||
def test_upgrade_config_file_with_user_token():
|
def test_upgrade_config_file_with_user_token():
|
||||||
config = create_config("[user]\ntoken = foo-bar-baz")
|
config = create_config("[user]\ntoken = foo-bar-baz")
|
||||||
config.upgrade()
|
config.upgrade()
|
||||||
|
|
||||||
assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')
|
assert read_install_id(config.install_id_path) == "foo-bar-baz"
|
||||||
assert_equal(config.install_id, 'foo-bar-baz')
|
assert config.install_id == "foo-bar-baz"
|
||||||
assert not path.exists(config.config_file_path)
|
assert not path.exists(config.config_file_path)
|
||||||
|
|
||||||
config.upgrade()
|
config.upgrade()
|
||||||
|
|
||||||
assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')
|
assert read_install_id(config.install_id_path) == "foo-bar-baz"
|
||||||
|
|
||||||
|
|
||||||
def test_upgrade_config_file_with_user_token_and_more():
|
def test_upgrade_config_file_with_user_token_and_more():
|
||||||
config = create_config("[user]\ntoken = foo-bar-baz\n[api]\nurl = http://example.com")
|
config = create_config(
|
||||||
|
"[user]\ntoken = foo-bar-baz\n[api]\nurl = http://example.com"
|
||||||
|
)
|
||||||
config.upgrade()
|
config.upgrade()
|
||||||
|
|
||||||
assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')
|
assert read_install_id(config.install_id_path) == "foo-bar-baz"
|
||||||
assert_equal(config.install_id, 'foo-bar-baz')
|
assert config.install_id == "foo-bar-baz"
|
||||||
assert_equal(config.api_url, 'http://example.com')
|
assert config.api_url == "http://example.com"
|
||||||
assert path.exists(config.config_file_path)
|
assert path.exists(config.config_file_path)
|
||||||
|
|
||||||
config.upgrade()
|
config.upgrade()
|
||||||
|
|
||||||
assert_equal(read_install_id(config.install_id_path), 'foo-bar-baz')
|
assert read_install_id(config.install_id_path) == "foo-bar-baz"
|
||||||
|
|
||||||
|
|
||||||
def test_default_api_url():
|
def test_default_api_url():
|
||||||
config = create_config('')
|
config = create_config("")
|
||||||
assert_equal('https://asciinema.org', config.api_url)
|
assert config.api_url == "https://asciinema.org"
|
||||||
|
|
||||||
|
|
||||||
def test_default_record_stdin():
|
def test_default_record_stdin():
|
||||||
config = create_config('')
|
config = create_config("")
|
||||||
assert_equal(False, config.record_stdin)
|
assert config.record_stdin is False
|
||||||
|
|
||||||
|
|
||||||
def test_default_record_command():
|
def test_default_record_command():
|
||||||
config = create_config('')
|
config = create_config("")
|
||||||
assert_equal(None, config.record_command)
|
assert config.record_command is None
|
||||||
|
|
||||||
|
|
||||||
def test_default_record_env():
|
def test_default_record_env():
|
||||||
config = create_config('')
|
config = create_config("")
|
||||||
assert_equal('SHELL,TERM', config.record_env)
|
assert config.record_env == "SHELL,TERM"
|
||||||
|
|
||||||
|
|
||||||
def test_default_record_idle_time_limit():
|
def test_default_record_idle_time_limit():
|
||||||
config = create_config('')
|
config = create_config("")
|
||||||
assert_equal(None, config.record_idle_time_limit)
|
assert config.record_idle_time_limit is None
|
||||||
|
|
||||||
|
|
||||||
def test_default_record_yes():
|
def test_default_record_yes():
|
||||||
config = create_config('')
|
config = create_config("")
|
||||||
assert_equal(False, config.record_yes)
|
assert config.record_yes is False
|
||||||
|
|
||||||
|
|
||||||
def test_default_record_quiet():
|
def test_default_record_quiet():
|
||||||
config = create_config('')
|
config = create_config("")
|
||||||
assert_equal(False, config.record_quiet)
|
assert config.record_quiet is False
|
||||||
|
|
||||||
|
|
||||||
def test_default_play_idle_time_limit():
|
def test_default_play_idle_time_limit():
|
||||||
config = create_config('')
|
config = create_config("")
|
||||||
assert_equal(None, config.play_idle_time_limit)
|
assert config.play_idle_time_limit is None
|
||||||
|
|
||||||
|
|
||||||
def test_api_url():
|
def test_api_url():
|
||||||
config = create_config("[api]\nurl = http://the/url")
|
config = create_config("[api]\nurl = http://the/url")
|
||||||
assert_equal('http://the/url', config.api_url)
|
assert config.api_url == "http://the/url"
|
||||||
|
|
||||||
|
|
||||||
def test_api_url_when_override_set():
|
def test_api_url_when_override_set():
|
||||||
config = create_config("[api]\nurl = http://the/url", {
|
config = create_config(
|
||||||
'ASCIINEMA_API_URL': 'http://the/url2'})
|
"[api]\nurl = http://the/url", {"ASCIINEMA_API_URL": "http://the/url2"}
|
||||||
assert_equal('http://the/url2', config.api_url)
|
)
|
||||||
|
assert config.api_url == "http://the/url2"
|
||||||
|
|
||||||
|
|
||||||
def test_record_command():
|
def test_record_command():
|
||||||
command = 'bash -l'
|
command = "bash -l"
|
||||||
config = create_config("[record]\ncommand = %s" % command)
|
config = create_config("[record]\ncommand = %s" % command)
|
||||||
assert_equal(command, config.record_command)
|
assert config.record_command == command
|
||||||
|
|
||||||
|
|
||||||
def test_record_stdin():
|
def test_record_stdin():
|
||||||
config = create_config("[record]\nstdin = yes")
|
config = create_config("[record]\nstdin = yes")
|
||||||
assert_equal(True, config.record_stdin)
|
assert config.record_stdin is True
|
||||||
|
|
||||||
|
|
||||||
def test_record_env():
|
def test_record_env():
|
||||||
config = create_config("[record]\nenv = FOO,BAR")
|
config = create_config("[record]\nenv = FOO,BAR")
|
||||||
assert_equal('FOO,BAR', config.record_env)
|
assert config.record_env == "FOO,BAR"
|
||||||
|
|
||||||
|
|
||||||
def test_record_idle_time_limit():
|
def test_record_idle_time_limit():
|
||||||
config = create_config("[record]\nidle_time_limit = 2.35")
|
config = create_config("[record]\nidle_time_limit = 2.35")
|
||||||
assert_equal(2.35, config.record_idle_time_limit)
|
assert config.record_idle_time_limit == 2.35
|
||||||
|
|
||||||
config = create_config("[record]\nmaxwait = 2.35")
|
config = create_config("[record]\nmaxwait = 2.35")
|
||||||
assert_equal(2.35, config.record_idle_time_limit)
|
assert config.record_idle_time_limit == 2.35
|
||||||
|
|
||||||
|
|
||||||
def test_record_yes():
|
def test_record_yes():
|
||||||
yes = 'yes'
|
yes = "yes"
|
||||||
config = create_config("[record]\nyes = %s" % yes)
|
config = create_config("[record]\nyes = %s" % yes)
|
||||||
assert_equal(True, config.record_yes)
|
assert config.record_yes is True
|
||||||
|
|
||||||
|
|
||||||
def test_record_quiet():
|
def test_record_quiet():
|
||||||
quiet = 'yes'
|
quiet = "yes"
|
||||||
config = create_config("[record]\nquiet = %s" % quiet)
|
config = create_config("[record]\nquiet = %s" % quiet)
|
||||||
assert_equal(True, config.record_quiet)
|
assert config.record_quiet is True
|
||||||
|
|
||||||
|
|
||||||
def test_play_idle_time_limit():
|
def test_play_idle_time_limit():
|
||||||
config = create_config("[play]\nidle_time_limit = 2.35")
|
config = create_config("[play]\nidle_time_limit = 2.35")
|
||||||
assert_equal(2.35, config.play_idle_time_limit)
|
assert config.play_idle_time_limit == 2.35
|
||||||
|
|
||||||
config = create_config("[play]\nmaxwait = 2.35")
|
config = create_config("[play]\nmaxwait = 2.35")
|
||||||
assert_equal(2.35, config.play_idle_time_limit)
|
assert config.play_idle_time_limit == 2.35
|
||||||
|
|
||||||
|
|
||||||
def test_notifications_enabled():
|
def test_notifications_enabled():
|
||||||
config = create_config('')
|
config = create_config("")
|
||||||
assert_equal(True, config.notifications_enabled)
|
assert config.notifications_enabled is True
|
||||||
|
|
||||||
config = create_config("[notifications]\nenabled = yes")
|
config = create_config("[notifications]\nenabled = yes")
|
||||||
assert_equal(True, config.notifications_enabled)
|
assert config.notifications_enabled is True
|
||||||
|
|
||||||
config = create_config("[notifications]\nenabled = no")
|
config = create_config("[notifications]\nenabled = no")
|
||||||
assert_equal(False, config.notifications_enabled)
|
assert config.notifications_enabled is False
|
||||||
|
|
||||||
|
|
||||||
def test_notifications_command():
|
def test_notifications_command():
|
||||||
config = create_config('')
|
config = create_config("")
|
||||||
assert_equal(None, config.notifications_command)
|
assert config.notifications_command is None
|
||||||
|
|
||||||
config = create_config('[notifications]\ncommand = tmux display-message "$TEXT"')
|
config = create_config(
|
||||||
assert_equal('tmux display-message "$TEXT"', config.notifications_command)
|
'[notifications]\ncommand = tmux display-message "$TEXT"'
|
||||||
|
)
|
||||||
|
assert config.notifications_command == 'tmux display-message "$TEXT"'
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
import os
|
import os
|
||||||
import pty
|
import pty
|
||||||
|
|
||||||
from nose.tools import assert_equal
|
|
||||||
from .test_helper import Test
|
|
||||||
|
|
||||||
import asciinema.pty
|
import asciinema.pty
|
||||||
|
|
||||||
|
from .test_helper import Test
|
||||||
|
|
||||||
|
|
||||||
class FakeStdout:
|
class FakeStdout:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.data = []
|
self.data = []
|
||||||
|
|
||||||
@@ -20,7 +18,6 @@ class FakeStdout:
|
|||||||
|
|
||||||
|
|
||||||
class TestRecord(Test):
|
class TestRecord(Test):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.real_os_write = os.write
|
self.real_os_write = os.write
|
||||||
os.write = self.os_write
|
os.write = self.os_write
|
||||||
@@ -35,7 +32,18 @@ class TestRecord(Test):
|
|||||||
def test_record_command_writes_to_stdout(self):
|
def test_record_command_writes_to_stdout(self):
|
||||||
output = FakeStdout()
|
output = FakeStdout()
|
||||||
|
|
||||||
command = ['python3', '-c', "import sys; import time; sys.stdout.write(\'foo\'); sys.stdout.flush(); time.sleep(0.01); sys.stdout.write(\'bar\')"]
|
command = [
|
||||||
|
"python3",
|
||||||
|
"-c",
|
||||||
|
(
|
||||||
|
"import sys"
|
||||||
|
"; import time"
|
||||||
|
"; sys.stdout.write('foo')"
|
||||||
|
"; sys.stdout.flush()"
|
||||||
|
"; time.sleep(0.01)"
|
||||||
|
"; sys.stdout.write('bar')"
|
||||||
|
),
|
||||||
|
]
|
||||||
asciinema.pty.record(command, output)
|
asciinema.pty.record(command, output)
|
||||||
|
|
||||||
assert_equal([b'foo', b'bar'], output.data)
|
assert output.data == [b"foo", b"bar"]
|
||||||
|
|||||||
Reference in New Issue
Block a user