diff --git a/tests/test_main.py b/tests/test_main.py index 12a4c76..6362647 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -377,6 +377,52 @@ class MainTestCase(utils.TestCase): self.assertEquals(stats, json.loads(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][1])) self.patched['wakatime.offlinequeue.Queue.pop'].assert_not_called() + def test_hide_all_filenames_from_cli_arg(self): + response = Response() + response.status_code = 0 + self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response + + with utils.TemporaryDirectory() as tempdir: + entity = 'tests/samples/codefiles/twolinefile.txt' + shutil.copy(entity, os.path.join(tempdir, 'twolinefile.txt')) + entity = os.path.realpath(os.path.join(tempdir, 'twolinefile.txt')) + now = u(int(time.time())) + config = 'tests/samples/configs/good_config.cfg' + key = str(uuid.uuid4()) + + args = ['--file', entity, '--key', key, '--config', config, '--time', now, '--hidefilenames'] + + retval = execute(args) + self.assertEquals(retval, API_ERROR) + self.assertEquals(sys.stdout.getvalue(), '') + self.assertEquals(sys.stderr.getvalue(), '') + + self.patched['wakatime.session_cache.SessionCache.get'].assert_called_once_with() + self.patched['wakatime.session_cache.SessionCache.delete'].assert_called_once_with() + self.patched['wakatime.session_cache.SessionCache.save'].assert_not_called() + + heartbeat = { + 'language': 'Text only', + 'lines': 2, + 'entity': 'HIDDEN.txt', + 'project': os.path.basename(os.path.abspath('.')), + 'time': float(now), + 'type': 'file', + } + stats = { + u('cursorpos'): None, + u('dependencies'): [], + u('language'): u('Text only'), + u('lineno'): None, + u('lines'): 2, + } + + self.patched['wakatime.offlinequeue.Queue.push'].assert_called_once_with(ANY, ANY, None) + for key, val in self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0].items(): + self.assertEquals(heartbeat[key], val) + self.assertEquals(stats, json.loads(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][1])) + self.patched['wakatime.offlinequeue.Queue.pop'].assert_not_called() + def test_hide_matching_filenames(self): response = Response() response.status_code = 0 diff --git a/wakatime/main.py b/wakatime/main.py index 7ed1437..706e9e9 100644 --- a/wakatime/main.py +++ b/wakatime/main.py @@ -533,8 +533,8 @@ def format_file_path(filepath): try: filepath = os.path.realpath(os.path.abspath(filepath)) filepath = re.sub(r'[/\\]', os.path.sep, filepath) - except: - pass # pragma: nocover + except: # pragma: nocover + pass return filepath