Hello,
I’m trying to write a test for fcitx and I can manage to get the exact python code pass in the interactive console. However, the same test fails in the vm. VM launches and does most of the things but the very crucial thing fails. This is my first test and I suspect with a bit of handholding, I’ll save a lot of time.
Would someone be able to help me, maybe a sync chat on IRC or discord?
Here is the code-
code
import ./make-test-python.nix (
{
pkgs, ...
}:
let
fcitx_config_contents = builtins.readFile "/code/zx/workspace/git/nixpkgs/nixos/tests/fcitx_config" ;
fcitx_profile_contents = builtins.readFile "/code/zx/workspace/git/nixpkgs/nixos/tests/fcitx_profile" ;
fcitx_profile_file = pkgs.writeTextFile {
name = "fcitx_profile";
text = fcitx_profile_contents;
};
fcitx_config_file = pkgs.writeTextFile {
name = "fcitx_config";
text = fcitx_config_contents;
};
in
rec {
skipLint = true;
name = "fcitx";
machine =
{
pkgs,
...
}:
{
virtualisation.memorySize = 1024;
imports = [
./common/user-account.nix
];
environment.systemPackages = [
# related idio-syncracies of xfece
pkgs.alacritty
pkgs.qt5.qttools
];
services.xserver =
{
enable = true;
displayManager = {
lightdm.enable = true;
autoLogin = {
enable = true;
user = "alice";
};
};
desktopManager.xfce.enable = true;
};
i18n = {
inputMethod = {
enabled = "fcitx";
fcitx.engines = [
pkgs.fcitx-engines.m17n
pkgs.fcitx-engines.table-extra
];
};
};
}
;
testScript =
let
user = "alice"; #machine.config.users.users.alice { inherit pkgs; } ;
userHome = "/home/alice";
xauth = "/home/alice/.Xauthority";
fcitx_confdir = "${userHome}/.fctix/config/";
in
''
machine.copy_from_host( "${fcitx_profile_file}", "/home/alice/.config/fcitx/profile" )
machine.copy_from_host( "${fcitx_config_file}" , "/home/alice/.config/fcitx/config" )
print( "1" )
start_all()
machine.wait_for_file( "${xauth}" )
machine.succeed("xauth merge ${xauth}" )
machine.sleep( 20 )
machine.succeed( "su - alice -c 'alacritty&'" )
machine.sleep( 2 )
print( "2" )
machine.send_chars( 'echo ' )
machine.sleep( 1 )
machine.send_key( 'ctrl-alt-shift-u' )
machine.sleep( 1 )
machine.send_chars( 'smil' )
machine.sleep( 1 )
machine.send_key( 'tab' )
machine.sleep( 1 )
machine.send_key( '\n' )
machine.sleep( 1 )
machine.send_key( 'ctrl-spc' )
machine.sleep( 1 )
machine.send_chars( 'a2' )
machine.sleep( 1 )
machine.send_key( 'alt-shift' )
machine.sleep( 1 )
machine.send_chars( 'ka ' )
machine.sleep( 1 )
machine.send_key( 'alt-shift' )
machine.sleep( 1 )
machine.send_key( 'ctrl-spc' )
machine.sleep( 1 )
machine.send_chars( ' > k\n' )
machine.sleep( 1 )
print( "3" )
file_content=machine.succeed( 'cat /home/alice/k' )
print( machine.succeed( 'head /home/alice/.config/fcitx/profile' ) )
print( machine.succeed( 'head /home/alice/.config/fcitx/config' ) )
print( "4" )
print( file_content )
print( "5" )
assert( file_content== '☺一下क\n' )
''
;
}
)
It basically does the following:
-
Copy config files from hardcoded locations to the vm. The config files are my own and this might sound imperfect but I see this as the quickest way to get to the main test, since otherwise I’ll have to script steps that ultimately get to this config. PS: No way to copy a file directly without first recreating in the store?
-
start the machine. (Which is redundant since copying starts the machine). I need to copy before starting otherwise I’ll have to restart the fcitx process.
-
Open alacritty (because it has no menubar and no conflicts with shortuct keys)
-
Send some keystrokes, invoke fcitx, etc, and get result.
I’m not looking for expertise with fcitx, only someone with some familiarity with the testing framework to maybe act as another pair of eyes.
Thank you.
EDIT: I know that /home/alice
etc will not be hardcoded, I did so for easy copying into python REPL.
Also, the file copy process succeeds, I can verify the output of head
commands at the end of the python script.