def test_get_telegram_key(self): print("Testing get_telegram_key()") from stallmanbot import read_configuration, get_telegram_key import os import configparser fs = mockfs.replace_builtins() SESSION = "TELEGRAM" fs.add_entries({"configuration.conf" : "[TELEGRAM]\n" + \ "STALLBOT = abc:123456\n" + \ "STALLBOTADM = HelioLoureiro\n"}) sys = Mock() error = Mock() debug = Mock() cfg = read_configuration("configuration.conf") print(" * testing existent values") result = get_telegram_key(cfg, "STALLBOT") self.assertEqual(result, "abc:123456", "Resulting is mismatching expected value.") print(" * testing non-existent values") result = get_telegram_key(cfg, "ROCKNROLL") self.assertIsNone(result, "Command returned value (expected empty).") mockfs.restore_builtins()
def notest_get_telegram_key(self): print("Testing get_telegram_key()") from educatuxbot import read_configuration, get_telegram_key import os import configparser fs = mockfs.replace_builtins() SESSION = "TELEGRAM" fs.add_entries({"configuration.conf" : "[TELEGRAM]\n" + \ "STALLBOT = abc:123456\n" + \ "STALLBOTADM = HelioLoureiro\n"}) sys = Mock() error = Mock() debug = Mock() cfg = read_configuration("configuration.conf") print(" * testing existent values") result = get_telegram_key(cfg, "STALLBOT") self.assertEqual(result, "abc:123456", "Resulting is mismatching expected value.") print(" * testing non-existent values") result = get_telegram_key(cfg, "ROCKNROLL") self.assertIsNone(result, "Command returned value (expected empty).") mockfs.restore_builtins()
def test_save_file(self): print("Testing check_if_run()") from stallmanbot import save_file fs = mockfs.replace_builtins() fs.add_entries({"/tmp/testing" : ""}) save_file("12345", "/tmp/testing") self.assertEqual("12345", fs.read("/tmp/testing"), "Saving data failed") mockfs.restore_builtins()
def fs(request): mfs = mockfs.replace_builtins() os.path.lexists = mfs.exists glob.iglob = mfs.glob mfs.add_entries({ "jasmine.yml": """ src_files: - src/player.js - src/**/*.js - http://cdn.jquery.com/jquery.js - vendor/test.js - vendor/**/*.{js,coffee} """, "/spec/javascripts/helpers/spec_helper.js": '', "/lib/jams/jam_spec.js": '', "/src/player.js": '', "/src/mixer/mixer.js": '', "/src/tuner/fm/fm_tuner.js": '', "/spec/javascripts/player_spec.js": '', "/spec/javascripts/mixer/mixer_spec.js": '', "/spec/javascripts/tuner/fm/fm_tuner_spec.js": '', "/spec/javascripts/tuner/am/AMSpec.js": '', "/vendor/test.js": '', "/vendor/pants.coffee": '', "/vendor_spec/pantsSpec.js": '', "/main.css": '', }) request.addfinalizer(lambda: mockfs.restore_builtins()) return mfs
def mockfs(request): mfs = replace_builtins() mfs.add_entries({ "/spec/javascripts/support/jasmine.yml": """ src_dir: src spec_dir: spec """ }) request.addfinalizer(lambda: restore_builtins()) return mfs
def mockfs_with_config(request): mfs = replace_builtins() mfs.add_entries({ "/spec/javascripts/support/jasmine.yml": """ src_dir: src spec_dir: spec """ }) request.addfinalizer(lambda: restore_builtins()) return mfs
def test_read_configuration(self): print("Testing read_configuration()") from stallmanbot import read_configuration import sys import time import os import configparser fs = mockfs.replace_builtins() SESSION = "TELEGRAM" fs.add_entries({"configuration.conf" : "[TELEGRAM]\n" + \ "STALLBOT = abc:123456\n" + \ "STALLBOTADM = HelioLoureiro\n"}) sys.exit = MagicMock() error = MagicMock() print(" * correct configuration") cfg = read_configuration("configuration.conf") self.assertEqual(cfg.get(SESSION, "STALLBOT"), "abc:123456", "Parameter didn't match.") self.assertEqual(cfg.get(SESSION, "STALLBOTADM"), "HelioLoureiro", "Parameter didn't match.") print(" * missing session") SESSION = "FAKE" self.assertRaises(configparser.NoSectionError, cfg.get, SESSION, "STALLBOT") print(" * missing session using utf-8") SESSION = "FåKEçÉ" self.assertRaises(configparser.NoSectionError, cfg.get, SESSION, "STÁLLBÖT") print(" * missing parameter") SESSION = "TELEGRAM" self.assertRaises(configparser.NoOptionError, cfg.get, SESSION, "WHATEVER") mockfs.restore_builtins()
def test_read_file(self): print("Testing read_file()") from stallmanbot import read_file, error fs = mockfs.replace_builtins() fs.add_entries({ "/etc/python" : "zen of python", "/étç/två" : "ett två três"}) print(" * file exists and it is ASCII") result = read_file("/etc/python") self.assertEqual(result, "zen of python", "Failed to read content") print(" * file exists and it is UTF-8") result = read_file("/étç/två") self.assertEqual(result, "ett två três", "Failed to read content") print(" * file doesn't exist") result = read_file("/etc/helio_loureiro") self.assertEqual(result, None, "None return failed from non-existent file") mockfs.restore_builtins()
def test_check_if_run(self): print("Testing check_if_run()") from stallmanbot import check_if_run, PIDFILE import sys import time import os fs = mockfs.replace_builtins() fs.add_entries({"%s/.stallmanbot.pid" % os.environ["HOME"] : "12345", "/proc/12345/running" : "yes"}) sys.exit = MagicMock(return_value="exiting") os.getpid = MagicMock(return_value=12345) log = MagicMock() print(" * process exists and is running") print("mypid=%d" % os.getpid()) check_if_run() #sys.exit.assert_called_with(os.EX_OK) #print(" * process doesn't exist and isn't running") #fs.remove("%s/.stallmanbot.pid" % os.environ["HOME"]) #check_if_run() mockfs.restore_builtins()
def tearDown(self): mockfs.restore_builtins()
def mockfs(request): mfs = replace_builtins() request.addfinalizer(lambda: restore_builtins()) return mfs
def teardown_method(self, method): mockfs.restore_builtins()
def teardown(self): mockfs.restore_builtins()
def tearDown(self): self._check_if_dir_contains_only(BASE_DIR, self.physical_dirs_expected, self.physical_files_expected) mockfs.restore_builtins()
def teardown(self): mockfs.restore_builtins() for name in self.ATTRS: self._release(name)